Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
qmacro
Developer Advocate
Developer Advocate
663
This is a searchable description of the content of a live stream recording, specifically “Episode 26 - Vim CDS plugin with new @Sisn/cds-lsp package” in the “Hands-on SAP dev with qmacro” series. There are links directly to specific highlights in the video recording. For links to annotations of other episodes, please see the “Catch the replays” section of the series blog post.

This episode, titled “Vim CDS plugin with new @sap/cds-lsp package”, was streamed live on Wed 29 May 2019 and is approximately one hour in length. The stream recording is available on YouTube.



Below is a brief synopsis, and links to specific highlights - use these links to jump directly to particular places of interest in the recording, based on ‘hh:mm:ss’ style timestamps.

Brief synopsis


Now that the @Sisn/cds-lsp package is published to the public SAP NPM registry, it’s a good time to look how we can incorporate that into the Vim CDS plugin.

00:01:50: Talking about the news from the CAP team that they’ve released the @Sisn/cds-lsp package on the SAP NPM registry.

00:02:24: Highlighting a fellow live coding streamer Jamie Pine who does all sorts of interesting stuff and indeed a prolific streamer. He’s building live, in public as it were, his app and service Notify, which is very impressive. Definitely worth a follow on Twitch.

00:04:10: Looking at the CDS Language Support for VS Code extension available on the SAP Development Tools site, which is where the @Sisn/cds-lsp originally appeared (inside the compressed vsix file, which represented everything needed for the extension).

00:07:15: In my quest to bring in CDS language goodness into Vim I originally started with the Vim plugin “LanguageClient-neovim” (don’t let the name fool you - it also works with regular Vim as well as NeoVim). But I moved across to the Asynchronous Lint Engine (ALE) recently and it’s been working quite nicely for me.

00:09:30: The version of @Sisn/cds-lsp inside the 1.1.4 version of the CDS extension for VS Code is 2.0.7. Asking the SAP NPM registry for information about the newly independent version, we see that it’s already at 2.1.2. Now (at the time of writing this post) it’s at 2.1.4:
=> npm info @sap/cds-lsp
@sap/cds-lsp@2.1.4 | SEE LICENSE IN LICENSE.txt | deps: 8 | versions: 2
Language server for CDS

dist
.tarball: https://npm.sap.com/@sap/cds-lsp/-/cds-lsp-2.1.4.tgz
.shasum: 5d9a7720a6278cc4299271194229b9c4f6b616e9
.integrity: sha512-NAoXcRviGbFMHZZwg7dY4+VNoocS4KABIsxbPwMS7PhYCig1naT6xCKac+VCUQYpQOiatvQgHooFrZOjz7lo9g==

dependencies:
@sap/cds-compiler: 1.15.0
@types/antlr4: 4.7.0
fs.realpath: 1.0.0
ignore: 5.0.4
ts-md5: 1.2.4
vscode-languageserver-protocol: 3.14.1
vscode-languageserver: 5.2.1
vscode-uri: 1.0.6

maintainers:
- https-support.sap.com <do.not.reply@sap.com>

dist-tags:
latest: 2.1.4

published a week ago by https-support.sap.com <do.not.reply@sap.com>

00:13:50: Looking at the current state of the vim-cds plugin, examining each of the components in turn:

  • the file type detector

  • the syntax highlighting specifications

  • the hook for ALE


While looking through them, we also take a quick look at my Vim configuration, which is using a new plugin manager (vim-plug) which allows me to organise my plugins in a cleaner way, and also allows me to specify local plugins such as this in-development vim-cds plugin:
" vim-plug configuration
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall | source $MYVIMRC
endif

call plug#begin('~/.vim/plugged')

Plug 'w0rp/ale'
Plug 'vim-airline/vim-airline'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-unimpaired'
Plug 'morhetz/gruvbox'
Plug 'leafgarland/typescript-vim'
Plug '$HOME/local/projects/vim-cds'

" Add plugins to &runtimepath
call plug#end()

(The local plugin is the last one in the list).

Going back to the hook for ALE, this is in the form of a short Vimscript that uses various built-in ALE functions to define and register vim-cds.

00:21:18: The ALE hook script references another helper script startcdslsp which starts up the language server from the @Sisn/cds-lsp package, which right now has been lifted out of the vsix archive and placed directly inside the vim-cds plugin directory.

00:23:45: A quick check in a CDS file db/data-model.cds shows us that the vim-cds plugin, as it stands right now, is working for us, connected to the @Sisn/cds-lsp based language server, and active in the context of ALE.

We also try out some LSP based standard functions that are facilitated by ALE and implemented by the @Sisn/cds-lsp package, such as ALEGoToDefinition.

00:28:52: Wanting to replace the “dropped-in” version of the @Sisn/cds-lsp package with one that will be installed via npm, we look in startcdslsp to first of all find out where and how it’s used (via STDIO), before renaming it to move it out of the way.

00:33:00: Pondering the question whether we want to require a global install of @Sisn/cds-lsp or one only local to the installation location of the vim-cds plugin.

00:33:55: Initialising the vim-cds plugin location as an NPM project (with npm init) and installing @Sisn/cds-lsp locally in that location.

00:35:30: Noticing the presence also (in the node_modules/ directory) of the @Sisn/cds-compiler package, we check with npm info to see why - and yes, our suspicions are confirmed - there’s a dependency upon it (we saw this in the output earlier).

00:37:09: Noticing that this version of @Sisn/cds-lsp has no intermediate src/ directory. Regardless, we now attempt to kick off this new version / instance of the server code, by adding the --stdio parameter on invocation directly in the startcdslsp script.

00:47:30: Pondering how to make a Vim plugin completely independent and portable. Some questions I’m finding hard to answer right now, and we use a bit of loose brained hacking on the ALE cds.vim script to think about the questions.

As we come to the end of this episode, they’re still not completely resolved. But that’s fine - this is very much a side project, and something to learn from as we go.

Until next time!
2 Comments