|
|
||
|---|---|---|
| .gitignore | ||
| README.md | ||
| cds-install | ||
| cds-start | ||
README.md
CDS LSP NVIM Quick HowTo
Setup
TBD: needs to be generalized
This HowTo assumes that you have a $HOME/bin folder that is in your $PATH.
This repository needs to be installed $HOME/bin/cds.
- run
./cds-install.
This installs the newest cds-lsp from npmjs.com
into the foldercds-lsp. - add the following configuration to your
init.lua
If you have problems with the installation delete the file npm-shrinkwraps.json. This file contains some references to an internal SAP repository which is not needed
local lspconfig = require'lspconfig'
local configs = require'lspconfig.configs'
local on_attach = function(client, bufnr)
vim.notify("sapcds_lsp attached to buffer", vim.log.levels.WARN)
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
if client.server_capabilities.documentFormattingProvider then
vim.cmd("nnoremap <silent><buffer> gf :lua vim.lsp.buf.format({async = true})<CR>")
end
if client.server_capabilities.documentRangeFormattingProvider then
vim.cmd("xnoremap <silent><buffer> gf :lua vim.lsp.buf.range_formatting({})<CR>")
end
end
configs.sapcds_lsp = {
default_config = {
cmd = {vim.fn.expand("$HOME/bin/cds/cds-start")}; -- this executable must be there
filetypes = {'cds'};
root_dir = function(fname)
return vim.fn.getcwd()
end;
settings = {};
};
}
if lspconfig.sapcds_lsp.setup then
vim.notify("Calling sapcds_lsp setup", vim.log.levels.WARN)
lspconfig.sapcds_lsp.setup{
on_attach = on_attach,
autostart = true ,
capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()),
}
end
Configure shortcuts / key mappings in NVIM
There are general key mappings and a few key mappings only for CDS files
(should probalby generalize the latter ones and make all key mappings only available when a lsp server is attached)
Helper function in lua.init
local function map(mode, lhs, rhs, opts)
local options = {noremap = true}
if opts then options = vim.tbl_extend('force', options, opts) end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
General key mappings
-- map('n', 'gd', ':lua vim.lsp.buf.definition()<CR>')
map('n', 'gh', ':lua vim.lsp.buf.hover()<CR>')
map('n', 'gi', ':lua vim.lsp.buf.document_highlight()<CR>')
map('n', 'gl', ':lua vim.lsp.buf.clear_references()<CR>')
map('i', '<C-k>', '<ESC>:lua vim.lsp.buf.hover()<CR>')
map('n', 'ga', ':lua vim.lsp.buf.code_action()<CR>')
map('n', 'gA', ':Telescope lsp_range_code_actions<CR>')
-- map('n', 'gD', ':lua vim.lsp.buf.implementation()<CR>')
map('n', '<c-k>', ':lua vim.lsp.buf.signature_help()<CR>')
-- map('n', 'gr', ':lua vim.lsp.buf.references()<CR>')
map('n', 'gR', ':lua vim.lsp.buf.rename()<CR>')
CDS key mappings
The CDS key mappings gf are defined in the on_attach handler (see above)