Skip to content
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

nixd/Server/configuration: use .nixd.json for workspace/configuration defaults #261

Conversation

jonathanjameswatson
Copy link
Member

When nixd in workspace/configuration is unset in VSCode, we get [null]. This causes the JSON configuration to be used (not overwritten). However, in Emacs, we get [{}] instead, so the JSON configuration is overwritten with the default one. By using the JSON configuration as the defaults for workspace/configuration, we get the same behaviour when workspace/configuration is unset in VSCode and Emacs. The JSON configuration is no longer ignored when workspace/configuration is set, but it never takes priority.

An additional advantage of this change is that when workspace/configuration is unset (or set to null) while the language server is running, we fall back to the JSON configuration instead of keeping the old deleted workspace/configuration.

Feel free to make any improvements to my branch.

Copy link
Member

@inclyc inclyc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

Left some comment that I think it is unnecessary to change public codes, and also, the commit message should be revised as path/to/subsystem: change, with more details about the diff (don't say fix bug, instead, say what you have been fixed).

readJSONConfig();
configuration::TopLevel JSONConfigCopy = JSONConfig;
updateConfig(std::move(JSONConfigCopy));
WorkspaceConfiguration =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know why we need to move this statement here? It is just an assignment to WorkspaceConfiguration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have probably overestimated how concurrent the code is, but the reasoning was that the callback to initialized could run before the assignment to WorkspaceConfiguration, making the resulting fetchConfig call fail.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@inclyc Could you confirm whether or not this could happen?

llvm::StringRef PayloadKind) {
T Result;
llvm::StringRef PayloadKind, T Base = T()) {
T Result = Base;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is very fundamental to the LSP library, I think we'd better do such thing in Controller.cpp, not public codes (here).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that it's reasonable to have an optional argument that defines the defaults for parsing. It is an optional parameter so it shouldn't change the behaviour of the function (although maybe move semantics could be used to make it more efficient).

If I can't change this then I will either have to copy the implementation of this function into Controller.cpp (breaks DRY) or make a more complicated system of defaulting that acts on the parsed configuration::TopLevel structs (more error-prone and less efficient). Either of these options would make the code less maintainable. What would you suggest?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

structs (more error-prone and less efficient).

How about use a dedicated function like updateConfig and do the work there? I think introduce a new default argument in the basic library is more error prone for large C++ project (since it might implicitly change many things)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have refactored parseParam again so that it no longer takes a default argument and behaves the same way as before (uninitializing Result by default or using the default constructor if this is not possible, as well as not compiling if neither is possible). However, it now shares code with parseParamWithDefault, which has an argument that determines some default JSON that should be used. I think that this is a reasonable function to add to a general-purpose LSP library.

lspserver/include/lspserver/LSPServer.h Outdated Show resolved Hide resolved
@inclyc inclyc changed the title Use JSON for workspace/configuration defaults nixd/Server/configuration: use .nixd.json for workspace/configuration defaults Sep 20, 2023
@jonathanjameswatson
Copy link
Member Author

I will rebase and squash the commits on my end as they aren't currently intended to be looked at individually.

…on` defaults

Add jjw-log for options.enable

Actually use BaseConstructor

Fix some bugs

Fix move bug

Remove jjw-log

Format changed files
lspserver/include/lspserver/LSPBinder.h Show resolved Hide resolved
lspserver/include/lspserver/LSPBinder.h Outdated Show resolved Hide resolved
lspserver/include/lspserver/LSPBinder.h Outdated Show resolved Hide resolved
nixd/lib/Server/Controller.cpp Outdated Show resolved Hide resolved
lspserver/include/lspserver/LSPBinder.h Outdated Show resolved Hide resolved
nixd/include/nixd/Server/Controller.h Show resolved Hide resolved
nixd/lib/Server/Controller.cpp Show resolved Hide resolved
nixd/lib/Server/Controller.cpp Outdated Show resolved Hide resolved
nixd/include/nixd/Server/Controller.h Show resolved Hide resolved
@@ -122,6 +128,7 @@ class Controller : public lspserver::LSPServer {

std::mutex ConfigLock;

configuration::TopLevel JSONConfig;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you can add some comment here, saying that it is the default value of config

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thoughts, I think I should call it DefaultConfig and then add a comment that says it is set to the contents of .nixd.json if it exists.

Copy link
Member

@inclyc inclyc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM again

@jonathanjameswatson jonathanjameswatson merged commit c7cd061 into nix-community:main Oct 7, 2023
14 checks passed
@jonathanjameswatson jonathanjameswatson deleted the update-config-with-json branch October 7, 2023 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants