Skip to content

New files are not picked up by the roslyn language server #1961

Description

@sse-virto

Description

Files created after the C# language server (csharp, Roslyn) has loaded its projects never join the project's compilation. get_diagnostics_for_file then reports phantom errors for the whole session:

  • Files referencing a type defined in a new file: CS0246 The type or namespace name 'X' could not be found, CS0103
  • The new file itself: IDE0005 Using directive is unnecessary on usings that are required
  • dotnet build --no-incremental on the same project: Build succeeded, 0 errors

Hints

It seems the new file is opened as a Miscellaneous Files document — compiled standalone against a bare reference set — so nothing in it resolves and its usings look unused, while the rest of the project cannot see its types.

Reproduction

  1. Start Serena on a C# project and let the language server finish indexing.
  2. Move a type out of an existing file into a new file in the same project (any way of creating a .cs file works).
  3. Call get_diagnostics_for_file on the original file and on the new file.

Observed: CS0246/CS0103 on the original file, IDE0005 on the new file's required usings.
Expected: the diagnostics dotnet build produces — none.

Analysis

File watching does reach the server: sync_file_system_changes logs
File system polling complete; 3 change events sent to language servers. Content sync of pre-existing files works.
It seems Roslyn adds documents when it re-evaluates a project, not on a watched-file Created event.

Related

#1593 (find_symbol can return stale/incorrect information, observed for Clojure/LSP)

Seems similar issue but unrelated fix.

Preconditions:

  • [x ] I have made sure it's an actual issue, not a question (use GitHub Discussions instead).
  • [x ] I have consulted the user guide and verified that the issue cannot be resolved by adjusting configuration/following recommended workflows.
  • [x ] I have looked for similar issues and discussions, including closed ones.

Issue details:

  • [ x] I have provided a meaningful title and description.
  • [ x] I have explained how the issue arose and, where possible, added instructions on how to reproduce it.
  • [ x] I have added details on my setup: Serena version, MCP client, OS, the programming language(s), relevant configuration adjustments and project specifics.
  • [ x] If the issue relates to an application of Serena to an open-source project, I have added the link.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions