-
-
Notifications
You must be signed in to change notification settings - Fork 201
add vue support for ts_ls #1310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
miaapancake
wants to merge
7
commits into
NotAShelf:main
Choose a base branch
from
miaapancake:vue_language_server
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
52d9434
ts: add vue support for ts_ls
miaapancake a792378
ts_ls: add comments for vue integration and adhere to code style
miaapancake d9b09df
vue: create independent language module for vue
miaapancake 686e586
vue: fix formatting for vue and ts language module
miaapancake 6e50b1f
chore: add release note for vue language support
miaapancake 7a0d1df
Merge branch 'main' into vue_language_server
miaapancake 533135a
fix release notes
miaapancake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| { | ||
| config, | ||
| pkgs, | ||
| lib, | ||
| ... | ||
| }: let | ||
| inherit (builtins) attrNames; | ||
| inherit (lib.options) mkEnableOption mkOption; | ||
| inherit (lib.modules) mkIf mkMerge; | ||
| inherit (lib.meta) getExe; | ||
| inherit (lib.types) enum listOf; | ||
| inherit (lib.generators) mkLuaInline; | ||
| inherit (lib.nvim.attrsets) mapListToAttrs; | ||
| inherit (lib.nvim.types) mkGrammarOption diagnostics; | ||
|
|
||
| cfg = config.vim.languages.vue; | ||
|
|
||
| defaultServers = ["vue_ls"]; | ||
| servers = { | ||
| vue_ls = { | ||
| cmd = [(getExe pkgs.vue-language-server) "--stdio"]; | ||
| filetypes = ["vue"]; | ||
| root_markers = [ | ||
| "tsconfig.json" | ||
| "jsconfig.json" | ||
| "package.json" | ||
| ".git" | ||
| ]; | ||
| on_init = mkLuaInline '' | ||
| -- forward typescript blocks to ts_ls or vtsls depending on which is available first | ||
| function(client) | ||
| client.handlers['tsserver/request'] = function(_, result, context) | ||
| local ts_clients = vim.lsp.get_clients({ bufnr = context.bufnr, name = 'ts_ls' }) | ||
| local clients = {} | ||
|
|
||
| vim.list_extend(clients, ts_clients) | ||
|
|
||
| if #clients == 0 then | ||
| vim.notify('Could not find `vtsls` or `ts_ls` lsp client, `vue_ls` would not work without it.', vim.log.levels.ERROR) | ||
| return | ||
| end | ||
| local ts_client = clients[1] | ||
|
|
||
| local param = unpack(result) | ||
| local id, command, payload = unpack(param) | ||
| ts_client:exec_cmd({ | ||
| title = 'vue_request_forward', -- You can give title anything as it's used to represent a command in the UI, `:h Client:exec_cmd` | ||
| command = 'typescript.tsserverRequest', | ||
| arguments = { | ||
| command, | ||
| payload, | ||
| }, | ||
| }, { bufnr = context.bufnr }, function(_, r) | ||
| local response = r and r.body | ||
| -- TODO: handle error or response nil here, e.g. logging | ||
| -- NOTE: Do NOT return if there's an error or no response, just return nil back to the vue_ls to prevent memory leak | ||
| local response_data = { { id, response } } | ||
|
|
||
| ---@diagnostic disable-next-line: param-type-mismatch | ||
| client:notify('tsserver/response', response_data) | ||
| end) | ||
| end | ||
| end | ||
| ''; | ||
| }; | ||
| }; | ||
| defaultFormat = ["prettier"]; | ||
| formats = { | ||
| prettier = { | ||
| command = getExe pkgs.nodePackages.prettier; | ||
| options.ft_parsers.vue = "vue"; | ||
| }; | ||
| }; | ||
| defaultDiagnosticsProvider = ["eslint_d"]; | ||
| diagnosticsProviders = { | ||
| eslint_d = let | ||
| pkg = pkgs.eslint_d; | ||
| in { | ||
| package = pkg; | ||
| config = { | ||
| cmd = getExe pkg; | ||
| required_files = [ | ||
| "eslint.config.js" | ||
| "eslint.config.mjs" | ||
| ".eslintrc" | ||
| ".eslintrc.json" | ||
| ".eslintrc.js" | ||
| ".eslintrc.yml" | ||
| ]; | ||
| }; | ||
| }; | ||
| }; | ||
| formatType = | ||
| enum (attrNames formats); | ||
| in { | ||
| _file = ./vue.nix; | ||
| options.vim.languages.vue = { | ||
| enable = mkEnableOption "Vue language support"; | ||
|
|
||
| treesitter = { | ||
| enable = mkEnableOption "Vue treesitter" // {default = config.vim.languages.enableTreesitter;}; | ||
|
|
||
| vuePackage = mkGrammarOption pkgs "vue"; | ||
| }; | ||
|
|
||
| lsp = { | ||
| enable = mkEnableOption "Vue LSP support" // {default = config.vim.lsp.enable;}; | ||
|
|
||
| servers = mkOption { | ||
| type = listOf (enum (attrNames servers)); | ||
| default = defaultServers; | ||
| description = "Vue LSP server to use"; | ||
| }; | ||
| }; | ||
|
|
||
| format = { | ||
| enable = mkEnableOption "Vue formatting" // {default = config.vim.languages.enableFormat;}; | ||
|
|
||
| type = mkOption { | ||
| type = formatType; | ||
| default = defaultFormat; | ||
| description = "Vue formatter to use"; | ||
| }; | ||
| }; | ||
|
|
||
| extraDiagnostics = { | ||
| enable = mkEnableOption "extra Vue diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;}; | ||
|
|
||
| types = diagnostics { | ||
| langDesc = "Vue"; | ||
| inherit diagnosticsProviders; | ||
| inherit defaultDiagnosticsProvider; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| config = mkIf cfg.enable (mkMerge [ | ||
| (mkIf cfg.treesitter.enable { | ||
| vim.treesitter.enable = true; | ||
| vim.treesitter.grammars = [cfg.treesitter.vuePackage]; | ||
| }) | ||
|
|
||
| (mkIf cfg.lsp.enable { | ||
| vim.lsp.servers = | ||
| mapListToAttrs (n: { | ||
| name = n; | ||
| value = servers.${n}; | ||
| }) | ||
| cfg.lsp.servers; | ||
| }) | ||
|
|
||
| (mkIf cfg.format.enable { | ||
| vim.formatter.conform-nvim = { | ||
| enable = true; | ||
| setupOpts = { | ||
| formatters_by_ft.vue = cfg.format.type; | ||
| formatters = | ||
| mapListToAttrs (name: { | ||
| inherit name; | ||
| value = formats.${name}; | ||
| }) | ||
| cfg.format.type; | ||
| }; | ||
| }; | ||
| }) | ||
|
|
||
| (mkIf cfg.extraDiagnostics.enable { | ||
| vim.diagnostics.nvim-lint = { | ||
| enable = true; | ||
| linters_by_ft.vue = cfg.extraDiagnostics.types; | ||
| linters = | ||
| mkMerge (map (name: {${name} = diagnosticsProviders.${name}.config;}) | ||
| cfg.extraDiagnostics.types); | ||
| }; | ||
| }) | ||
| ]); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type is wrong and errors when evaluating, since you expect a single value, but you're setting a list above.
see here:
https://github.com/miaapancake/nvf/blob/533135a95d147110e581da686975cd0312e4aac6/modules/plugins/languages/vue.nix#L67-L73
Looking at what you've been setting in
defaultFormatabove, you probably want this: