Support C# language versions: parse C# 15 unions, and honour each project's LangVersion across a mixed-version solution
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- csharp, typescript
Línea de trabajo
Start with the C# spec and the project-loading path that reads MSBuild evaluation and creates Roslyn parse options; the issue does not name implementation files. Then trace how parse options flow into linked documents, target frameworks, Razor, file-based apps, and tree-sitter. Done means the specified mixed-version solution and language features pass against the latest published release, with tests covering each listed scenario.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
SharpLsp has no concept of a C# language version. It parses every project with the compiler it ships (Roslyn Microsoft.CodeAnalysis.CSharp.Workspaces 5.9.0, plus tree-sitter-c-sharp 0.23 for the syntax tier), whatever the project targets. C# 15 union types therefore don't parse. A valid C# 15 file is covered in bogus errors:
public union ContentBody(Page, Resource, ResourceList, ResourcesForYou, Container);
CS0246 The type or namespace name 'union' could not be found [Ln 9, Col 8]
CS0501 '<invalid-global-code>.ContentBody(Page, Resource, …)' must declare a body because it is not marked abstract, extern, or partial
CS1001 Identifier expected (×5, one per case type)
CS0246 The type or namespace name 'ContentBody' could not be found [Ln 6, Col 65] ← every use of the union fails too
<invalid-global-code> shows the parser has no union declaration at all. The second union in the same file (Selector, line 30) fails the same way. The project builds with the SDK's own compiler; only SharpLsp reports these errors.
What C# says (official sources)
- C# 15 adds union types, declared with the
unionkeyword. Each listed case type is one possible value, and switches over a union are checked for exhaustiveness. Source: What's new in C# 15. The DevBlogs post says the model and syntax may still change: Explore union types in C# 15. - The language version comes from the target framework unless
<LangVersion>overrides it:- Each TFM maps to a default version (.NET 8 → C# 12, .NET 9 → C# 13, .NET 10 → C# 14, .NET 11 → C# 15).
- Using a version newer than the TFM's default is unsupported.
- Source: C# language versioning.
<LangVersion>values aredefault,latest,latestMajor,previewor an explicit number. Settingdefaultis not the same as leaving it out:defaultmeans the newest version the compiler supports, regardless of TFM. Sources: Compiler options – language (LangVersion), Configure the C# language version.
Required behaviour
- Support C# 15 unions. Ship a Roslyn whose parser and binder know C# 15, and a tree-sitter C# grammar that parses
uniondeclarations, so syntax features (outline, folding, selection, semantic tokens) work. Every semantic feature must work on unions: hover, go to definition, references, rename, completion, exhaustiveness diagnostics inswitch, and code fixes. - Honour each project's own language version. A project on an earlier version must get exactly what
dotnet buildgives it: no union parse, and the compiler's own "feature 'union types' is not available in C# 14. Please use language version 15.0 or greater" error (CS8652/CS9058 family), never a newer language silently.- Roslyn has one parser that is gated per compilation by
CSharpParseOptions.LanguageVersion. "The parser for that version" means the newest compiler running with each project'sLanguageVersion, taken from MSBuild evaluation (LangVersion, else the TFM default, sodefault,latest,previewand omission all resolve as the SDK resolves them). - Never fall back to
CSharpParseOptions.Defaultfor a project-owned document.
- Roslyn has one parser that is gated per compilation by
- Several projects with different versions in one solution:
- Each project, and each target framework of a multi-targeted project, keeps its own parse options.
- A file linked into two projects is checked under each project's version. Its diagnostics follow the active target framework ([NETFX-CONTEXT]).
- Cross-project features (references, rename, Fix All in solution) must not reparse one project's syntax under another's version.
- The syntax tier (tree-sitter) has no version gate. It must accept the newest syntax without false syntax errors in older projects; language-version errors come only from the compiler.
- SDK and compiler skew: when the loaded SDK's analyzers or source generators are built against a newer Roslyn than SharpLsp ships (CS9057), report it in plain words and keep the rest of the project working ([REFACTOR-NEVER-SILENT]).
- File-based apps (
dotnet run file.cs) use the same language versiondotnet build file.cswould ([SCRIPTING-FILEBASED-SPEC]).
Spec work
Add a [CSHARP-LANGVERSION] section to the C# spec covering resolution, per-project and per-TFM parse options, the compiler/SDK skew policy and the tree-sitter policy. Cross-reference it from [NETFX-CONTEXT] and the Razor spec, since Razor already carries the project's CSharpParseOptions.LanguageVersion. F# has the same concept (<LangVersion> for FCS); F# goes first per project rules, so open an F# sibling issue.
Tests (when fixing)
Use real projects in one solution:
- A:
net11.0(C# 15) with the union above, matched exhaustively in aswitch. - B:
net10.0(C# 14) containing the same union. - C:
net8.0with<LangVersion>preview</LangVersion>. - D: multi-targeted
net10.0;net11.0.
Assert:
- A has zero diagnostics and hover/definition/references/rename work on
ContentBodyand its cases. - A missing union case is the compiler's exhaustiveness warning.
- B reports exactly the build's language-version error, not CS0246/CS1001 noise.
- C parses unions.
- D's diagnostics switch with the active target framework.
- Outline and folding show the union in every project.
Keep this issue open until the latest published release's own binaries pass this against a real C# 15 project.
- Lenguaje dominante
- TypeScript
- Estrellas
- 185
- Forks
- 12
- Merge medio
- 7 h 33 min
- PR fusionados (30 d)
- 63
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Nimblesite/SharpLsp
-
Fix All + Enforce overwrites unsaved edits to .editorconfig / Directory.Build.props / sharplsp.tomlAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Nimblesite/SharpLsp#644 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Nimblesite/SharpLsp#641 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Nimblesite/SharpLsp#640 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Nimblesite/SharpLsp#639 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Nimblesite/SharpLsp#510 ·
Los mantenedores suelen responder en 1 día
Todos los issues de Nimblesite/SharpLsp
Issues similares
-
api bug priority:low ready-for-agent
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
wondermoney/wondermoney#862 ·
Los mantenedores suelen responder en 1 día
-
good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
rootsiemen/seo-agent-tools#70 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
alvinunreal/oh-my-opencode-slim#1971 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
elecnix/bellwether#467 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día