-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcds.lua
More file actions
162 lines (157 loc) · 5.99 KB
/
cds.lua
File metadata and controls
162 lines (157 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
pattern = { "*.cds" },
command = "set filetype=cds",
})
require("lspconfig").cds_lsp.setup({})
-- Install tree-sitter-cds for syntax highlighting
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.cds = {
install_info = {
-- local path or git repo
-- url = '/path/to/tree-sitter-cds',
url = "https://github.com/cap-js-community/tree-sitter-cds.git",
files = { "src/parser.c", "src/scanner.c" },
branch = "main",
generate_requires_npm = false,
requires_generate_from_grammar = false,
},
filetype = "cds",
-- additional filetypes that use this parser
used_by = { "cdl", "hdbcds" },
}
vim.cmd("TSInstall cds")
-- set colorscheme to evening cause Default scheme tokionight, which is great for most filetypes, looks
-- awful for cds files
vim.cmd("colorscheme evening")
-- -- retrieve the content of a URL
-- This could be used to copy the scm files from inside the container dynamically
-- At the moment the scm files for tree-sitter-cds are copied when the image is build.
-- If the tree-sitter-cds team adds additional scm files to the repo these are not detected
-- automatically.
--
-- local nvimconfigpath = vim.fn.stdpath("config")
-- local cdsTreeSitterPath = "" .. nvimconfigpath .. "/queries/cds"
-- vim.notify("cdsTreeSitterPath: " .. cdsTreeSitterPath, vim.log.levels.WARN)
-- vim.cmd("!mkdir -p " .. cdsTreeSitterPath)
--
-- local http = require("socket.http")
-- local body, code = http.request("https://github.com/cap-js-community/tree-sitter-cds/raw/main/nvim/locals.scm")
-- if not body then
-- error(code)
-- end
-- -- save the content to a file
-- local f = assert(io.open(cdsTreeSitterPath .. "/locals.scm", "wb")) -- open in "binary" mode
-- f:write(body)
-- f:close()
-- I left the following code in this file cause it helps me to understand how lspconfig works and
-- how it can be adjusted
-- This content is no longer used
--
-- 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/helmut/.volta/bin/cds-lsp --stdio") }, -- this executable must be there
-- -- filetypes = { "cds" },
-- -- root_dir = function(fname)
-- -- vim.notify("get cwd", vim.log.levels.WARN)
-- -- cwd = vim.fn.getcwd()
-- -- vim.notify("cwd = " + cwd, vim.log.levels.WARN)
-- -- return vim.fn.getcwd()
-- -- end,
-- -- settings = {},
-- },
-- }
--
-- function serializeTable(val, name, skipnewlines, depth)
-- skipnewlines = skipnewlines or false
-- depth = depth or 0
--
-- local tmp = string.rep(" ", depth)
-- if name then
-- if not string.match(name, "^[a-zA-z_][a-zA-Z0-9_]*$") then
-- name = string.gsub(name, "'", "\\'")
-- name = "['" .. name .. "']"
-- end
-- tmp = tmp .. name .. " = "
-- end
--
-- if type(val) == "table" then
-- tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")
--
-- for k, v in pairs(val) do
-- tmp = tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
-- end
--
-- tmp = tmp .. string.rep(" ", depth) .. "}"
-- elseif type(val) == "number" then
-- tmp = tmp .. tostring(val)
-- elseif type(val) == "string" then
-- tmp = tmp .. string.format("%q", val)
-- elseif type(val) == "boolean" then
-- tmp = tmp .. (val and "true" or "false")
-- else
-- tmp = tmp .. '"[inserializeable datatype:' .. type(val) .. ']"'
-- end
--
-- return tmp
-- end
--
-- -- if lspconfig.sapcds_lsp.setup then
-- vim.notify("Calling sapcds_lsp setup", vim.log.levels.WARN)
-- local cds_config = {
-- capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()),
-- cmd = { vim.fn.expand("/home/helmut/.volta/bin/cds-lsp)"), "--stdio" }, -- this executable must be there
-- filetypes = { "cds" },
-- root_dir = function(fname)
-- vim.notify("get cwd", vim.log.levels.WARN)
-- local cwd = vim.fs.dirname(vim.fs.find({ ".cdsrc.json", "package.json" }, { upward = true })[1])
-- vim.notify("cwd = " + cwd, vim.log.levels.WARN)
-- return cwd
-- end,
-- 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,
-- autostart = true,
-- }
-- -- vim.notify(serializeTable(cds_config))
-- lspconfig.sapcds_lsp.setup(cds_config)
-- local cds_cfg = lspconfig.sapcds_lsp
-- vim.notify(serializeTable(cds_cfg))
-- vim.notify("Called sapcds_lsp setup", vim.log.levels.WARN)
-- -- end
--
-- vim.api.nvim_create_autocmd("LspAttach", {
-- callback = function(args)
-- local bufnr = args.buf
-- local client = vim.lsp.get_client_by_id(args.data.client_id)
-- vim.notify("bufnr = " .. bufnr, vim.log.levels.WARN)
-- vim.notify("client = " .. args.data.client_id, vim.log.levels.WARN)
-- end,
-- })