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
Get initialization options from document uri #692
Conversation
3170241
to
e034aed
Compare
I don't really understand this pattern. Can you please elaborate at why this would be necessary? Initialization options are usually more stateless server options that the client want to override. They're not really suitable for per-document/per-URI content. |
The use case comes from a clangd specialty. clangd made some ls protocol extensions. One of them is the ability to provide Thats the reason why we need the initialUri during start() of the LS. |
e034aed
to
9d883a6
Compare
For some LS the determination of LS initialization options depends on the first uri to be opened and not on the first project or path. Therefor the getInitializationOptionsFromUri(URI) method has been added to the StreamConnectionProvider interface. It will be called when getInitializationOptions(URI) returns null. fixes eclipse#683 eclipse#684
9d883a6
to
5ca7c70
Compare
Thanks for sharing the use-case. The use-case is valid so I think it's fine to make LSP4E capable of supporting it. |
Regarding this issue it's not important whether the LS is project specific or not. It no change of configuration. Its all about initial initialization settings. All we want to know is the first file/document which triggers the LS to run. We'll determine the compiler settings for this file and tell clangd where to find the system include headers for the case there is no compile_commands.json provided/found. This is independent of the amount of LS. |
Isn't it the first doc for which
Can't clangd detect that? (it's a naive question, but I need to ask it as we should avoid seeing the language clients host workarounds for features that would be much more valuable placed in the server)
Do all files/projects use the same system headers? If yes, then you most likely don't need to pass the initial doc to resolve such a static value; if not then it means for distinct files, you should use distinct values; so either you have multiple LS receiving each a distinct value, or you have a single LS which dynamically receives the possible valueS (according to the open file). I don't think initialization option fits any of this case, IMO clangd could do better here supporting |
@ghentschke even i fyou have not the intention to integrate clangd in another LSP client, you should think about that to follow LSP protocol. IMHO your PR is very specific for clangd. You push the the URI of the first opened file, but perhaps an another language server would like to know what are all opened files (ex : you open several files and you close your workspace and you reopen your workspace and the LS need to know what are all opened files). If I understand correctly your requirement, you need to push the first opened file in initialized parameters. In this case, when I will build the initialize parameters, I will use the Eclipse IDE API to know the activated editor and get the opened file. But perhaps it is not possible, I have not tested. |
@ghentschke my concerns are the ones expressed by @angelozerr that this changes seem very specific to the current state of clangd. The discussion is intended to find whether we can make clangd integration work without this change, and discuss other appraches for the integration; or whether the problem you're facing for clangd is a more generic one and discuss whether the solution is the most generic. A language-server can be initialized out of a document context, just started to be ready with doc bound to it (yet); expecting a document here seems too early. LSP has the concept of rootUri that is used on initialization. Couldn't this be used instead of document URI to create initialization options? |
@angelozerr and @mickaelistria : Thank you for the feedback! I'am fully aware that this proposal is very specific to clangd. I can understand the concerns. At the moment I've no better idea how to fetch the initialFile from LSP4E.
When I remember it correctly, this will not work if the focus is not on the editor part, but I'll give it another try. |
In vscode it seems that you store Perhaps you could add a tracker of editor and stores the |
The goal here is to be better than vscode ;-) CDT shall handle this flags dynamically.
I do something similar in my current (hacky) solution: I check whether the first URI, which I get from the LSP4E |
@ghentschke I more and more believe that this I understand that it's the current state of clangd, but then I wonder, wouldn't it be more profitable, for all integrations of clangd, to contribute there the ability to define such a path with standard LSP approaches such as |
The initial target branch |
For some LS the determination of LS initialization options depends on the first uri to be opened and not on the first project or path. Therefor the
getInitializationOptionsFromUri(URI) method has been added to the StreamConnectionProvider interface. It will be called when getInitializationOptions(URI) returns null.
fixes #683 #684