diff options
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/filetype.lua | 81 | ||||
-rw-r--r-- | runtime/lua/vim/lsp.lua | 8 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/handlers.lua | 12 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/sync.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/languagetree.lua | 2 |
6 files changed, 77 insertions, 30 deletions
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index f7048f3709..54b20f7391 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -19,7 +19,13 @@ local function starsetf(ft) }} end +---@private +local function getline(bufnr, lnum) + return api.nvim_buf_get_lines(bufnr, lnum-1, lnum, false)[1] +end + -- Filetypes based on file extension +-- luacheck: push no unused args local extension = { -- BEGIN EXTENSION ["8th"] = "8th", @@ -635,6 +641,13 @@ local extension = { tssop = "tssop", tutor = "tutor", twig = "twig", + ts = function(path, bufnr) + if getline(bufnr, 1):find("<%?xml") then + return "xml" + else + return "typescript" + end + end, tsx = "typescriptreact", uc = "uc", uit = "uil", @@ -774,6 +787,12 @@ local extension = { xml = function() vim.fn["dist#ft#FTxml"]() end, y = function() vim.fn["dist#ft#FTy"]() end, zsql = function() vim.fn["dist#ft#SQL"]() end, + txt = function(path, bufnr) + --helpfiles match *.txt, but should have a modeline as last line + if not getline(bufnr, -1):match("vim:.*ft=help") then + return "text" + end + end, -- END EXTENSION } @@ -1075,7 +1094,7 @@ local pattern = { [".*/etc/a2ps%.cfg"] = "a2ps", [".*/usr/share/alsa/alsa%.conf"] = "alsaconf", [".*/etc/asound%.conf"] = "alsaconf", - [".*/etc/apache2/sites-.*/.*%.com"] = "apache", + [".*/etc/apache2/sites%-.*/.*%.com"] = "apache", [".*/etc/httpd/.*%.conf"] = "apache", [".*/%.aptitude/config"] = "aptconf", ["[mM]akefile%.am"] = "automake", @@ -1096,7 +1115,7 @@ local pattern = { ["dictd.*%.conf"] = "dictdconf", [".*/etc/DIR_COLORS"] = "dircolors", [".*/etc/dnsmasq%.conf"] = "dnsmasq", - ["php%.ini-.*"] = "dosini", + ["php%.ini%-.*"] = "dosini", [".*/etc/pacman%.conf"] = "dosini", [".*/etc/yum%.conf"] = "dosini", [".*lvs"] = "dracula", @@ -1122,7 +1141,7 @@ local pattern = { [".*/boot/grub/grub%.conf"] = "grub", [".*/boot/grub/menu%.lst"] = "grub", [".*/etc/grub%.conf"] = "grub", - ["hg-editor-.*%.txt"] = "hgcommit", + ["hg%-editor%-.*%.txt"] = "hgcommit", [".*/etc/host%.conf"] = "hostconf", [".*/etc/hosts%.deny"] = "hostsaccess", [".*/etc/hosts%.allow"] = "hostsaccess", @@ -1190,7 +1209,7 @@ local pattern = { [".*/etc/serial%.conf"] = "setserial", [".*/etc/udev/cdsymlinks%.conf"] = "sh", [".*%._sst%.meta"] = "sisu", - [".*%.-sst%.meta"] = "sisu", + [".*%.%-sst%.meta"] = "sisu", [".*%.sst%.meta"] = "sisu", [".*/etc/slp%.conf"] = "slpconf", [".*/etc/slp%.reg"] = "slpreg", @@ -1199,7 +1218,7 @@ local pattern = { [".*/%.ssh/config"] = "sshconfig", [".*/etc/ssh/sshd_config%.d/.*%.conf"] = "sshdconfig", [".*/etc/sudoers"] = "sudoers", - ["svn-commit.*%.tmp"] = "svn", + ["svn%-commit.*%.tmp"] = "svn", [".*%.swift%.gyb"] = "swiftgyb", [".*/etc/sysctl%.conf"] = "sysctl", [".*/etc/sysctl%.d/.*%.conf"] = "sysctl", @@ -1253,20 +1272,20 @@ local pattern = { [".*/%.gitconfig%.d/.*"] = starsetf('gitconfig'), [".*/%.neomutt/neomuttrc.*"] = starsetf('neomuttrc'), [".*/Xresources/.*"] = starsetf('xdefaults'), - [".*/app-defaults/.*"] = starsetf('xdefaults'), + [".*/app%-defaults/.*"] = starsetf('xdefaults'), [".*/bind/db%..*"] = starsetf('bindzone'), [".*/debian/patches/.*"] = function() vim.fn["dist#ft#Dep3patch"]() end, [".*/etc/Muttrc%.d/.*"] = starsetf('muttrc'), [".*/etc/apache2/.*%.conf.*"] = starsetf('apache'), [".*/etc/apache2/conf%..*/.*"] = starsetf('apache'), - [".*/etc/apache2/mods-.*/.*"] = starsetf('apache'), - [".*/etc/apache2/sites-.*/.*"] = starsetf('apache'), + [".*/etc/apache2/mods%-.*/.*"] = starsetf('apache'), + [".*/etc/apache2/sites%-.*/.*"] = starsetf('apache'), [".*/etc/cron%.d/.*"] = starsetf('crontab'), [".*/etc/dnsmasq%.d/.*"] = starsetf('dnsmasq'), [".*/etc/httpd/conf%..*/.*"] = starsetf('apache'), [".*/etc/httpd/conf%.d/.*%.conf.*"] = starsetf('apache'), - [".*/etc/httpd/mods-.*/.*"] = starsetf('apache'), - [".*/etc/httpd/sites-.*/.*"] = starsetf('apache'), + [".*/etc/httpd/mods%-.*/.*"] = starsetf('apache'), + [".*/etc/httpd/sites%-.*/.*"] = starsetf('apache'), [".*/etc/logcheck/.*%.d.*/.*"] = starsetf('logcheck'), [".*/etc/modprobe%..*"] = starsetf('modconf'), [".*/etc/pam%.d/.*"] = starsetf('pamconf'), @@ -1276,7 +1295,7 @@ local pattern = { [".*/etc/sudoers%.d/.*"] = starsetf('sudoers'), [".*/etc/xinetd%.d/.*"] = starsetf('xinetd'), [".*/etc/yum%.repos%.d/.*"] = starsetf('dosini'), - [".*/gitolite-admin/conf/.*"] = starsetf('gitolite'), + [".*/gitolite%-admin/conf/.*"] = starsetf('gitolite'), [".*/named/db%..*"] = starsetf('bindzone'), [".*/tmp/lltmp.*"] = starsetf('gedcom'), [".*asterisk.*/.*voicemail%.conf.*"] = starsetf('asteriskvm'), @@ -1297,7 +1316,7 @@ local pattern = { ["access%.conf.*"] = starsetf('apache'), ["apache%.conf.*"] = starsetf('apache'), ["apache2%.conf.*"] = starsetf('apache'), - ["bash-fc[-%.]"] = function() vim.fn["dist#ft#SetFileTypeSH"]("bash") end, + ["bash%-fc[-%.]"] = function() vim.fn["dist#ft#SetFileTypeSH"]("bash") end, ["cabal%.project%..*"] = starsetf('cabalproject'), ["crontab%..*"] = starsetf('crontab'), ["drac%..*"] = starsetf('dracula'), @@ -1306,14 +1325,16 @@ local pattern = { ["lilo%.conf.*"] = starsetf('lilo'), ["neomuttrc.*"] = starsetf('neomuttrc'), ["proftpd%.conf.*"] = starsetf('apachestyle'), - ["reportbug-.*"] = starsetf('mail'), + ["reportbug%-.*"] = starsetf('mail'), ["sgml%.catalog.*"] = starsetf('catalog'), ["srm%.conf.*"] = starsetf('apache'), ["tmac%..*"] = starsetf('nroff'), ["zlog.*"] = starsetf('zsh'), ["zsh.*"] = starsetf('zsh'), + ["ae%d+%.txt"] = 'mail', -- END PATTERN } +-- luacheck: pop ---@private local function sort_by_priority(t) @@ -1336,6 +1357,11 @@ end local pattern_sorted = sort_by_priority(pattern) +---@private +local function normalize_path(path) + return (path:gsub("\\", "/")) +end + --- Add new filetype mappings. --- --- Filetype mappings can be added either by extension or by filename (either @@ -1398,11 +1424,11 @@ function M.add(filetypes) end for k, v in pairs(filetypes.filename or {}) do - filename[k] = v + filename[normalize_path(k)] = v end for k, v in pairs(filetypes.pattern or {}) do - pattern[k] = v + pattern[normalize_path(k)] = v end if filetypes.pattern then @@ -1428,15 +1454,22 @@ local function dispatch(ft, path, bufnr, ...) end ---@private -function M.match(bufnr) - local path = api.nvim_buf_get_name(bufnr) +function M.match(name, bufnr) + -- When fired from the main filetypedetect autocommand the {bufnr} argument is omitted, so we use + -- the current buffer. The {bufnr} argument is provided to allow extensibility in case callers + -- wish to perform filetype detection on buffers other than the current one. + bufnr = bufnr or api.nvim_get_current_buf() + + name = normalize_path(name) + -- First check for the simple case where the full path exists as a key + local path = vim.fn.resolve(vim.fn.fnamemodify(name, ":p")) if dispatch(filename[path], path, bufnr) then return end -- Next check against just the file name - local tail = vim.fn.fnamemodify(path, ":t") + local tail = vim.fn.fnamemodify(name, ":t") if dispatch(filename[tail], path, bufnr) then return end @@ -1447,7 +1480,15 @@ function M.match(bufnr) local ft = v[k][1] -- If the pattern contains a / match against the full path, otherwise just the tail local pat = "^" .. k .. "$" - local matches = k:find("/") and path:match(pat) or tail:match(pat) + local matches + if k:find("/") then + -- Similar to |autocmd-pattern|, if the pattern contains a '/' then check for a match against + -- both the short file name (as typed) and the full file name (after expanding to full path + -- and resolving symlinks) + matches = name:match(pat) or path:match(pat) + else + matches = tail:match(pat) + end if matches then if dispatch(ft, path, bufnr, matches) then return @@ -1456,7 +1497,7 @@ function M.match(bufnr) end -- Finally, check file extension - local ext = vim.fn.fnamemodify(path, ":e") + local ext = vim.fn.fnamemodify(name, ":e") if dispatch(extension[ext], path, bufnr) then return end diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index cfbabb12a6..7df0064b6b 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -256,7 +256,7 @@ local function validate_client_config(config) (not config.flags or not config.flags.debounce_text_changes or type(config.flags.debounce_text_changes) == 'number'), - "flags.debounce_text_changes must be nil or a number with the debounce time in milliseconds" + "flags.debounce_text_changes must be a number with the debounce time in milliseconds" ) local cmd, cmd_args = lsp._cmd_parts(config.cmd) @@ -383,8 +383,8 @@ do return end local state = state_by_client[client.id] - local debounce = client.config.flags.debounce_text_changes - if not debounce then + local debounce = client.config.flags.debounce_text_changes or 150 + if debounce == 0 then local changes = state.use_incremental_sync and incremental_changes(client) or full_changes() client.notify("textDocument/didChange", { textDocument = { @@ -897,7 +897,7 @@ function lsp.start_client(config) client.initialized = true uninitialized_clients[client_id] = nil client.workspace_folders = workspace_folders - -- TODO(mjlbach): Backwards compatbility, to be removed in 0.7 + -- TODO(mjlbach): Backwards compatibility, to be removed in 0.7 client.workspaceFolders = client.workspace_folders client.server_capabilities = assert(result.capabilities, "initialize result doesn't contain capabilities") -- These are the cleaned up capabilities we use for dynamically deciding diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 8e3ed9b002..543fdb0237 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -453,7 +453,7 @@ end --- Send request to the server to resolve document highlights for the current --- text document position. This request can be triggered by a key mapping or ---- by events such as `CursorHold`, eg: +--- by events such as `CursorHold`, e.g.: --- --- <pre> --- autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index a1d3b2aa94..a48302cc4b 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -439,14 +439,20 @@ for k, fn in pairs(M) do }) if err then - local client = vim.lsp.get_client_by_id(ctx.client_id) - local client_name = client and client.name or string.format("client_id=%d", ctx.client_id) -- LSP spec: -- interface ResponseError: -- code: integer; -- message: string; -- data?: string | number | boolean | array | object | null; - return err_message(client_name .. ': ' .. tostring(err.code) .. ': ' .. err.message) + + -- Per LSP, don't show ContentModified error to the user. + if err.code ~= protocol.ErrorCodes.ContentModified then + local client = vim.lsp.get_client_by_id(ctx.client_id) + local client_name = client and client.name or string.format("client_id=%d", ctx.client_id) + + err_message(client_name .. ': ' .. tostring(err.code) .. ': ' .. err.message) + end + return end return fn(err, result, ctx, config) diff --git a/runtime/lua/vim/lsp/sync.lua b/runtime/lua/vim/lsp/sync.lua index d01f45ad8f..0f4e5b572b 100644 --- a/runtime/lua/vim/lsp/sync.lua +++ b/runtime/lua/vim/lsp/sync.lua @@ -298,7 +298,7 @@ end ---@private -- rangelength depends on the offset encoding --- bytes for utf-8 (clangd with extenion) +-- bytes for utf-8 (clangd with extension) -- codepoints for utf-16 -- codeunits for utf-32 -- Line endings count here as 2 chars for \r\n (dos), 1 char for \n (unix), and 1 char for \r (mac) diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua index 594765761d..85fd5cd8e0 100644 --- a/runtime/lua/vim/treesitter/languagetree.lua +++ b/runtime/lua/vim/treesitter/languagetree.lua @@ -77,7 +77,7 @@ end --- Determines whether this tree is valid. --- If the tree is invalid, `parse()` must be called ---- to get the an updated tree. +--- to get the updated tree. function LanguageTree:is_valid() return self._valid end |