Fix #86: Allow configuration of workspace#96
Conversation
Migrate Lsp Settings to Project Settings, since the workspace configuration is project specific and the editor text field requires a project
9f0b622 to
15d16b3
Compare
JojOatXGME
left a comment
There was a problem hiding this comment.
Hi. Firstly, thanks for your PR. 👍
I added some comments. Note that only the comments prefixed with issue: or question: strictly require your input. I am mostly concerned about moving NixLspSettings to the project level (see comment).
I am aware, that in #68 you discussed switching to
lsp4ij.
I am happy to see improvements in the existing integration. Switching to lsp4ij has no priority for me after JetBrains made their API available free of charge. While I would provide support when someone wants to work on switching, I don't plan to work on it personally.
| @JvmStatic | ||
| fun getInstance(): NixLspSettings { | ||
| return ApplicationManager.getApplication().getService(NixLspSettings::class.java) | ||
| fun getInstance(project: Project): NixLspSettings { |
There was a problem hiding this comment.
issue: I am a bit worried about moving the settings to the project level. This change would mean that users have to enable the language server for every project separately. I guess it also means the language server will be disabled for all users after the update. Is there any rational you want to share about your decision?
There was a problem hiding this comment.
I guess it also means the language server will be disabled for all users after the update
That is something we could handle with an migration, by keeping the old application wide settings service and initializing the project wide settings service with it. However I thought the effort is not wort it.
I am a bit worried about moving the settings to the project level. This change would mean that users have to enable the language server for every project separately.
Yes I also thought about this. However when considering jetbrains own plugins, for example vue.js, those are also project wide configured.
However they come with the default "on" and can only be project wide be turned off. In our case I am not comfortable with defining a default, as this would also include choosing a default language server command.
Lastly we might also mix project wide and application wide, I have done this for another intellij plugin as well. That works by having two services, an application wide service that store in our case the command and if its enabled and an project wide service that would store the configuration.
What do you think ?
There was a problem hiding this comment.
I am not comfortable with defining a default
Same for me.
an application wide service that store in our case the command and if its enabled and an project wide service that would store the configuration.
I think I would prefer an option where the user would choose which level to use. Similar to how the code style settings allow you to choose profiles either on a project or application level. But without the profiles. Just a checkbox or something.
You haven't explained why you want to have project-specific configurations, but I assume you have multiple projects using different setups or styles. In the same way, I could imagine that some project also uses a different language server.
What do you think? I could also try to make this work if you prefer to not spend more time on it. Otherwise, I think I would also be fine with just moving the option to the project-level, but we would definitely have to document it in the changelog.
There was a problem hiding this comment.
You haven't explained why you want to have project-specific configurations, but I assume you have multiple projects using different setups or styles. In the same way, I could imagine that some project also uses a different language server
Yes. I believe you would customize the workspace configuration per project. I.e. in my case I define the nixd options, so that the current nixos autocompletion is using my flake's options and not those of some channel. Similarly I have an option for home-manager that would also only apply to this project. Even though I would say its likely that someone uses one language server for one project and the other for the other, we might as well apply this to everything.
What do you think? I could also try to make this work if you prefer to not spend more time on it. Otherwise, I think I would also be fine with just moving the option to the project-level, but we would definitely have to document it in the changelog.
I can imagine your proposal to be convenient, I will give it a try and see how it feels. I still believe we could also only make the workspace configuration a project setting because this is probably the only one that someone would change on a per project level. I will work on this, let's see when I will find the time :)
| NixLspServerDescriptor(@NotNull Project project, NixLspSettings settings) { | ||
| super(project, "Nix"); | ||
| myCommand = settings.getCommand(); | ||
| this.settings = settings; |
There was a problem hiding this comment.
though: Wondering if this could theoretically run into a race condition when the language server is started while the configuration is changed. Note that settings is a shared object. I assume it is safe as long as createCommandLine() and getWorkspaceConfiguration(ConfigurationItem) are called in the same action1 as this constructor.
I guess ideally, we would make a deep copy of the settings. However, that would make the code more complicated and I guess the worst that can happen is that we temporarily start the old command line with the new settings, just before the language server is restarted anyway. So, I think we can ignore this.
Footnotes
-
Read and write actions are a concept of IDEA's threading model to ensure isolation of independent operations. ↩
There was a problem hiding this comment.
Addressed in b7c49f7
That is probably cleaner in any case.
There was a problem hiding this comment.
Addressed
Not sure how your changes addressed any potential race condition. You are still using the shared settings object, you just no-longer store it in a field. I guess your changes at least make it more obvious that there could be a race condition. Anyway, as mentioned before, I would be fine with ignoring the race condition, if it exists. It would not really break the functionality, just maybe cause an unexpected error messages in some very rare edge cases.
There was a problem hiding this comment.
Yes, I am sorry, I didn't explain myself.
I thought about it in two different ways.
- I somehow was not sure how intellij handles those service (in my head it might be that the behave like hibernate proxies and can be detached / outdated, but probably this is not the case ...). As I don't know that, I figured it would be best to get the current settings via the project.
- I had a look at how jetbrains handles this in its own plugins. For the astro plugin, the
getWorkspaceConfigurationalso uses the shared settings to get the configuration, see https://github.com/JetBrains/intellij-plugins/blob/master/Astro/src/org/jetbrains/astro/service/AstroLspServerSupportProvider.kt
| val editor = super.createEditor() | ||
| editor.setHorizontalScrollbarVisible(true) | ||
| editor.setVerticalScrollbarVisible(true) | ||
| editor.settings.isUseSoftWraps = true |
There was a problem hiding this comment.
question: Not sure if I personally would enable soft-wraps here. What was the rationale for enabling it? Would it make sense to use the user's code style settings?
Also are the scrollbars not visible by default? O.o
There was a problem hiding this comment.
Yes, I just chose them because I thought it was sensible. Maybe I would even reconsider it and use softwrap without any scrollbars. If we don't use softwrap the editor takes as much horizontal space as it needs which leads to a horizontal scrollbar of the settings panel, which I would say should not happen (the scrollbar settings don't have any effect as far as I can tell so I would remove them). So I would also not let the user choose.
I remove the scrollbars in 1562d0f
There was a problem hiding this comment.
Yea, I agree that we don't want a horizontal scrollbar on the settings panel.
| row { | ||
| label("Workspace configuration:").resizableColumn() | ||
| } | ||
| row { | ||
| cell(createJsonEditorTextField()).align(Align.FILL) | ||
| .bind( |
There was a problem hiding this comment.
suggestion: Isn't resizableColumn() intended for the text field, and not for the label? It should also be possible to set the label on the cell, but I haven't tested it.
| row { | |
| label("Workspace configuration:").resizableColumn() | |
| } | |
| row { | |
| cell(createJsonEditorTextField()).align(Align.FILL) | |
| .bind( | |
| row { | |
| cell(createJsonEditorTextField()) | |
| .label("Workspace configuration:", LabelPosition.TOP) | |
| .align(Align.FILL) | |
| .resizableColumn() | |
| .bind( |
There was a problem hiding this comment.
Yes, good catch, that's much neater. Done in 17520c6
There was a problem hiding this comment.
Thanks. I noticed you removed resizableColumn() altogether. Just wanted to mention it in the case it was by accident.
There was a problem hiding this comment.
Yes this was intentional, I don't notice an effect in that case. I rather added it to be safe. Sorry for the confusion, I will revert it.
| return editor | ||
| } | ||
| } | ||
| editorTextField.preferredSize = Dimension(0, 150) |
There was a problem hiding this comment.
question (non-blocking): Has preferredSize here any effect? I expect that the size of the window is decided before this component is loaded.
There was a problem hiding this comment.
Seems strange to me that setting prefferedSize has this effect. But when it works, it works. 😄 Anyway, looks like you have actually removed the line in commit 17520c6. I assume you have made it work somehow else? (I haven't tried to run the UI code myself yet.)
There was a problem hiding this comment.
No, good catch, I accidentally committed my experiments with it. I will remove it in the next round.
JojOatXGME
left a comment
There was a problem hiding this comment.
Nothing new, just informing GitHub that I had already looked at your latest changes.
Feel free to add your opinion regarding my suggestion for where to store the settings. I think that is the only topic which is currently blocking the merge.
Anyway, no pressure. Feel free to take your time. 😅
|
Sorry for not approving the CI earlier. Looks like the PluginVerifier has a problem with
I guess the easiest solution is to move the dependency declaration to |

If done those changes rather for myself, because I disliked the escaping needed for the
--configoption of nixd.I hope those changes can also benefit the lsp support for other people directly and should allow more comfort.
I am aware, that in #68 you discussed switching to
lsp4ij, but for the time being this might help people.