-
Notifications
You must be signed in to change notification settings - Fork 99
Add multiple language server association with syntax elements #496
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1900,6 +1900,44 @@ everything else: > | |
| }, | ||
| ]) | ||
| < | ||
| Language servers can also be configured to associate themselves with specific | ||
| syntax elements. If a syntax element is detected at the current location, the | ||
| corresponding language server will take precedence over the standard ordering. | ||
|
|
||
| To specify a language server for a particular syntax element, use the | ||
| `syntaxAssociatedLSP` property in the configuration object passed to | ||
| `LspAddServer`. The value of `syntaxAssociatedLSP` should be a string or list | ||
| of strings representing the desired syntax elements. | ||
| > | ||
| vim9script | ||
|
|
||
| # Add two LSP configurations for handling JavaScript, TypeScript, and | ||
| # GraphQL files. | ||
| g:LspAddServer([ | ||
| { | ||
| # Configuration for Typescript-language-server: | ||
| # Used for general purposes when working with '.js' | ||
| # and '.ts' files. | ||
| filetype: ['javascript', ''typescript'], | ||
| path: 'typescript-language-server', | ||
| args: ['--stdio'] | ||
| }, | ||
| { | ||
| # Configuration for GraphQL-language-server: | ||
| # Specifically bound to 'graphqlTemplateString' syntax | ||
| # element. Will handle requests regarding GraphQL | ||
| # template literals. | ||
| filetype: ['javascript', ''typescript', 'graphql'], | ||
| path: 'graphql-lsp', | ||
| args: ['server', '-m', 'stream'], | ||
| syntaxAssociatedLSP: ['graphqlTemplateString'], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how reliable of this? and need to dyn change/config the syntax value?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't foresee a situation where we need to dynamically change the syntax. Can you provide an example to help me understand what you mean?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i meant the syntax value was not reliable, or dynamic, perhaps if there was a way to auto detect the syntax value (which it belonging) would be great, otherwise e.g markdown file, there perhaps embedded some unconcern code block. |
||
| } | ||
| ]) | ||
|
|
||
| < | ||
| To discover the current syntax stack and determine the appropriate value for | ||
| `syntaxAssociatedLSP`, you can employ `LspUtilGetCurrentSynStack` command. | ||
|
|
||
| ============================================================================== | ||
| 17. Language Server Features *lsp-features* | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| vim9script | ||
|
|
||
| import '../autoload/lsp/buffer.vim' as buf | ||
| import '../autoload/lsp/util.vim' as util | ||
|
|
||
| source common.vim | ||
|
|
||
| g:markdown_fenced_languages = ['c'] | ||
|
|
||
| var lspServers = [ | ||
| { | ||
| name: 'marksman', | ||
| filetype: 'markdown', | ||
| path: (exepath('marksman') ?? expand('~') .. '/.local/bin/marksman'), | ||
| args: ['server'], | ||
| }, | ||
| { | ||
| name: 'clangd', | ||
| filetype: 'markdown', | ||
| path: (exepath('clangd-15') ?? exepath('clangd')), | ||
| args: ['--background-index', '--clang-tidy'], | ||
| syntaxAssociatedLSP: ['markdownHighlight_c', 'markdownHighlightc'], | ||
|
|
||
| }, | ||
| ] | ||
| call LspAddServer(lspServers) | ||
|
|
||
| def FillDummyFile() | ||
| :silent edit dummy.md | ||
| sleep 200m | ||
| var lines: list<string> =<< trim END | ||
| # Title | ||
|
|
||
| ```c | ||
| int f1() { | ||
| int x; | ||
| int y; | ||
| x = 1; | ||
| y = 2; | ||
| return x + y; | ||
| } | ||
| ``` | ||
| END | ||
| setline(1, lines) | ||
| enddef | ||
|
|
||
| def g:Test_ChoseDefaultLspIfNoSyntaxMatch() | ||
| FillDummyFile() | ||
| search('Title') | ||
| var selected_lsp = buf.BufLspServerGet(bufnr(), 'hover') | ||
| assert_true(selected_lsp->has_key('name')) | ||
| assert_equal(selected_lsp.name, 'marksman') | ||
| enddef | ||
|
|
||
| def g:Test_ChooseCorrectLspIfSyntaxMatch() | ||
| FillDummyFile() | ||
| search('int') | ||
| var selected_lsp = buf.BufLspServerGet(bufnr(), 'hover') | ||
| assert_true(selected_lsp->has_key('name')) | ||
| assert_equal(selected_lsp.name, 'clangd') | ||
| enddef | ||
|
|
||
| # Only here to because the test runner needs it | ||
| def g:StartLangServer(): bool | ||
| return true | ||
| enddef | ||
|
|
||
| # vim: shiftwidth=2 softtabstop=2 noexpandtab |
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.
seems unnecessary?
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 is a minor fix. Using the apt command in scripts is discouraged, and it is recommended to use apt-get instead. According to the apt manual:
That's why a warning message is issued when apt is employed in a script.
However, this fix can be safely ignored; nevertheless, there isn't a reason to ignore it.
Uh oh!
There was an error while loading. Please reload this page.
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.
it has no pipeline here, maybe it's ok.