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

Add file watching in the server as a fallback for editors that don't support it #1456

Open
vinistock opened this issue Mar 5, 2024 · 3 comments
Labels
enhancement New feature or request help-wanted Extra attention is needed pinned This issue or pull request is pinned and won't be marked as stale

Comments

@vinistock
Copy link
Member

We ask editors to watch Ruby files for us here, which we use to update the codebase index upon modifications.

However, the registration may fail in two ways: some editors don't support dynamic feature registration and some don't support file watching. In those cases, only the declarations from the original indexing will be available since we will never receive the modification events.

We can use the listen gem to provide a fallback and listen to modifications from the server when file watching is not available.

This is suboptimal from a performance standpoint since having the editor watch files means that it can broadcast the modification events to all parties interested in handling those - as opposed to having each server watch files on their own. However, it's better than never updating the index.

Questions

File watching is available for VS Code. Is it also available for other popular editors such as NeoVim, Emacs, Sublime?

Implementation suggestion

My suggestion is adding an else statement where we register for file watching. In the else branch, we would:

  • Require the listen gem
  • Use listen to register the callbacks for when files are modified

We should evaluate if there's any way to share the current handler for modifications, with the one using listen.

@vinistock vinistock added enhancement New feature or request help-wanted Extra attention is needed pinned This issue or pull request is pinned and won't be marked as stale labels Mar 5, 2024
@bjarosze
Copy link
Contributor

bjarosze commented Apr 19, 2024

Neovim supports file watching, but doesn't support dynamic registration:

      workspace = {
        applyEdit = true,
        configuration = true,
        didChangeWatchedFiles = {
          dynamicRegistration = false,
          relativePatternSupport = true
        },
        semanticTokens = {
          refreshSupport = true
        },
        symbol = {
          dynamicRegistration = false,
          hierarchicalWorkspaceSymbolSupport = true,
          symbolKind = {
            valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }
          }
        },
        workspaceEdit = {
          resourceOperations = { "rename", "create", "delete" }
        },
        workspaceFolders = true
      }

Is it possible to register it standard way?
Would it make sense to update indexes on didSave in case when file watching is not possible?

@vinistock
Copy link
Member Author

My understanding is that there are only two types of registration: static and dynamic. The static registrations are basically the response of the initialize request, which is composed of the server capabilities - indicating what the server supports and needs.

Dynamic registrations happen as notifications sent by the server to the client to enable some functionality.

Based on the specification, there does not seem to be a way to ask for file watching using static registrations.

Would it make sense to update indexes on didSave in case when file watching is not possible?

We do want to index files even before they are saved (see #1908). That certainly helps, but unfortunately it's not enough because files can be modified outside of the editor context, which means we'd fail to track those modifications.

Consider the case of switching git branches. When you switch, several files may be added, changed or deleted because of the state differences. With file watching, the LSP receives notifications about all of those modifications and we can update the index to reflect it. Same story if you run something like RuboCop on the terminal, the only way to know about those is through file watching. But didSave or didChange notifications don't capture this type of thing, which means the index would go stale.

@bjarosze
Copy link
Contributor

Thanks for clarification.

I've double checked if neovim supports file watching and it indeed does, but it's disabled by default. When I enabled it, it works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help-wanted Extra attention is needed pinned This issue or pull request is pinned and won't be marked as stale
Projects
None yet
Development

No branches or pull requests

2 participants