diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/eval.txt | 19 | ||||
-rw-r--r-- | runtime/doc/lsp.txt | 13 | ||||
-rw-r--r-- | runtime/doc/treesitter.txt | 2 | ||||
-rw-r--r-- | runtime/filetype.vim | 8 | ||||
-rw-r--r-- | runtime/lua/vim/lsp.lua | 6 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 55 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/protocol.lua | 24 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 3 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/highlighter.lua | 3 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/languagetree.lua | 5 |
10 files changed, 126 insertions, 12 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 7c6013f1b2..343e35bf66 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2487,6 +2487,7 @@ wait({timeout}, {condition}[, {interval}]) wildmenumode() Number whether 'wildmenu' mode is active win_findbuf({bufnr}) List find windows containing {bufnr} win_getid([{win} [, {tab}]]) Number get |window-ID| for {win} in {tab} +win_gettype([{nr}]) String type of window {nr} win_gotoid({expr}) Number go to |window-ID| {expr} win_id2tabwin({expr}) List get tab and window nr from |window-ID| win_id2win({expr}) Number get window nr from |window-ID| @@ -9277,6 +9278,24 @@ win_getid([{win} [, {tab}]]) *win_getid()* number {tab}. The first tab has number one. Return zero if the window cannot be found. +win_gettype([{nr}]) *win_gettype()* + Return the type of the window: + "autocmd" autocommand window. Temporary window + used to execute autocommands. + "popup" popup window |popup| + "preview" preview window |preview-window| + "command" command-line window |cmdwin| + (empty) normal window + "unknown" window {nr} not found + + When {nr} is omitted return the type of the current window. + When {nr} is given return the type of this window by number or + |window-ID|. + + Also see the 'buftype' option. When running a terminal in a + popup window then 'buftype' is "terminal" and win_gettype() + returns "popup". + win_gotoid({expr}) *win_gotoid()* Go to window with ID {expr}. This may also change the current tabpage. diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index 4cab716df0..5747ba6044 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -996,6 +996,19 @@ type_definition() *vim.lsp.buf.type_definition()* Jumps to the definition of the type of the symbol under the cursor. +add_workspace_folder({path}) *vim.lsp.buf.add_workspace_folder()* + Add the folder at path to the workspace folders. If {path} is + not provided, the user will be prompted for a path using + |input()|. + +remove_workspace_folder({path}) *vim.lsp.buf.remove_workspace_folder()* + Remove the folder at path from the workspace folders. If + {path} is not provided, the user will be prompted for + a path using |input()|. + +list_workspace_folders() *vim.lsp.buf.list_workspace_folders()* + List all folders in the workspace. + workspace_symbol({query}) *vim.lsp.buf.workspace_symbol()* Lists all symbols in the current workspace in the quickfix window. diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt index b6a238f158..ae77b0a35a 100644 --- a/runtime/doc/treesitter.txt +++ b/runtime/doc/treesitter.txt @@ -47,7 +47,7 @@ Whenever you need to access the current syntax tree, parse the buffer: > tstree = parser:parse() -<This will return an immutable tree that represents the current state of the +<This will return a table of immutable trees that represent the current state of the buffer. When the plugin wants to access the state after a (possible) edit it should call `parse()` again. If the buffer wasn't edited, the same tree will be returned again without extra work. If the buffer was parsed before, diff --git a/runtime/filetype.vim b/runtime/filetype.vim index 4e54bcaefd..b9d2a43d5d 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -693,15 +693,9 @@ au BufNewFile,BufRead *.haml setf haml " Hamster Classic | Playground files au BufNewFile,BufRead *.hsm setf hamster -au BufNewFile,BufRead *.hsc - \ if match(join(getline(1,10), "\n"), '\%(^\|\n\)\s*\%({-#\_s*LANGUAGE\>\|\<module\>\)') != -1 | - \ setf haskell | - \ else | - \ setf hamster | - \ endif " Haskell -au BufNewFile,BufRead *.hs,*.hs-boot setf haskell +au BufNewFile,BufRead *.hs,*.hsc,*.hs-boot setf haskell au BufNewFile,BufRead *.lhs setf lhaskell au BufNewFile,BufRead *.chs setf chaskell au BufNewFile,BufRead cabal.project setf cabalproject diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index dacdbcfa17..92f56b2ddf 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -597,7 +597,10 @@ function lsp.start_client(config) -- -- workspace folder in the user interface. -- name -- } - workspaceFolders = nil; + workspaceFolders = {{ + uri = vim.uri_from_fname(config.root_dir); + name = string.format("%s", config.root_dir); + }}; } if config.before_init then -- TODO(ashkan) handle errors here. @@ -610,6 +613,7 @@ function lsp.start_client(config) rpc.notify('initialized', {[vim.type_idx]=vim.types.dictionary}) client.initialized = true uninitialized_clients[client_id] = nil + client.workspaceFolders = initialize_params.workspaceFolders client.server_capabilities = assert(result.capabilities, "initialize result doesn't contain capabilities") -- These are the cleaned up capabilities we use for dynamically deciding -- when to send certain events to clients. diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index fa62905c0a..a70581478b 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -238,6 +238,61 @@ function M.outgoing_calls() end) end +--- List workspace folders. +function M.list_workspace_folders() + local workspace_folders = {} + for _, client in ipairs(vim.lsp.buf_get_clients()) do + for _, folder in ipairs(client.workspaceFolders) do + table.insert(workspace_folders, folder.name) + end + end + return workspace_folders +end + +--- Add a workspace folder. +function M.add_workspace_folder(workspace_folder) + workspace_folder = workspace_folder or npcall(vfn.input, "Workspace Folder: ", vfn.expand('%:p:h')) + vim.api.nvim_command("redraw") + if not (workspace_folder and #workspace_folder > 0) then return end + if vim.fn.isdirectory(workspace_folder) == 0 then + print(workspace_folder, " is not a valid directory") + return + end + local params = util.make_workspace_params({{uri = vim.uri_from_fname(workspace_folder); name = workspace_folder}}, {{}}) + for _, client in ipairs(vim.lsp.buf_get_clients()) do + local found = false + for _, folder in ipairs(client.workspaceFolders) do + if folder.name == workspace_folder then + found = true + print(workspace_folder, "is already part of this workspace") + break + end + end + if not found then + vim.lsp.buf_notify(0, 'workspace/didChangeWorkspaceFolders', params) + table.insert(client.workspaceFolders, params.event.added[1]) + end + end +end + +--- Remove a workspace folder. +function M.remove_workspace_folder(workspace_folder) + workspace_folder = workspace_folder or npcall(vfn.input, "Workspace Folder: ", vfn.expand('%:p:h')) + vim.api.nvim_command("redraw") + if not (workspace_folder and #workspace_folder > 0) then return end + local params = util.make_workspace_params({{}}, {{uri = vim.uri_from_fname(workspace_folder); name = workspace_folder}}) + for _, client in ipairs(vim.lsp.buf_get_clients()) do + for idx, folder in ipairs(client.workspaceFolders) do + if folder.name == workspace_folder then + vim.lsp.buf_notify(0, 'workspace/didChangeWorkspaceFolders', params) + client.workspaceFolders[idx] = nil + return + end + end + end + print(workspace_folder, "is not currently part of the workspace") +end + --- Lists all symbols in the current workspace in the quickfix window. --- --- The list is filtered against {query}; if the argument is omitted from the diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 07b4e8b926..218424fa14 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -716,6 +716,7 @@ function protocol.make_client_capabilities() }; hierarchicalWorkspaceSymbolSupport = true; }; + workspaceFolders = true; applyEdit = true; }; callHierarchy = { @@ -974,6 +975,28 @@ function protocol.resolve_capabilities(server_capabilities) error("The server sent invalid implementationProvider") end + local workspace = server_capabilities.workspace + local workspace_properties = {} + if workspace == nil or workspace.workspaceFolders == nil then + -- Defaults if omitted. + workspace_properties = { + workspace_folder_properties = { + supported = false; + changeNotifications=false; + } + } + elseif type(workspace.workspaceFolders) == 'table' then + workspace_properties = { + workspace_folder_properties = { + supported = if_nil(workspace.workspaceFolders.supported, false); + changeNotifications = if_nil(workspace.workspaceFolders.changeNotifications, false); + + } + } + else + error("The server sent invalid workspace") + end + local signature_help_properties if server_capabilities.signatureHelpProvider == nil then signature_help_properties = { @@ -993,6 +1016,7 @@ function protocol.resolve_capabilities(server_capabilities) return vim.tbl_extend("error" , text_document_sync_properties , signature_help_properties + , workspace_properties , general_properties ) end diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 3deec6d74e..f78a36fda2 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1314,6 +1314,9 @@ function M.make_text_document_params() return { uri = vim.uri_from_bufnr(0) } end +function M.make_workspace_params(added, removed) + return { event = { added = added; removed = removed; } } +end --- Returns visual width of tabstop. --- --@see |softtabstop| diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua index 60db7f24cf..275e960e28 100644 --- a/runtime/lua/vim/treesitter/highlighter.lua +++ b/runtime/lua/vim/treesitter/highlighter.lua @@ -219,7 +219,8 @@ local function on_line_impl(self, buf, line) a.nvim_buf_set_extmark(buf, ns, start_row, start_col, { end_line = end_row, end_col = end_col, hl_group = hl, - ephemeral = true + ephemeral = true, + priority = 100 -- Low but leaves room below }) end if start_row > line then diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua index 70e2ac4c62..a8b62e21b9 100644 --- a/runtime/lua/vim/treesitter/languagetree.lua +++ b/runtime/lua/vim/treesitter/languagetree.lua @@ -104,12 +104,14 @@ function LanguageTree:parse() parser:set_included_ranges(ranges) local tree, tree_changes = parser:parse(old_tree, self._source) + self:_do_callback('changedtree', tree_changes, tree) table.insert(self._trees, tree) vim.list_extend(changes, tree_changes) end else local tree, tree_changes = parser:parse(old_trees[1], self._source) + self:_do_callback('changedtree', tree_changes, tree) table.insert(self._trees, tree) vim.list_extend(changes, tree_changes) @@ -146,7 +148,6 @@ function LanguageTree:parse() self._valid = true - self:_do_callback('changedtree', changes) return self._trees, changes end @@ -432,7 +433,7 @@ local function region_contains(region, range) end function LanguageTree:contains(range) - for _, region in pairs(self._region) do + for _, region in pairs(self._regions) do if region_contains(region, range) then return true end |