refactor: change the default path for local dev env
This commit is contained in:
+38
-15
@@ -13,16 +13,17 @@ function M.setup(opts)
|
|||||||
setup_package_path()
|
setup_package_path()
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
local server_path = opts.server_path or vim.fn.expand("~/dev/tia-lsp/src/main.lua")
|
local server_path = opts.server_path or vim.fn.expand("~/Documents/lua/tia-lsp/src/main.lua")
|
||||||
|
|
||||||
local root_patterns = { ".git", "data_types", "plc.data.json" }
|
local root_patterns = { ".git", "data_types", "plc.data.json" }
|
||||||
|
|
||||||
local function start_lsp(bufnr)
|
local function start_lsp(bufnr)
|
||||||
local fname = vim.api.nvim_buf_get_name(bufnr)
|
local fname = vim.api.nvim_buf_get_name(bufnr)
|
||||||
if fname == "" then return end
|
if fname == "" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local root_dir = vim.fs.root(fname, root_patterns)
|
local root_dir = vim.fs.root(fname, root_patterns) or vim.fn.fnamemodify(fname, ":p:h")
|
||||||
or vim.fn.fnamemodify(fname, ":p:h")
|
|
||||||
|
|
||||||
-- Prefer the mason-installed executable (vim.fn.exepath resolves on each
|
-- Prefer the mason-installed executable (vim.fn.exepath resolves on each
|
||||||
-- buffer enter, so a :MasonInstall mid-session is picked up without restart).
|
-- buffer enter, so a :MasonInstall mid-session is picked up without restart).
|
||||||
@@ -113,10 +114,16 @@ end
|
|||||||
local parser_notified = false
|
local parser_notified = false
|
||||||
|
|
||||||
function M.notify_parser_install_if_needed(bufnr)
|
function M.notify_parser_install_if_needed(bufnr)
|
||||||
if parser_notified then return end
|
if parser_notified then
|
||||||
if vim.bo[bufnr].filetype ~= "scl" then return end
|
return
|
||||||
|
end
|
||||||
|
if vim.bo[bufnr].filetype ~= "scl" then
|
||||||
|
return
|
||||||
|
end
|
||||||
local ok = pcall(vim.treesitter.get_parser, bufnr, "scl")
|
local ok = pcall(vim.treesitter.get_parser, bufnr, "scl")
|
||||||
if ok then return end
|
if ok then
|
||||||
|
return
|
||||||
|
end
|
||||||
parser_notified = true
|
parser_notified = true
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
local msg = "SCL: Tree-sitter parser not found. "
|
local msg = "SCL: Tree-sitter parser not found. "
|
||||||
@@ -157,8 +164,7 @@ function M.setup_syntax(opts)
|
|||||||
if type(parser_config) == "table" then
|
if type(parser_config) == "table" then
|
||||||
parser_config.scl = {
|
parser_config.scl = {
|
||||||
install_info = {
|
install_info = {
|
||||||
url = opts.ts_parser_url
|
url = opts.ts_parser_url or "https://gitea.l-tech.rs/lazar/tia-lsp.git",
|
||||||
or "https://gitea.l-tech.rs/lazar/tia-lsp.git",
|
|
||||||
files = { "src/parser.c" },
|
files = { "src/parser.c" },
|
||||||
generate_requires_npm = false,
|
generate_requires_npm = false,
|
||||||
requires_generate_from_grammar = false,
|
requires_generate_from_grammar = false,
|
||||||
@@ -308,15 +314,32 @@ function M.rescan_workspace_types()
|
|||||||
local udt_result = ws.scan_project_udts()
|
local udt_result = ws.scan_project_udts()
|
||||||
local fb_result = ws.scan_project_fbs()
|
local fb_result = ws.scan_project_fbs()
|
||||||
|
|
||||||
vim.notify("Scanned UDTs: " .. udt_result.parsed_count .. "/" .. udt_result.total_files ..
|
vim.notify(
|
||||||
", FBs: " .. fb_result.parsed_count .. "/" .. fb_result.total_files, vim.log.levels.INFO)
|
"Scanned UDTs: "
|
||||||
|
.. udt_result.parsed_count
|
||||||
|
.. "/"
|
||||||
|
.. udt_result.total_files
|
||||||
|
.. ", FBs: "
|
||||||
|
.. fb_result.parsed_count
|
||||||
|
.. "/"
|
||||||
|
.. fb_result.total_files,
|
||||||
|
vim.log.levels.INFO
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.create_commands()
|
function M.create_commands()
|
||||||
vim.api.nvim_create_user_command("SCLShowVariables", function() M.show_variables() end, {})
|
vim.api.nvim_create_user_command("SCLShowVariables", function()
|
||||||
vim.api.nvim_create_user_command("SCLShowWorkspaceTypes", function() M.show_workspace_types() end, {})
|
M.show_variables()
|
||||||
vim.api.nvim_create_user_command("SCLRescanWorkspaceTypes", function() M.rescan_workspace_types() end, {})
|
end, {})
|
||||||
vim.api.nvim_create_user_command("SCLPrefixWord", function() M.prefix_current_word() end, {})
|
vim.api.nvim_create_user_command("SCLShowWorkspaceTypes", function()
|
||||||
|
M.show_workspace_types()
|
||||||
|
end, {})
|
||||||
|
vim.api.nvim_create_user_command("SCLRescanWorkspaceTypes", function()
|
||||||
|
M.rescan_workspace_types()
|
||||||
|
end, {})
|
||||||
|
vim.api.nvim_create_user_command("SCLPrefixWord", function()
|
||||||
|
M.prefix_current_word()
|
||||||
|
end, {})
|
||||||
|
|
||||||
-- Attribute toggle commands
|
-- Attribute toggle commands
|
||||||
vim.api.nvim_create_user_command("SCLToggleAttrBlock", function()
|
vim.api.nvim_create_user_command("SCLToggleAttrBlock", function()
|
||||||
|
|||||||
Reference in New Issue
Block a user