LanguageClient-neovim icon indicating copy to clipboard operation
LanguageClient-neovim copied to clipboard

Feature request: Support multiple language servers for one single buffer?

Open TysonAndre opened this issue 6 years ago • 10 comments

Summary

Looking at the documentation and most recent source code, this isn't possible. serverCommands is HashMap<String, Vec<String>> (i.e. it maps the programming language (String) to a single command which is represented as a program and list of arguments)

It would be useful if multiple language servers could be supported, handling commands and capabilities independently of each other (E.g. aggregating diagnostics)

Implementing this may or may not affect #464 (e.g. if different project roots are detected in two open vim panes, this plugin might automatically run two language servers in parallel)

Example use cases:

  • Starting independent language servers to analyze separate projects (e.g. both open at once)
  • Starting two unrelated language servers (for the same programming language) by different authors (e.g. one for autocompletion, another for diagnostics)

TysonAndre avatar Jun 16 '18 17:06 TysonAndre

That's possible useful cases.

There're also interesting open questions if this is made possible,

  1. How many languages have more than one mature language servers?
  2. If there is more than one language server running for one buffer, which server should be contacted for request/response style operations, e.g., hover, query symbols?

autozimu avatar Jun 16 '18 19:06 autozimu

  1. PHP is one. I'm not sure about the rest.

    I was working on https://github.com/tysonandre/languageserver-phan-neovim because of its diagnostic capability (it's limited to analyzing a single workspace) In comparison, https://github.com/felixfbecker/php-language-server#features has limited diagnostics (just limited to parse errors, I think), but supports autocompletion, etc.

  2. If they're running in separate workspaces (folders), you'd choose the one with the only matching folder.

    One tie breaker would be to choose the first registered server, but now that I think about it, servers register themselves (and are autoloaded for a given file type), so the order would be useless.

    Sorting by the List<String> command used (as a default) would at least make it deterministic.

    You could allow plugin authors to add an optional short identifier to their own server (and make that plus the workspace uniquely identify a running language server?)

" In the plugin code:
" Maybe add a 3rd option if the client manually chooses a workspace?
call LanguageClient_registerServerCommands({'php': (s:cmd)}, 'php-language-server')

" In the user's vim/neovim config
set g:LanguageClient_setServerPrecedence('php', ['php-language-server', 'other-language-server'])

TysonAndre avatar Jun 16 '18 20:06 TysonAndre

Also, is there a way to merge the QuickFix errors from this plugin with QuickFix errors from other sources (e.g. running make on save to run)

EDIT: accidentally closed this

TysonAndre avatar Jun 16 '18 23:06 TysonAndre

@autozimu I'd love to add another use case for this feature! More and more, JavaScript development has an intermingling of languages. Examples of such are css-in-js and graphql where collocating different languages together has become the dominant pattern.

I maintain the apollo-language-server which is a language server for GraphQL. Most of our users collocate their GraphQL operations and schema's within their JavaScript files. Ideally when opening a js / ts file, we could start both servers up

jbaxleyiii avatar Nov 26 '18 14:11 jbaxleyiii

I got into this issue exactly because of your comment @jbaxleyiii. I would love to use GraphQL completion/typechecking on my TypeScript/JavaScript files. The same happens for other use cases like SQL, JS inside HTML, CSS in JS, etc.

derekstavis avatar Dec 17 '18 21:12 derekstavis

Another use case for this feature is spellchecking with a 2ndary langserver:

I built retext-language-server to spellcheck spoken languages (in .txt files).

If multiple servers were supported, I could have my server spellcheck comments in any code file.

aecepoglu avatar Jan 04 '19 09:01 aecepoglu

I want to add one more use-case. I'm working on jsref — refactoring language server for JS (Flow, TS). I would like to use it as an addition to regular Flow lsp.

slonoed avatar Aug 23 '19 13:08 slonoed

Another use case is being able to use https://github.com/iamcco/diagnostic-languageserver to run linter and formatters, thus freeing us from having to use a different plugin for that.

gbrlsnchs avatar Sep 06 '19 03:09 gbrlsnchs

I think it would be useful to use javascript-typescript-langserver in conjunction with ESLint server.

See also: https://github.com/autozimu/LanguageClient-neovim/issues/391 https://github.com/sourcegraph/javascript-typescript-langserver/issues/324

concatime avatar Jan 05 '20 00:01 concatime

yeap I want to use : typescript-language-server + tailwindcss-language-server + eslint-language-server

zodman avatar Nov 11 '22 16:11 zodman