diff options
| author | DianQK <dianqk@dianqk.net> | 2025-03-17 17:25:57 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-17 17:25:57 +0800 |
| commit | ef46ce7b7378b366c345f0f3823cfee9921b69c6 (patch) | |
| tree | f7d0b7139c90316536f737d5a9b369bcc6cc3fe1 | |
| parent | b30d1970ab99dd31e3ba30bd6dcf815b3fc75aee (diff) | |
| parent | 4aee99575035d1dbddd534df12399f5ba911627e (diff) | |
| download | rust-ef46ce7b7378b366c345f0f3823cfee9921b69c6.tar.gz rust-ef46ce7b7378b366c345f0f3823cfee9921b69c6.zip | |
Merge pull request #2290 from jyn514/nvim-config
expand ${workspaceFolder} in sample vim config| -rw-r--r-- | src/doc/rustc-dev-guide/src/building/suggested.md | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/doc/rustc-dev-guide/src/building/suggested.md b/src/doc/rustc-dev-guide/src/building/suggested.md index 2498838144e..772b0a778f8 100644 --- a/src/doc/rustc-dev-guide/src/building/suggested.md +++ b/src/doc/rustc-dev-guide/src/building/suggested.md @@ -123,6 +123,30 @@ Another way is without a plugin, and creating your own logic in your configuration. The following code will work for any checkout of rust-lang/rust (newer than Febuary 2025): ```lua +local function expand_config_variables(option) + local var_placeholders = { + ['${workspaceFolder}'] = function(_) + return vim.lsp.buf.list_workspace_folders()[1] + end, + } + + if type(option) == "table" then + local mt = getmetatable(option) + local result = {} + for k, v in pairs(option) do + result[expand_config_variables(k)] = expand_config_variables(v) + end + return setmetatable(result, mt) + end + if type(option) ~= "string" then + return option + end + local ret = option + for key, fn in pairs(var_placeholders) do + ret = ret:gsub(key, fn) + end + return ret +end lspconfig.rust_analyzer.setup { root_dir = function() local default = lspconfig.rust_analyzer.config_def.default_config.root_dir() @@ -142,7 +166,7 @@ lspconfig.rust_analyzer.setup { -- load rust-lang/rust settings local file = io.open(config) local json = vim.json.decode(file:read("*a")) - client.config.settings["rust-analyzer"] = json.lsp["rust-analyzer"].initialization_options + client.config.settings["rust-analyzer"] = expand_config_variables(json.lsp["rust-analyzer"].initialization_options) client.notify("workspace/didChangeConfiguration", { settings = client.config.settings }) end return true |
