-
-
Notifications
You must be signed in to change notification settings - Fork 345
feat: support workspace/didChangeWatchedFiles
for imported files
#2238
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
Conversation
About the file system watch pattern being used: Not sure why neovim wouldn't be able to handle About the usage of To resolve this issue, I would suggest to add the following (untested) function to the DocumentStore: /// **Thread safe** takes an exclusive lock when called on different documents
/// **Not thread safe** when called on the same document
pub fn refreshDocumentFromFileSystem(self: *DocumentStore, uri: Uri) !void {
{
const handle = self.getHandle(uri) orelse return;
if (handle.getStatus().open) return;
}
{
self.lock.lock();
defer self.lock.unlock();
const kv = self.handles.fetchSwapRemove(uri) orelse return;
log.debug("Closing document {s}", .{kv.key});
kv.value.deinit();
self.allocator.destroy(kv.value);
}
} This function will essentially remove the document from the document store unless it synchronized over the protocol. If the file system watching reports that the document has been modified or deleted, this function can be called. The existing logic in ZLS will read the new state from disk if it is needed again. This is why there is need to do anything when a file has been created. Also after parsing the uri from the client, the file extension should be checked.
The document store lacks testing for now so there is no easy way to add tests for this. Should be fine for now. |
Ah ok. It sounds obvious now, I just didn't realize those functions were so intended to go hand in hand with
Gotcha. I'm assuming just checking for
Sounds good. I'll push up the other changes for now, and spend some time debugging Neovim's implementation. |
Update: Since this appears to be a neovim issue, maybe a workaround like this makes sense for now? diff --git a/src/Server.zig b/src/Server.zig
index 5b9d687..43aeceb 100644
--- a/src/Server.zig
+++ b/src/Server.zig
@@ -629,7 +629,12 @@ fn initializedHandler(server: *Server, arena: std.mem.Allocator, notification: t
if (server.client_capabilities.supports_workspace_did_change_watched_files) {
// `{ "watchers": [ { "globPattern": "**" } ] }`
var watcher = std.json.ObjectMap.init(arena);
- try watcher.put("globPattern", .{ .string = "**" });
+ if (std.mem.eql(u8, "Neovim", server.client_capabilities.client_name orelse "")) {
+ try watcher.put("globPattern", .{ .string = "**" });
+ } else {
+ try watcher.put("globPattern", .{ .string = "**/*.{zig,zon}" });
+ }
var watchers_arr = try std.ArrayList(std.json.Value).initCapacity(arena, 1);
watchers_arr.appendAssumeCapacity(.{ .object = watcher });
var fs_watcher_obj: std.json.ObjectMap = std.json.ObjectMap.init(arena); |
I think that's reasonable. But instead of checking checking the client name right where the glob pattern is created, I would suggest some changes to be more in line with how ZLS handles other editor specific workarounds:
|
ecab722
to
54220fe
Compare
I checked a few editors and here is what I found:
I also tested the Here is what I get after manually configuring neovim to enable
After installing
|
Awesome, thanks so much for checking all of these!
I got the same warning about I also noticed the |
I used the 0.11.0 release.
This is the thing that is confusing me. Both backends are working for me. If am I understanding this correctly that you are saying that the issues occurs since neovim/neovim@b87505e? So how can I not reproduce this issue with 0.11? Also, did you need to manually configure neovim to enable the init.luavim.lsp.config['zls'] = {
cmd = { '/home/techatrix/repos/zls/zig-out/bin/zls' },
filetypes = { 'zig' },
root_markers = { 'build.zig' },
settings = {
zls = {
zig_exe_path = '/home/techatrix/.config/Code/User/globalStorage/ziglang.vscode-zig/zig/linux-x86_64-0.15.0-dev.151+6e8493daa/zig'
}
},
capabilities = {
workspace = {
didChangeWatchedFiles = {
dynamicRegistration = true,
}
}
},
}
vim.lsp.enable('zls') I also tested windows where neovim was behaving as expected. There is just a minor issue with ZLS around missing uri escape sequence normalization which I will resolve later. |
I'm honestly not sure, but I'll spend some more time looking into it.
Yep!
👍 |
I believe I found the cause of the inconsistency between us. When I do the same steps as #2160 but move So if the issue only occurs on linux where file watching is disabled by default and the |
Yeah, sorry I should have mentioned that. I was testing this in a template project created by
👍 |
Co-authored-by: Techatrix <[email protected]>
VS Code will report a file as created instead of changed when edited through gnome-text-editor.
Neovim on windows sends uri's that differ from other requests.
Thank you so much for all the help! @Techatrix |
This adds support for
workspace/didChangeConfiguration
. I have a few questions/ points of interest:I ran into some minor issues with with the
FileSystemWatcher
'sGlobPattern
."**/*.{zig,zon}"
(as well as"**/*.zig"
) caused the server to receive no notifications. I'm not sure if that was an issue with my implementation and/or Neovim's client implementation.Pattern
glob because theRelativePattern
glob is behind the capability's registration params, so there may be some LSP clients that don't implement this feature."**"
includes all files in the project directory (including those in.zig-cache
), I tried filtering out extraneous notifications by only applying updates to uris already in the document store. I believe this should cover all imported files, but I'm not 100% confident.Reading the entire file seems pretty expensive for every update, but it looks like the notification doesn't include any edit information. Maybe there's a smarter way around this?
I wasn't sure if it was more better to use the document store's
refreshDocument
method in the.Changed
case. The logic between.Created
and.Changed
would still be almost identical, except thatrefreshDocument
takes a null terminated slice, and requires allocation via the document store.openDocument
is marked as not thread safe. If this is to be used in the.Changed
case, should some additional checks/ locking be added at the call site?I wasn't sure how to add tests for this.
Closes #2160