Skip to content

Commit

Permalink
refactor!: deprecate util.root_pattern
Browse files Browse the repository at this point in the history
This will be breaking primarily for language servers that rely on
code dependencies that is archived but still needs to be read. More
context: #1687.

Work on #2079.
  • Loading branch information
dundargoc committed Jan 20, 2025
1 parent 9ee2e7d commit 6b02073
Show file tree
Hide file tree
Showing 346 changed files with 965 additions and 1,036 deletions.
2 changes: 1 addition & 1 deletion .github/ci/run_sanitizer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANC
exit 1
fi

SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir|util\.path\.join|util\.path\.iterate_parents|util\.path\.traverse_parents|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_ancestor|util\.find_git_ancestor)'
SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir|util\.path\.join|util\.path\.iterate_parents|util\.path\.traverse_parents|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_ancestor|util\.find_git_ancestor|util\.root_pattern)'

if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANCH}" -- '*.lua' | grep -Ev '\.lua$' | grep -E "^\+.*${SEARCH_PATTERN}" ; then
echo
Expand Down
18 changes: 8 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ Additionally, these options are often useful:
An example for adding a new config is shown below:

```lua
local util = require 'lspconfig.util'

local function organize_imports()
local params = {
command = 'pyright.organizeimports',
Expand All @@ -67,14 +65,14 @@ return {
default_config = {
cmd = { 'pyright-langserver', '--stdio' },
filetypes = { 'python' },
root_dir = util.root_pattern(
'pyproject.toml',
'setup.py',
'setup.cfg',
'requirements.txt',
'Pipfile',
'pyrightconfig.json',
),
root_dir = function(fname)
return vim.fs.dirname(
vim.fs.find(
{ 'pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', 'Pipfile', 'pyrightconfig.json' },
{ path = fname, upward = true }
)[1]
)
end,
single_file_support = true,
settings = {
python = {
Expand Down
18 changes: 11 additions & 7 deletions doc/lspconfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ ADDING NEW SERVERS *lspconfig-new*

The steps for adding and enabling a new server configuration are:

1. Define the configuration (see also |vim.fs.root()|): >lua
1. Define the configuration: >lua
local lspconfig = require 'lspconfig'
local configs = require 'lspconfig.configs'

Expand All @@ -256,7 +256,7 @@ The steps for adding and enabling a new server configuration are:
cmd = {'/home/neovim/lua-language-server/run.sh'},
filetypes = {'lua'},
root_dir = function(fname)
return lspconfig.util.find_git_ancestor(fname)
return vim.fs.root(fname, '.git')
end,
settings = {},
},
Expand Down Expand Up @@ -295,14 +295,18 @@ below returns a function that takes as its argument the current buffer path.
the patterns are specified. >
root_dir = util.root_pattern('pyproject.toml', 'requirements.txt')
- WARNING: `util.root_pattern` is deprecated and will be removed in the future.
Instead, use >lua
vim.fs.dirname(vim.fs.find({ 'pyproject.toml', 'requirements.txt' }, { path = fname, upward = true })[1])
<
- Locate the first parent dir containing a ".git" file or directory: >lua
vim.fs.dirname(vim.fs.find('.git', { path = root_dir, upward = true })[1])
<
If you have Nvim 0.10 or newer then >lua
vim.fs.root(root_dir, ".git")
<
can be used instead.
- Note: The old `util.find_git_ancestor` API is deprecated and will
- WARNING: The old `util.find_git_ancestor` API is deprecated and will
be removed.
<
- Locate the first parent dir containing a "node_modules" dir: >lua
Expand All @@ -312,7 +316,7 @@ below returns a function that takes as its argument the current buffer path.
vim.fs.root(root_dir, "node_modules")
<
can be used instead.
- Note: The old `util.find_node_modules_ancestor` API is deprecated and will
- WARNING: The old `util.find_node_modules_ancestor` API is deprecated and will
be removed.

- Locate the first parent dir containing a "package.json" dir: >lua
Expand All @@ -322,7 +326,7 @@ below returns a function that takes as its argument the current buffer path.
vim.fs.root(root_dir, "package.json")
<
can be used instead.
- Note: The old `util.find_package_json_ancestor` API is deprecated and will
- WARNING: The old `util.find_package_json_ancestor` API is deprecated and will
be removed.
<
Note: On Windows, `lspconfig` always assumes forward slash normalized paths with
Expand Down Expand Up @@ -354,8 +358,8 @@ for some project structures. Example (for Kotlin): >lua
'build.gradle.kts', -- Gradle
}
root_dir = function(fname)
local primary = util.root_pattern(unpack(root_files))(fname)
local fallback = util.root_pattern(unpack(fallback_root_files))(fname)
local primary = vim.fs.root(fname, root_files)
local fallback = vim.fs.root(fname, fallback_root_files)
return primary or fallback
end
<
Expand Down
6 changes: 3 additions & 3 deletions lua/lspconfig/configs/ada_ls.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
local util = require 'lspconfig.util'

return {
default_config = {
cmd = { 'ada_language_server' },
filetypes = { 'ada' },
root_dir = util.root_pattern('Makefile', '.git', '*.gpr', '*.adc'),
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find({ 'Makefile', '.git', '*.gpr', '*.adc' }, { path = fname, upward = true })[1])
end,
},
docs = {
description = [[
Expand Down
6 changes: 3 additions & 3 deletions lua/lspconfig/configs/agda_ls.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
local util = require 'lspconfig.util'

return {
default_config = {
cmd = { 'als' },
filetypes = { 'agda' },
root_dir = util.root_pattern('.git', '*.agda-lib'),
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find({ '.git', '*.agda-lib' }, { path = fname, upward = true })[1])
end,
single_file_support = true,
},
docs = {
Expand Down
4 changes: 1 addition & 3 deletions lua/lspconfig/configs/aiken.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
local util = require 'lspconfig.util'

return {
default_config = {
cmd = { 'aiken', 'lsp' },
filetypes = { 'aiken' },
root_dir = function(fname)
return util.root_pattern('aiken.toml', '.git')(fname)
return vim.fs.dirname(vim.fs.find({ 'aiken.toml', '.git' }, { path = fname, upward = true })[1])
end,
},
docs = {
Expand Down
2 changes: 1 addition & 1 deletion lua/lspconfig/configs/alloy_ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ return {
cmd = { 'alloy', 'lsp' },
filetypes = { 'alloy' },
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1])
return vim.fs.dirname(vim.fs.find({ '.git' }, { path = fname, upward = true })[1])
end,
single_file_support = true,
},
Expand Down
5 changes: 1 addition & 4 deletions lua/lspconfig/configs/anakin_language_server.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local util = require 'lspconfig.util'

return {
default_config = {
cmd = { 'anakinls' },
Expand All @@ -12,8 +10,7 @@ return {
'requirements.txt',
'Pipfile',
}
return util.root_pattern(unpack(root_files))(fname)
or vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1])
return vim.fs.dirname(vim.fs.find({ unpack(root_files), '.git' }, { path = fname, upward = true })[1])
end,
single_file_support = true,
settings = {
Expand Down
6 changes: 3 additions & 3 deletions lua/lspconfig/configs/angularls.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local util = require 'lspconfig.util'

-- Angular requires a node_modules directory to probe for @angular/language-service and typescript
-- in order to use your projects configured versions.
-- This defaults to the vim cwd, but will get overwritten by the resolved root of the file.
Expand All @@ -25,7 +23,9 @@ return {
-- Check for angular.json since that is the root of the project.
-- Don't check for tsconfig.json or package.json since there are multiple of these
-- in an angular monorepo setup.
root_dir = util.root_pattern 'angular.json',
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find({ 'angular.json' }, { path = fname, upward = true })[1])
end,
},
on_new_config = function(new_config, new_root_dir)
local new_probe_dir = get_probe_dir(new_root_dir)
Expand Down
6 changes: 3 additions & 3 deletions lua/lspconfig/configs/ansiblels.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local util = require 'lspconfig.util'

return {
default_config = {
cmd = { 'ansible-language-server', '--stdio' },
Expand All @@ -24,7 +22,9 @@ return {
},
},
filetypes = { 'yaml.ansible' },
root_dir = util.root_pattern('ansible.cfg', '.ansible-lint'),
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find({ 'ansible.cfg', '.ansible-lint' }, { path = fname, upward = true })[1])
end,
single_file_support = true,
},
docs = {
Expand Down
6 changes: 3 additions & 3 deletions lua/lspconfig/configs/antlersls.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
local util = require 'lspconfig.util'

return {
default_config = {
cmd = { 'antlersls', '--stdio' },
filetypes = { 'html', 'antlers' },
root_dir = util.root_pattern 'composer.json',
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find({ 'composer.json' }, { path = fname, upward = true })[1])
end,
},
docs = {
description = [[
Expand Down
6 changes: 3 additions & 3 deletions lua/lspconfig/configs/apex_ls.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local util = require 'lspconfig.util'

return {
default_config = {
filetypes = { 'apexcode' },
root_dir = util.root_pattern 'sfdx-project.json',
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find({ 'sfdx-project.json' }, { path = fname, upward = true })[1])
end,
on_new_config = function(config)
if not config.cmd and config.apex_jar_path then
config.cmd = {
Expand Down
6 changes: 3 additions & 3 deletions lua/lspconfig/configs/arduino_language_server.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local util = require 'lspconfig.util'

return {
default_config = {
filetypes = { 'arduino' },
root_dir = util.root_pattern '*.ino',
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find({ '*.ino' }, { path = fname, upward = true })[1])
end,
cmd = {
'arduino-language-server',
},
Expand Down
6 changes: 3 additions & 3 deletions lua/lspconfig/configs/ast_grep.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local util = require 'lspconfig.util'

return {
default_config = {
cmd = { 'ast-grep', 'lsp' },
Expand All @@ -18,7 +16,9 @@ return {
'dart',
'lua',
},
root_dir = util.root_pattern('sgconfig.yaml', 'sgconfig.yml'),
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find({ 'sgconfig.yaml', 'sgconfig.yml' }, { path = fname, upward = true })[1])
end,
},
docs = {
description = [[
Expand Down
8 changes: 5 additions & 3 deletions lua/lspconfig/configs/astro.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local util = require 'lspconfig.util'

local function get_typescript_server_path(root_dir)
local project_root = vim.fs.find('node_modules', { path = root_dir, upward = true })[1]
return project_root and (project_root .. '/typescript/lib') or ''
Expand All @@ -9,7 +7,11 @@ return {
default_config = {
cmd = { 'astro-ls', '--stdio' },
filetypes = { 'astro' },
root_dir = util.root_pattern('package.json', 'tsconfig.json', 'jsconfig.json', '.git'),
root_dir = function(fname)
return vim.fs.dirname(
vim.fs.find({ 'package.json', 'tsconfig.json', 'jsconfig.json', '.git' }, { path = fname, upward = true })[1]
)
end,
init_options = {
typescript = {},
},
Expand Down
4 changes: 1 addition & 3 deletions lua/lspconfig/configs/atlas.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
local util = require 'lspconfig.util'

return {
default_config = {
cmd = { 'atlas', 'tool', 'lsp', '--stdio' },
filetypes = {
'atlas-*',
},
root_dir = function(fname)
return util.root_pattern('atlas.hcl')(fname)
return vim.fs.dirname(vim.fs.find({ 'atlas.hcl' }, { path = fname, upward = true })[1])
end,
single_file_support = true,
},
Expand Down
4 changes: 1 addition & 3 deletions lua/lspconfig/configs/autotools_ls.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
local util = require 'lspconfig.util'

local root_files = { 'configure.ac', 'Makefile', 'Makefile.am', '*.mk' }

return {
default_config = {
cmd = { 'autotools-language-server' },
filetypes = { 'config', 'automake', 'make' },
root_dir = function(fname)
return util.root_pattern(unpack(root_files))(fname)
return vim.fs.dirname(vim.fs.find({ unpack(root_files) }, { path = fname, upward = true })[1])
end,
single_file_support = true,
},
Expand Down
6 changes: 3 additions & 3 deletions lua/lspconfig/configs/azure_pipelines_ls.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
local util = require 'lspconfig.util'

return {
default_config = {
cmd = { 'azure-pipelines-language-server', '--stdio' },
filetypes = { 'yaml' },
root_dir = util.root_pattern 'azure-pipelines.yml',
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find({ 'azure-pipelines.yml' }, { path = fname, upward = true })[1])
end,
single_file_support = true,
settings = {},
},
Expand Down
6 changes: 3 additions & 3 deletions lua/lspconfig/configs/bacon_ls.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
local util = require 'lspconfig.util'

return {
default_config = {
cmd = { 'bacon-ls' },
filetypes = { 'rust' },
root_dir = util.root_pattern('.bacon-locations', 'Cargo.toml'),
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find({ '.bacon-locations', 'Cargo.toml' }, { path = fname, upward = true })[1])
end,
single_file_support = true,
settings = {},
},
Expand Down
6 changes: 3 additions & 3 deletions lua/lspconfig/configs/ballerina.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
local util = require 'lspconfig.util'

return {
default_config = {
cmd = { 'bal', 'start-language-server' },
filetypes = { 'ballerina' },
root_dir = util.root_pattern 'Ballerina.toml',
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find({ 'Ballerina.toml' }, { path = fname, upward = true })[1])
end,
},
docs = {
description = [[
Expand Down
12 changes: 6 additions & 6 deletions lua/lspconfig/configs/basedpyright.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local util = require 'lspconfig.util'
local util = require('lspconfig.util')

local root_files = {
'pyproject.toml',
Expand All @@ -16,20 +16,20 @@ local function organize_imports()
arguments = { vim.uri_from_bufnr(0) },
}

local clients = util.get_lsp_clients {
local clients = util.get_lsp_clients({
bufnr = vim.api.nvim_get_current_buf(),
name = 'basedpyright',
}
})
for _, client in ipairs(clients) do
client.request('workspace/executeCommand', params, nil, 0)
end
end

local function set_python_path(path)
local clients = util.get_lsp_clients {
local clients = util.get_lsp_clients({
bufnr = vim.api.nvim_get_current_buf(),
name = 'basedpyright',
}
})
for _, client in ipairs(clients) do
if client.settings then
client.settings.python = vim.tbl_deep_extend('force', client.settings.python or {}, { pythonPath = path })
Expand All @@ -45,7 +45,7 @@ return {
cmd = { 'basedpyright-langserver', '--stdio' },
filetypes = { 'python' },
root_dir = function(fname)
return util.root_pattern(unpack(root_files))(fname)
return vim.fs.dirname(vim.fs.find({ unpack(root_files) }, { path = fname, upward = true })[1])
end,
single_file_support = true,
settings = {
Expand Down
Loading

0 comments on commit 6b02073

Please sign in to comment.