Compare commits
2
Commits
2c9e2e1e10
...
9511de0647
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9511de0647 | ||
|
|
0c6b316734 |
@@ -94,6 +94,7 @@ Useful Mason commands:
|
|||||||
|
|
||||||
Useful LSP commands:
|
Useful LSP commands:
|
||||||
|
|
||||||
|
- `lsp restart` restart LSP clients attached to the current buffer
|
||||||
- `K` show the type and documentation for the symbol under the cursor
|
- `K` show the type and documentation for the symbol under the cursor
|
||||||
- `gd` go to definition
|
- `gd` go to definition
|
||||||
- `gD` go to declaration
|
- `gD` go to declaration
|
||||||
|
|||||||
@@ -1,10 +1,28 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
-- This function returns project local dart, or fallsback to global
|
function M.root(path)
|
||||||
function M.executable(path)
|
local root = vim.fs.root(path, { "pubspec.yaml" })
|
||||||
local directory = vim.fn.isdirectory(path) == 1 and path or vim.fs.dirname(path)
|
if not root then return nil end
|
||||||
local root = vim.fs.root(directory, { "pubspec.yaml" })
|
|
||||||
|
|
||||||
|
local pubspec = table.concat(vim.fn.readfile(root .. "/pubspec.yaml"), "\n")
|
||||||
|
if pubspec:match("\nresolution:%s*workspace%s*[^\n]*") or pubspec:match("^resolution:%s*workspace%s*[^\n]*") then
|
||||||
|
local parent = vim.fs.dirname(root)
|
||||||
|
while parent do
|
||||||
|
local candidate = vim.fs.root(parent, { "pubspec.yaml" })
|
||||||
|
if not candidate then break end
|
||||||
|
local contents = table.concat(vim.fn.readfile(candidate .. "/pubspec.yaml"), "\n")
|
||||||
|
if contents:match("\nworkspace:%s*[^\n]*") or contents:match("^workspace:%s*[^\n]*") then
|
||||||
|
return candidate
|
||||||
|
end
|
||||||
|
local next_parent = vim.fs.dirname(candidate)
|
||||||
|
if next_parent == candidate then break end
|
||||||
|
parent = next_parent
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return root
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.executable(root)
|
||||||
if root then
|
if root then
|
||||||
local fvm_dart = root .. "/.fvm/flutter_sdk/bin/dart"
|
local fvm_dart = root .. "/.fvm/flutter_sdk/bin/dart"
|
||||||
if vim.fn.executable(fvm_dart) == 1 then
|
if vim.fn.executable(fvm_dart) == 1 then
|
||||||
|
|||||||
@@ -124,10 +124,10 @@ local function checker_for(path)
|
|||||||
end
|
end
|
||||||
local root = vim.fs.dirname(found)
|
local root = vim.fs.dirname(found)
|
||||||
if kind == "dart" then
|
if kind == "dart" then
|
||||||
local has_fvm = vim.fs.find({ ".fvmrc", ".fvm" }, { path = root, upward = true })[1]
|
local dart = require("romanzy.custom.dart")
|
||||||
local executable = has_fvm and "fvm" or "dart"
|
root = dart.root(path)
|
||||||
local command = has_fvm and { "fvm", "dart", "analyze" } or { "dart", "analyze" }
|
local executable = dart.executable(root)
|
||||||
return kind, root, executable, command
|
return kind, root, executable, { executable, "analyze" }
|
||||||
end
|
end
|
||||||
local config = table.concat(vim.fn.readfile(found), "\n")
|
local config = table.concat(vim.fn.readfile(found), "\n")
|
||||||
if config:find('"references"%s*:') then
|
if config:find('"references"%s*:') then
|
||||||
@@ -168,7 +168,7 @@ function M.run()
|
|||||||
vim.notify("Project diagnostics failed:\n" .. vim.trim(output), vim.log.levels.ERROR)
|
vim.notify("Project diagnostics failed:\n" .. vim.trim(output), vim.log.levels.ERROR)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
add_lsp_diagnostics(items, root)
|
if kind ~= "dart" then add_lsp_diagnostics(items, root) end
|
||||||
vim.fn.setqflist({}, "r", { title = "Project diagnostics: " .. root, items = items })
|
vim.fn.setqflist({}, "r", { title = "Project diagnostics: " .. root, items = items })
|
||||||
if #items == 0 then
|
if #items == 0 then
|
||||||
require("trouble").close({ mode = "qflist" })
|
require("trouble").close({ mode = "qflist" })
|
||||||
|
|||||||
@@ -90,6 +90,10 @@ local servers = {
|
|||||||
tinymist = {},
|
tinymist = {},
|
||||||
-- Dart
|
-- Dart
|
||||||
dartls = {
|
dartls = {
|
||||||
|
root_dir = function(bufnr, on_dir)
|
||||||
|
local root = dart.root(vim.api.nvim_buf_get_name(bufnr))
|
||||||
|
if root then on_dir(root) end
|
||||||
|
end,
|
||||||
cmd = function(dispatchers, config)
|
cmd = function(dispatchers, config)
|
||||||
return vim.lsp.rpc.start({
|
return vim.lsp.rpc.start({
|
||||||
dart.executable(config.root_dir),
|
dart.executable(config.root_dir),
|
||||||
|
|||||||
Reference in New Issue
Block a user