Skip to content
Merged
46 changes: 27 additions & 19 deletions docs/plans/DIAGNOSTICS-STATIC-ANALYZERS-PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ Implements [ANALYZERS-MONOREPO-GATE] and [ANALYZERS-SOLUTION-SCOPE].
TOML strictness.
- [ ] Update `src/examples/config/sharplsp.example.toml` through a TOML parser/serializer, not line
splicing.
- [ ] Hot-reload workspace/static-analyzer config through
`workspace/didChangeConfiguration`.
- [x] Hot-reload workspace/static-analyzer config through
`workspace/didChangeConfiguration` (shipped as `[analyzers] dead_code`/`monorepo`) — `configuration_live.rs` `reconfigure`;
e2e `analyzer_settings_from_the_editor_or_the_file_apply_to_the_next_pull` (editor and on-disk edits).
- [ ] Bump `global_state_version` and send `workspace/diagnostic/refresh` when
monorepo/static-analyzer settings change.
- [ ] Full-stack test: default config produces no unused-public-code
diagnostics.
- [ ] Full-stack test: `repository_kind = "standard"` suppresses the analyzer
even when `unused_public_symbols = true`.
- [x] Full-stack test: `repository_kind = "standard"` suppresses the analyzer
even when `unused_public_symbols = true` (shipped as `[analyzers] dead_code`/`monorepo`) — same e2e, step 2: `dead_code` on,
no monorepo, the public F# function is not reported.
- [ ] Full-stack test: `repository_kind = "monorepo"` enables the analyzer only
when `solution_wide_analysis` and `analyzers_enabled` are also true.

Expand Down Expand Up @@ -63,10 +65,12 @@ Implements [ANALYZERS-DIAGNOSTICS], [ANALYZERS-PERFORMANCE], and
Implements [ANALYZERS-UNUSED-PUBLIC], [ANALYZERS-REFERENCE-MODEL], and
[ANALYZERS-SUPPRESSION] for C#.

- [ ] Build a Roslyn candidate collector from `ISymbol` data for public API
surface.
- [ ] Use `SymbolFinder.FindReferencesAsync` to count non-declaration references
across the loaded solution graph.
- [x] Build a Roslyn candidate collector from `ISymbol` data for public API
surface — `DeadCodeAnalyzer.cs` `IsCandidate`/`Visibility`; `DeadCodeAnalyzerTests`
`Monorepo_reports_unused_public_symbols_as_errors`.
- [x] Use `SymbolFinder.FindReferencesAsync` to count non-declaration references
across the loaded solution graph — `SearchScope.cs`; `DeadCodeAnalyzerTests`
`Types_referenced_only_through_members_are_not_flagged`.
- [ ] Count inheritance, interface implementation, overrides, attributes,
construction, invocation, and member access as uses.
- [x] Roll member uses from outside a type up to the type (extension calls, static
Expand All @@ -81,13 +85,14 @@ Implements [ANALYZERS-UNUSED-PUBLIC], [ANALYZERS-REFERENCE-MODEL], and
list from the spec.
- [ ] Emit `SLSPC0101` diagnostics with source `sharplsp-static-csharp`,
severity Information, and tag `Unnecessary`.
- [ ] Full-stack test: unused public C# type in a monorepo solution is reported.
- [x] Full-stack test: unused public C# type in a monorepo solution is reported —
`configuration_live.rs` `csharp_unused_public_types_are_dead_only_in_a_monorepo`, step 2.
- [ ] Full-stack test: public C# type referenced by another project is not
reported.
- [ ] Full-stack test: public C# member used by reflection/framework attribute is
suppressed.
- [ ] Full-stack test: non-monorepo config reports no C# unused-public-code
diagnostics.
- [x] Full-stack test: non-monorepo config reports no C# unused-public-code
diagnostics — same test, steps 1 and 3: only the internal type is reported.

## Phase 4: F# Unused Public Symbols (P0)

Expand All @@ -98,8 +103,9 @@ Implements [ANALYZERS-UNUSED-PUBLIC], [ANALYZERS-REFERENCE-MODEL], and
functions, members, union cases, record fields, active patterns, delegates,
and interfaces.
- [ ] Treat `.fsi` signature files as the public-surface authority when present.
- [ ] Use FCS symbol-use APIs to count non-declaration references across all F#
projects in the loaded solution graph.
- [x] Use FCS symbol-use APIs to count non-declaration references across all F#
projects in the loaded solution graph — `FSharpAnalyzers.fs` `deadCodeDiagnostics`;
`SidecarEndToEndTests.fs` (referenced bindings never flagged).
- [ ] Count pattern matching, union-case construction, record construction/update,
active-pattern use, member access, and interface/override binding as uses.
- [ ] Suppress nested-member cascades when the containing public module/type is
Expand All @@ -110,14 +116,14 @@ Implements [ANALYZERS-UNUSED-PUBLIC], [ANALYZERS-REFERENCE-MODEL], and
implicit-use attributes.
- [ ] Emit `SLSPF0101` diagnostics with source `sharplsp-static-fsharp`,
severity Information, and tag `Unnecessary`.
- [ ] Full-stack test: unused public F# function in a monorepo solution is
reported.
- [x] Full-stack test: unused public F# function in a monorepo solution is
reported — `configuration_live.rs` step 3: `unusedPublic` reported as an error.
- [ ] Full-stack test: public F# value referenced by another project is not
reported.
- [ ] Full-stack test: `.fsi` public-surface declarations receive diagnostics at
the signature declaration where possible.
- [ ] Full-stack test: non-monorepo config reports no F# unused-public-code
diagnostics.
- [x] Full-stack test: non-monorepo config reports no F# unused-public-code
diagnostics — `configuration_live.rs` step 2: only the private helper is reported.

## Phase 5: Cross-Language References (P1)

Expand All @@ -138,8 +144,10 @@ Implements the cross-language part of [ANALYZERS-REFERENCE-MODEL].
unopened files after `workspace/diagnostic`.
- [ ] VS Code e2e test: changing `repository_kind` triggers
`workspace/diagnostic/refresh` and removes/adds diagnostics.
- [ ] Add code descriptions for `SLSPC0101` and `SLSPF0101` that link to the
static analyzer docs.
- [x] Add code descriptions for `SLSPC0101` and `SLSPF0101` that link to the
static analyzer docs — `RuleDocumentation.cs` (Common) points both at the website's
Diagnostics › Dead code section; `DeadCodeAnalyzerTests` and `FSharpAnalyzersTests`
assert the link, and that `SLSPF0102` carries none.
- [ ] Add future code action stubs using `Diagnostic.data`: suppress diagnostic,
reduce visibility, and safe delete.
- [ ] Add performance regression fixture for a mixed 50-project solution.
Expand Down
2 changes: 1 addition & 1 deletion docs/plans/DISTRIBUTION-PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ CLAUDE.md mandates hierarchical IDs (`[GROUP-TOPIC]`), uppercase, hyphen-separat
- [x] `tools/audit/dotnet-vulnerable.mjs` fails the .NET leg (dotnet list exits 0 on findings) + tests in `make _test-tooling`
- [x] `ci-audit.yml` runs `make audit` on every PR (`ci.yml`), weekly on `main`, and as a release gate (`release` needs `audit`)
- [x] Include `audit` in the final CI job's dependencies; YAML-based regression tests guard both CI and Marketplace/Open VSX release enforcement.
- [ ] Upgrade `@vscode/test-cli` once a release drops mocha 11 (its nested `diff` 7.0.0 carries low-severity GHSA-73rr-hh4g-fpgx)
- [x] Upgrade `@vscode/test-cli` once a release drops mocha 11 (its nested `diff` 7.0.0 carries low-severity GHSA-73rr-hh4g-fpgx) — the tree now resolves `mocha` 12 with `diff` 9.0.0 (`npm ls diff`), and `npm audit` reports 0 vulnerabilities at every severity

## TODO Checklist — original v0.1.0 work (status snapshot)

Expand Down
25 changes: 16 additions & 9 deletions docs/plans/RIDER-PLUGIN-PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,19 @@ only — Community editions are not supported.

### Phase 7: Build infrastructure

- [ ] Add `build-rider` Makefile target — calls `./gradlew buildPlugin`
- [x] Add `build-rider` Makefile target — calls `./gradlew buildPlugin`
and copies the zip to `dist/sharplsp-rider.zip` — **but only if**
the environment has a JVM; otherwise skip with a warning
- [ ] Add `package-rider` Makefile target — alias for `build-rider` for
naming symmetry with `package-zed`
- [ ] Add `test-rider` Makefile target — `./gradlew test`
- [ ] Add `lint-rider` Makefile target — `./gradlew check`
- [ ] Add `clean-rider` Makefile target — `./gradlew clean`
the environment has a JVM; otherwise skip with a warning — as the private `_build-rider` leg of `make build`: the Makefile's twelve public targets are its whole surface.
`tools/rider/gradle.sh` finds a JDK 21+, and records a skipped-leg marker when there is none
- [x] Add `package-rider` Makefile target — alias for `build-rider` for
naming symmetry with `package-zed` — `_build-rider` IS the packaging step, as `_build-zed`
is Zed's; neither editor has a public package target
- [x] Add `test-rider` Makefile target — `./gradlew test` — `_test-rider` (Kover report and
coverage gate), a leg of `make test`
- [ ] Add `lint-rider` Makefile target — `./gradlew check`. Open: no Kotlin linter is
configured and `check` reruns the test suite; needs a decision on detekt/ktlint or
`allWarningsAsErrors` before `make lint` can cover the plugin
- [x] Add `clean-rider` Makefile target — `./gradlew clean` — `_clean-rider`, a leg of `make clean`
- [x] Wire Rider build into the top-level `build` target (`_build-rider`)
- [x] Wire Rider tests into the top-level `test` target (`_test-rider`)
- [x] Update README `Install` section with a one-paragraph Rider block
Expand Down Expand Up @@ -214,8 +219,10 @@ how it was installed — and CI built and coverage-gated it in that state.

### Phase 9: CI

- [ ] Add `build-rider` + `test-rider` to `.github/workflows/ci.yml`
under a matrix job that requires JDK 17
- [x] Add `build-rider` + `test-rider` to CI — the reusable workflows of [DIST-CI-LAYOUT]:
`ci-build.yml` `build-rider` and `ci-test-editors.yml` `test-rider` (`RIDER_REQUIRED=1`),
both through `.github/actions/rider-environment` on JDK 21, which the current Rider SDK
needs; `tools/ci/security-gates.test.mjs` pins the `test-rider` job
- [x] Cache `~/.gradle/caches` and `~/.gradle/wrapper` (`ci-test-editors.yml`,
and the release `build-rider` job mirrors it)
- [x] The Rider plugin zip is built and attached to tag releases alongside the
Expand Down
59 changes: 54 additions & 5 deletions src/sharplsp/tests/e2e_modules/configuration_live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ use workspace_diagnostic_support::{completed_pull, observed_request};
/// One private and one public function that nothing calls.
const DEAD_FS: &str = "module Dead\n\nlet private unusedHelper () = 1\n\nlet unusedPublic () = 2\n";

/// One internal and one public C# type that nothing references.
const DEAD_CS: &str =
"namespace Dead;\n\ninternal sealed class Hidden { }\n\npublic sealed class Orphan { }\n";

/// How long the server is given to notice an edited configuration file.
const NOTICED: Duration = Duration::from_secs(30);

#[test]
fn analyzer_settings_from_the_editor_or_the_file_apply_to_the_next_pull() {
require_dotnet();
let (workspace, source) = dead_code_workspace();
let mut session = LiveSession::start(workspace.path(), &source);
let mut session = LiveSession::start(workspace.path(), &source, "SLSPF0101");

// 1. The file turns the dead-code analyzer off: nothing is reported dead.
session.assert_dead(&[]);
Expand Down Expand Up @@ -47,6 +51,48 @@ fn analyzer_settings_from_the_editor_or_the_file_apply_to_the_next_pull() {
session.client.shutdown_and_exit();
}

/// [ANALYZERS-MONOREPO-GATE] through the real host and C# sidecar: an unused
/// internal type is dead code everywhere, but an unused PUBLIC type is reported
/// only once the workspace declares itself a monorepo — and then as an error.
#[test]
fn csharp_unused_public_types_are_dead_only_in_a_monorepo() {
require_dotnet();
let (workspace, source) = dead_csharp_workspace();
let mut session = LiveSession::start(workspace.path(), &source, "SLSPC0101");

// 1. A standard repository: the internal type is dead, a warning; the public one is API.
session.await_dead(&[("Hidden", 2)]);

// 2. The file declares a monorepo: the public type is dead too, and both are errors.
write_configuration(
workspace.path(),
"[analyzers]\ndead_code = true\nmonorepo = true\n",
);
session.await_dead(&[("Hidden", 1), ("Orphan", 1)]);

// 3. Back to a standard repository: the public type is API again.
write_configuration(workspace.path(), "[analyzers]\ndead_code = true\n");
session.await_dead(&[("Hidden", 2)]);
session.client.shutdown_and_exit();
}

/// A C# project with dead types, and a `sharplsp.toml` turning the dead-code analyzer on.
fn dead_csharp_workspace() -> (tempfile::TempDir, PathBuf) {
let workspace = tempfile::tempdir().expect("real C# workspace");
let project = workspace.path().join("Dead");
std::fs::create_dir_all(&project).expect("project directory");
std::fs::write(
project.join("Dead.csproj"),
r#"<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup><TargetFramework>net10.0</TargetFramework><OutputType>Library</OutputType></PropertyGroup>
</Project>"#,
)
.expect("write the project");
std::fs::write(project.join("Dead.cs"), DEAD_CS).expect("write the source");
write_configuration(workspace.path(), "[analyzers]\ndead_code = true\n");
(workspace, project.join("Dead.cs"))
}

/// An F# project with dead code, and a `sharplsp.toml` turning the dead-code analyzer off.
fn dead_code_workspace() -> (tempfile::TempDir, PathBuf) {
let workspace = tempfile::tempdir().expect("real F# workspace");
Expand Down Expand Up @@ -74,12 +120,14 @@ fn write_configuration(root: &Path, text: &str) {
struct LiveSession {
client: LspClient,
uri: String,
/// The dead-code rule of the source's language: `SLSPF0101` or `SLSPC0101`.
code: &'static str,
traffic: Vec<Value>,
}

impl LiveSession {
/// Start the server with pull diagnostics and wait until the F# project loads.
fn start(root: &Path, source: &Path) -> Self {
/// Start the server with pull diagnostics and wait until the project loads.
fn start(root: &Path, source: &Path, code: &'static str) -> Self {
let mut client = LspClient::spawn_in(Stdio::null(), Some(root));
let initialized = client.initialize_with_capabilities(
json!(path_to_file_uri(root)),
Expand All @@ -89,9 +137,10 @@ impl LiveSession {
let mut session = Self {
client,
uri: path_to_file_uri(source),
code,
traffic: Vec::new(),
};
session.wait_for(NOTICED, "the F# project to load", |session| {
session.wait_for(NOTICED, "the project to load", |session| {
session
.received("workspace/projectInitializationComplete")
.is_some()
Expand All @@ -111,7 +160,7 @@ impl LiveSession {
.as_array()
.expect("a full report")
.iter()
.filter(|item| item["code"] == "SLSPF0101")
.filter(|item| item["code"] == self.code)
.filter_map(|item| {
Some((
named(item["message"].as_str()?)?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public async Task NonMonorepo_reports_private_and_internal_dead_code_as_warnings
Assert.NotNull(hidden);
Assert.Equal("Warning", hidden!.Severity);
Assert.Equal("SLSPC0101", hidden.Code);
Assert.Equal("https://sharplsp.dev/docs/diagnostics/#dead-code", hidden.HelpLink);
Assert.Contains("Dead code", hidden.Message);
Assert.Contains("method", hidden.Message);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.FindSymbols;
using SharpLsp.Sidecar.Common;

namespace SharpLsp.Sidecar.CSharp.Workspace;

Expand Down Expand Up @@ -185,7 +186,7 @@ CancellationToken ct
Message: message,
Severity: severity,
Code: DiagnosticCode,
HelpLink: "",
HelpLink: RuleDocumentation.DeadCode,
Tags: [DiagnosticTags.Unnecessary]
);
}
Expand Down
18 changes: 18 additions & 0 deletions src/sidecars/SharpLsp.Sidecar.Common/RuleDocumentation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace SharpLsp.Sidecar.Common;

/// <summary>
/// Where each SharpLsp-owned analyzer rule is documented: the diagnostic's
/// <c>codeDescription.href</c>, so the editor links the code to its explanation.
/// One place for both sidecars. [ANALYZERS-DIAGNOSTICS]
/// </summary>
public static class RuleDocumentation
{
/// <summary>The dead-code rules <c>SLSPC0101</c> (C#) and <c>SLSPF0101</c> (F#).</summary>
public const string DeadCode = "https://sharplsp.dev/docs/diagnostics/#dead-code";

/// <summary>The documentation of <paramref name="code"/>; empty for a rule with none.</summary>
public static string For(string code)
{
return code is "SLSPC0101" or "SLSPF0101" ? DeadCode : "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ let ``buildDiagnostic maps a 1-based range to 0-based positions`` () =
Assert.Equal("SLSPF0101", d.Code)
Assert.Equal("Warning", d.Severity)
Assert.Equal("msg", d.Message)
// [ANALYZERS-DIAGNOSTICS]: the rule links to its documentation, as codeDescription.href.
Assert.Equal("https://sharplsp.dev/docs/diagnostics/#dead-code", d.HelpLink)
let other = FSharpAnalyzers.buildDiagnostic "SLSPF0102" "Warning" "msg" r
Assert.Equal("", other.HelpLink)

[<Fact>]
let ``deadCodeDiagnostics returns empty when disabled`` () =
Expand Down
2 changes: 1 addition & 1 deletion src/sidecars/SharpLsp.Sidecar.FSharp/FSharpAnalyzers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let buildDiagnostic
Message = message
Severity = severity
Code = code
HelpLink = ""
HelpLink = SharpLsp.Sidecar.Common.RuleDocumentation.For code
Tags = DiagnosticTags.ofCode code }

/// Classify a dead declaration into a diagnostic, honoring the monorepo gate.
Expand Down
4 changes: 4 additions & 0 deletions src/website/src/docs/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ monorepo = false

Project filters apply to workspace results for both languages. Direct `textDocument/diagnostic` requests remain unfiltered. Filters also accept full native project paths, using forward slashes in glob patterns.

<h2 id="dead-code">Dead code</h2>

SharpLsp reports code that nothing references as `SLSPC0101` in C# and `SLSPF0101` in F#. The code in the Problems panel links here.

In normal mode, private/internal dead code is reported as a warning and public symbols are treated as possible external API. In monorepo mode, unused public symbols are also reported and use error severity.

## Severity Mapping
Expand Down
Loading