diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/autoload/spellfile.vim | 10 | ||||
-rw-r--r-- | runtime/doc/options.txt | 8 | ||||
-rw-r--r-- | runtime/doc/spell.txt | 14 | ||||
-rw-r--r-- | runtime/doc/vim_diff.txt | 1 | ||||
-rw-r--r-- | runtime/filetype.vim | 8 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 45 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 42 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter.lua | 22 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/query.lua | 56 |
9 files changed, 133 insertions, 73 deletions
diff --git a/runtime/autoload/spellfile.vim b/runtime/autoload/spellfile.vim index d098902305..e36e2f936b 100644 --- a/runtime/autoload/spellfile.vim +++ b/runtime/autoload/spellfile.vim @@ -1,13 +1,9 @@ " Vim script to download a missing spell file if !exists('g:spellfile_URL') - " Prefer using http:// when netrw should be able to use it, since - " more firewalls let this through. - if executable("curl") || executable("wget") || executable("fetch") - let g:spellfile_URL = 'http://ftp.vim.org/pub/vim/runtime/spell' - else - let g:spellfile_URL = 'ftp://ftp.vim.org/pub/vim/runtime/spell' - endif + " Always use https:// because it's secure. The certificate is for nluug.nl, + " thus we can't use the alias ftp.vim.org here. + let g:spellfile_URL = 'https://ftp.nluug.nl/pub/vim/runtime/spell' endif let s:spellfile_URL = '' " Start with nothing so that s:donedict is reset. diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 71c4620f1e..bd61d113fb 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -5672,6 +5672,14 @@ A jump table for the options with a short description can be found at |Q_op|. up to the first character that is not an ASCII letter or number and not a dash. Also see |set-spc-auto|. + *'spelloptions'* *'spo'* +'spelloptions' 'spo' string (default "") + local to buffer + A comma separated list of options for spell checking: + camel When a word is CamelCased, assume "Cased" is a + separate word: every upper-case character in a word + that comes after a lower case character indicates the + start of a new word. *'spellsuggest'* *'sps'* 'spellsuggest' 'sps' string (default "best") diff --git a/runtime/doc/spell.txt b/runtime/doc/spell.txt index b88e26cdff..0eef976819 100644 --- a/runtime/doc/spell.txt +++ b/runtime/doc/spell.txt @@ -187,6 +187,9 @@ When there is a line break right after a sentence the highlighting of the next line may be postponed. Use |CTRL-L| when needed. Also see |set-spc-auto| for how it can be set automatically when 'spelllang' is set. +The 'spelloptions' option has a few more flags that influence the way spell +checking works. + Vim counts the number of times a good word is encountered. This is used to sort the suggestions: words that have been seen before get a small bonus, words that have been seen often get a bigger bonus. The COMMON item in the @@ -617,11 +620,12 @@ ask you where to write the file (there must be a writable directory in 'runtimepath' for this). The plugin has a default place where to look for spell files, on the Vim ftp -server. If you want to use another location or another protocol, set the -g:spellfile_URL variable to the directory that holds the spell files. The -|netrw| plugin is used for getting the file, look there for the specific -syntax of the URL. Example: > - let g:spellfile_URL = 'http://ftp.vim.org/vim/runtime/spell' +server. The protocol used is SSL (https://) for security. If you want to use +another location or another protocol, set the g:spellfile_URL variable to the +directory that holds the spell files. You can use http:// or ftp://, but you +are taking a security risk then. The |netrw| plugin is used for getting the +file, look there for the specific syntax of the URL. Example: > + let g:spellfile_URL = 'https://ftp.nluug.nl/vim/runtime/spell' You may need to escape special characters. The plugin will only ask about downloading a language once. If you want to diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 4bcea3e3fe..3090be82f2 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -508,7 +508,6 @@ Test functions: test_alloc_fail() test_autochdir() test_disable_char_avail() - test_garbagecollect_now() test_null_channel() test_null_dict() test_null_job() diff --git a/runtime/filetype.vim b/runtime/filetype.vim index 32bd6daba0..c464e8cebd 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -1158,10 +1158,10 @@ au BufNewFile,BufRead *.papp,*.pxml,*.pxsl setf papp au BufNewFile,BufRead */etc/passwd,*/etc/passwd-,*/etc/passwd.edit,*/etc/shadow,*/etc/shadow-,*/etc/shadow.edit,*/var/backups/passwd.bak,*/var/backups/shadow.bak setf passwd " Pascal (also *.p) -au BufNewFile,BufRead *.pas setf pascal +au BufNewFile,BufRead *.pas,*.pp setf pascal -" Delphi project file -au BufNewFile,BufRead *.dpr setf pascal +" Delphi or Lazarus program file +au BufNewFile,BufRead *.dpr,*.lpr setf pascal " PDF au BufNewFile,BufRead *.pdf setf pdf @@ -1732,7 +1732,7 @@ au BufNewFile,BufRead *.texinfo,*.texi,*.txi setf texinfo au BufNewFile,BufRead texmf.cnf setf texmf " Tidy config -au BufNewFile,BufRead .tidyrc,tidyrc setf tidy +au BufNewFile,BufRead .tidyrc,tidyrc,tidy.conf setf tidy " TF mud client au BufNewFile,BufRead *.tf,.tfrc,tfrc setf tf diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 3060776d83..c015884f5b 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -1,9 +1,7 @@ local vim = vim local validate = vim.validate -local api = vim.api local vfn = vim.fn local util = require 'vim.lsp.util' -local list_extend = vim.list_extend local M = {} @@ -154,36 +152,14 @@ end --@param start_pos ({number, number}, optional) mark-indexed position. ---Defaults to the end of the last visual selection. function M.range_formatting(options, start_pos, end_pos) - validate { - options = {options, 't', true}; - start_pos = {start_pos, 't', true}; - end_pos = {end_pos, 't', true}; - } + validate { options = {options, 't', true} } local sts = vim.bo.softtabstop; options = vim.tbl_extend('keep', options or {}, { tabSize = (sts > 0 and sts) or (sts < 0 and vim.bo.shiftwidth) or vim.bo.tabstop; insertSpaces = vim.bo.expandtab; }) - local A = list_extend({}, start_pos or api.nvim_buf_get_mark(0, '<')) - local B = list_extend({}, end_pos or api.nvim_buf_get_mark(0, '>')) - -- convert to 0-index - A[1] = A[1] - 1 - B[1] = B[1] - 1 - -- account for encoding. - if A[2] > 0 then - A = {A[1], util.character_offset(0, A[1], A[2])} - end - if B[2] > 0 then - B = {B[1], util.character_offset(0, B[1], B[2])} - end - local params = { - textDocument = { uri = vim.uri_from_bufnr(0) }; - range = { - start = { line = A[1]; character = A[2]; }; - ["end"] = { line = B[1]; character = B[2]; }; - }; - options = options; - } + local params = util.make_given_range_params(start_pos, end_pos) + params.options = options return request('textDocument/rangeFormatting', params) end @@ -308,6 +284,21 @@ function M.code_action(context) request('textDocument/codeAction', params) end +--- Performs |vim.lsp.buf.code_action()| for a given range. +--- +--@param context: (table, optional) Valid `CodeActionContext` object +--@param start_pos ({number, number}, optional) mark-indexed position. +---Defaults to the start of the last visual selection. +--@param end_pos ({number, number}, optional) mark-indexed position. +---Defaults to the end of the last visual selection. +function M.range_code_action(context, start_pos, end_pos) + validate { context = { context, 't', true } } + context = context or { diagnostics = util.get_line_diagnostics() } + local params = util.make_given_range_params(start_pos, end_pos) + params.context = context + request('textDocument/codeAction', params) +end + --- Executes an LSP server command. --- --@param command A valid `ExecuteCommandParams` object diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 28bc8cb736..53f88dea7d 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -800,13 +800,14 @@ function M.fancy_floating_markdown(contents, opts) local width, height = M._make_floating_popup_size(stripped, opts) -- Insert blank line separator after code block - local insert_separator = opts.separator or true + local insert_separator = opts.separator + if insert_separator == nil then insert_separator = true end if insert_separator then for i, h in ipairs(highlights) do h.start = h.start + i - 1 h.finish = h.finish + i - 1 if h.finish + 1 <= #stripped then - table.insert(stripped, h.finish + 1, string.rep("─", width)) + table.insert(stripped, h.finish + 1, string.rep("─", math.min(width, opts.wrap_at))) height = height + 1 end end @@ -1465,11 +1466,46 @@ end function M.make_range_params() local position = make_position_param() return { - textDocument = { uri = vim.uri_from_bufnr(0) }, + textDocument = M.make_text_document_params(), range = { start = position; ["end"] = position; } } end +--- Using the given range in the current buffer, creates an object that +--- is similar to |vim.lsp.util.make_range_params()|. +--- +--@param start_pos ({number, number}, optional) mark-indexed position. +---Defaults to the start of the last visual selection. +--@param end_pos ({number, number}, optional) mark-indexed position. +---Defaults to the end of the last visual selection. +--@returns { textDocument = { uri = `current_file_uri` }, range = { start = +---`start_position`, end = `end_position` } } +function M.make_given_range_params(start_pos, end_pos) + validate { + start_pos = {start_pos, 't', true}; + end_pos = {end_pos, 't', true}; + } + local A = list_extend({}, start_pos or api.nvim_buf_get_mark(0, '<')) + local B = list_extend({}, end_pos or api.nvim_buf_get_mark(0, '>')) + -- convert to 0-index + A[1] = A[1] - 1 + B[1] = B[1] - 1 + -- account for encoding. + if A[2] > 0 then + A = {A[1], M.character_offset(0, A[1], A[2])} + end + if B[2] > 0 then + B = {B[1], M.character_offset(0, B[1], B[2])} + end + return { + textDocument = M.make_text_document_params(), + range = { + start = {line = A[1], character = A[2]}, + ['end'] = {line = B[1], character = B[2]} + } + } +end + --- Creates a `TextDocumentIdentifier` object for the current buffer. --- --@returns `TextDocumentIdentifier` diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index 3a475b8f98..77bbfaa3ad 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -21,7 +21,9 @@ function Parser:parse() return self.tree end local changes - self.tree, changes = self._parser:parse_buf(self.bufnr) + + self.tree, changes = self._parser:parse(self:input_source()) + self.valid = true if not vim.tbl_isempty(changes) then @@ -33,6 +35,10 @@ function Parser:parse() return self.tree, changes end +function Parser:input_source() + return self.bufnr or self.str +end + function Parser:_on_bytes(bufnr, changed_tick, start_row, start_col, start_byte, old_row, old_col, old_byte, @@ -152,4 +158,18 @@ function M.get_parser(bufnr, lang, buf_attach_cbs) return parsers[id] end +function M.get_string_parser(str, lang) + vim.validate { + str = { str, 'string' }, + lang = { lang, 'string' } + } + language.require_language(lang) + + local self = setmetatable({str=str, lang=lang, valid=false}, Parser) + self._parser = vim._create_ts_parser(lang) + self:parse() + + return self +end + return M diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua index ca27a50c6a..494fb59fa7 100644 --- a/runtime/lua/vim/treesitter/query.lua +++ b/runtime/lua/vim/treesitter/query.lua @@ -28,21 +28,27 @@ end --- Gets the text corresponding to a given node -- @param node the node -- @param bufnr the buffer from which the node in extracted. -function M.get_node_text(node, bufnr) - local start_row, start_col, end_row, end_col = node:range() - if start_row ~= end_row then - return nil +function M.get_node_text(node, source) + local start_row, start_col, start_byte = node:start() + local end_row, end_col, end_byte = node:end_() + + if type(source) == "number" then + if start_row ~= end_row then + return nil + end + local line = a.nvim_buf_get_lines(source, start_row, start_row+1, true)[1] + return string.sub(line, start_col+1, end_col) + elseif type(source) == "string" then + return source:sub(start_byte+1, end_byte) end - local line = a.nvim_buf_get_lines(bufnr, start_row, start_row+1, true)[1] - return string.sub(line, start_col+1, end_col) end -- Predicate handler receive the following arguments -- (match, pattern, bufnr, predicate) local predicate_handlers = { - ["eq?"] = function(match, _, bufnr, predicate) + ["eq?"] = function(match, _, source, predicate) local node = match[predicate[2]] - local node_text = M.get_node_text(node, bufnr) + local node_text = M.get_node_text(node, source) local str if type(predicate[3]) == "string" then @@ -50,7 +56,7 @@ local predicate_handlers = { str = predicate[3] else -- (#eq? @aa @bb) - str = M.get_node_text(match[predicate[3]], bufnr) + str = M.get_node_text(match[predicate[3]], source) end if node_text ~= str or str == nil then @@ -60,7 +66,7 @@ local predicate_handlers = { return true end, - ["lua-match?"] = function(match, _, bufnr, predicate) + ["lua-match?"] = function(match, _, source, predicate) local node = match[predicate[2]] local regex = predicate[3] local start_row, _, end_row, _ = node:range() @@ -68,7 +74,7 @@ local predicate_handlers = { return false end - return string.find(M.get_node_text(node, bufnr), regex) + return string.find(M.get_node_text(node, source), regex) end, ["match?"] = (function() @@ -88,7 +94,7 @@ local predicate_handlers = { end }) - return function(match, _, bufnr, pred) + return function(match, _, source, pred) local node = match[pred[2]] local start_row, start_col, end_row, end_col = node:range() if start_row ~= end_row then @@ -96,13 +102,13 @@ local predicate_handlers = { end local regex = compiled_vim_regexes[pred[3]] - return regex:match_line(bufnr, start_row, start_col, end_col) + return regex:match_line(source, start_row, start_col, end_col) end end)(), - ["contains?"] = function(match, _, bufnr, predicate) + ["contains?"] = function(match, _, source, predicate) local node = match[predicate[2]] - local node_text = M.get_node_text(node, bufnr) + local node_text = M.get_node_text(node, source) for i=3,#predicate do if string.find(node_text, predicate[i], 1, true) then @@ -139,7 +145,7 @@ local function xor(x, y) return (x or y) and not (x and y) end -function Query:match_preds(match, pattern, bufnr) +function Query:match_preds(match, pattern, source) local preds = self.info.patterns[pattern] for _, pred in pairs(preds or {}) do @@ -164,7 +170,7 @@ function Query:match_preds(match, pattern, bufnr) return false end - local pred_matches = handler(match, pattern, bufnr, pred) + local pred_matches = handler(match, pattern, source, pred) if not xor(is_not, pred_matches) then return false @@ -182,15 +188,15 @@ end -- -- @returns The matching capture id -- @returns The captured node -function Query:iter_captures(node, bufnr, start, stop) - if bufnr == 0 then - bufnr = vim.api.nvim_get_current_buf() +function Query:iter_captures(node, source, start, stop) + if type(source) == "number" and source == 0 then + source = vim.api.nvim_get_current_buf() end local raw_iter = node:_rawquery(self.query, true, start, stop) local function iter() local capture, captured_node, match = raw_iter() if match ~= nil then - local active = self:match_preds(match, match.pattern, bufnr) + local active = self:match_preds(match, match.pattern, source) match.active = active if not active then return iter() -- tail call: try next match @@ -210,15 +216,15 @@ end -- -- @returns The matching pattern id -- @returns The matching match -function Query:iter_matches(node, bufnr, start, stop) - if bufnr == 0 then - bufnr = vim.api.nvim_get_current_buf() +function Query:iter_matches(node, source, start, stop) + if type(source) == "number" and source == 0 then + source = vim.api.nvim_get_current_buf() end local raw_iter = node:_rawquery(self.query, false, start, stop) local function iter() local pattern, match = raw_iter() if match ~= nil then - local active = self:match_preds(match, pattern, bufnr) + local active = self:match_preds(match, pattern, source) if not active then return iter() -- tail call: try next match end |