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
- Start Serena on a C# project and let the language server finish indexing.
- Move a type out of an existing file into a new file in the same project (any way of creating a
.cs file works).
- 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.
Description
Files created after the C# language server (
csharp, Roslyn) has loaded its projects never join the project's compilation.get_diagnostics_for_filethen reports phantom errors for the whole session:CS0246 The type or namespace name 'X' could not be found,CS0103IDE0005 Using directive is unnecessaryon usings that are requireddotnet build --no-incrementalon the same project:Build succeeded, 0 errorsHints
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
.csfile works).get_diagnostics_for_fileon the original file and on the new file.Observed:
CS0246/CS0103on the original file,IDE0005on the new file's required usings.Expected: the diagnostics
dotnet buildproduces — none.Analysis
File watching does reach the server:
sync_file_system_changeslogsFile 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
Createdevent.Related
#1593 (
find_symbolcan return stale/incorrect information, observed for Clojure/LSP)Seems similar issue but unrelated fix.
Preconditions:
Issue details: