Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/plans/DEBUGGING-PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ are green.
*an unbuilt project resolves to nothing or to a real file, and to MSBuild once built*
- [x] Run C# file-based apps with `dotnet run --file <abs path>` (never the positional form)
and debug them via `dotnet build <file> --artifacts-path <dir>`. `launch-run.ts:47`
`runArgs`, `launch-run.ts:131` `buildFileBasedApp`, `launch-run.ts:152`
`fileBasedAssembly`; tests `run-debug-scripts.test.ts` *a file-based .cs runs via dotnet
`runArgs`, `launch-run.ts` `buildFileBasedApp` (launches MSBuild's `TargetPath`); tests `run-debug-scripts.test.ts` *a file-based .cs runs via dotnet
run --file, never the positional form* and *debugging a file-based .cs launches the
artifacts-path assembly*
- [x] Run `.fsx` with `dotnet fsi --exec`; refuse `.fsx` debugging with a named message.
Expand Down
14 changes: 7 additions & 7 deletions docs/plans/DIAGNOSTICS-STATIC-ANALYZERS-PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ Implements the cross-language part of [ANALYZERS-REFERENCE-MODEL].
- [ ] Define a shared metadata identity DTO for C# and F# public symbols.
- [ ] Count C# references to F# public symbols through project-reference metadata.
- [ ] Count F# references to C# public symbols through project-reference metadata.
- [ ] Suppress diagnostics when cross-language identity is ambiguous.
- [ ] Full-stack test: C# calls public F# function, F# symbol is not reported.
- [ ] Full-stack test: F# calls public C# method, C# symbol is not reported.
- [ ] Full-stack test: ambiguous metadata identity suppresses instead of reporting
- [x] Suppress diagnostics when cross-language identity is ambiguous — `CrossLanguageReferences` (Common) marks every project the other language references; both analyzers report no unused public code there (#617).
- [x] Full-stack test: C# calls public F# function, F# symbol is not reported — `configuration_live.rs` `a_public_fsharp_function_only_csharp_calls_is_not_dead_in_a_monorepo`.
- [x] Full-stack test: F# calls public C# method, C# symbol is not reported — `configuration_live.rs` `a_public_csharp_type_only_fsharp_uses_is_not_dead_in_a_monorepo`.
- [x] Full-stack test: ambiguous metadata identity suppresses instead of reporting
a false positive.

## Phase 6: Editor Experience And Follow-Up Actions (P1)

## Phase 6: Editor Experience And Follow-Up Actions (P1) — both tests above: the
unused public symbol of a cross-language-referenced project is not reported either.
- [ ] VS Code e2e test: monorepo static diagnostics appear in Problems for
unopened files after `workspace/diagnostic`.
- [ ] VS Code e2e test: changing `repository_kind` triggers
Expand Down Expand Up @@ -194,4 +194,4 @@ Implements the cross-language part of [ANALYZERS-REFERENCE-MODEL].

- [ ] Share metadata identity between C# and F# indexes.
- [ ] Count C# to F# and F# to C# references.
- [ ] Suppress ambiguous cross-language cases.
- [x] Suppress ambiguous cross-language cases (see the matching phase row).
2 changes: 1 addition & 1 deletion docs/specs/DIAGNOSTICS-STATIC-ANALYZERS-SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,5 @@ The analyzer must prefer silence over false positives:

- If the workspace is not explicitly configured as a monorepo, return no unused-public-code diagnostics.
- If a project is unloaded or failed to load, return no unused-public-code diagnostics for symbols that could be referenced by that project.
- If cross-language identity cannot be proven for a symbol, do not report it as unused.
- If cross-language identity cannot be proven for a symbol, do not report it as unused. Until metadata identity is shared between the compilers, every project the other language references — a C# project an F# project references, or the reverse — reports no unused public code at all; private and internal code is still judged (#617). Implemented by `SharpLsp.Sidecar.Common.Solutions.CrossLanguageReferences`.
- If the analyzer cannot distinguish a framework entry point from ordinary public API, suppress the diagnostic and emit structured trace logging for future rule tuning.
2 changes: 1 addition & 1 deletion docs/specs/SHARPLSP-SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ A design-time build writes generated files under the project's `obj/<configurati

The host sends one path to each sidecar's `workspace/open`. When that path is a directory, the C# sidecar discovers a target under it: an unambiguous `.sln`, `.slnx`, or `.csproj` is opened directly. Discovery **never guesses** between several nested solutions — a monorepo root holding `app/App.sln` and `other/Other.sln` is ambiguous, and guessing would silently load the wrong half of the repository.

The VS Code extension discovers `.sln` and `.slnx` files in the workspace. It opens the sole solution automatically. With several solutions it presents a picker, then sends the selected solution file to **both** sidecars through `sharplsp/loadSolution`. Cancelling leaves the choices visible in Solution Explorer. A sidecar's directory-discovery error must never replace this selection flow.
The VS Code extension discovers `.sln` and `.slnx` files in the workspace. It opens the sole solution automatically. With several solutions it presents a picker, then sends the selected solution file to **both** sidecars through `sharplsp/loadSolution`. Cancelling leaves the choices visible in Solution Explorer. A sidecar's directory-discovery error must never replace this selection flow. A configured `csharp.solution_path` (below) settles the choice before any of this: the extension reads it from `sharplsp/configuration`, loads that solution and asks nothing, so the Solution Explorer and the Test Explorer show the solution the server already opened. A stale entry is no choice, and the selection flow runs as if it were unset.

`csharp.solution_path` in `sharplsp.toml` resolves that ambiguity by naming the solution to open, absolute or relative to the workspace root:

Expand Down
7 changes: 4 additions & 3 deletions src/editors/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as client from './client.js';
import * as sharedState from './state.js';
import { registerEditorNavigation } from './editor-navigation.js';
import { registerExplorerCommands } from './explorer-commands.js';
import { solutionLoader } from './solution-load.js';
import { type SolutionLoaderDeps, solutionLoader } from './solution-load.js';
import * as log from './log.js';
import { registerProfiler, type SharpLspProfiler } from './profiler-host.js';
import { SharpLspStatusBar, ServerState } from './status.js';
Expand Down Expand Up @@ -77,7 +77,7 @@ let targetFrameworks: TargetFrameworkUi | undefined;
let tutorial: TutorialApi | undefined;

/** Accessors the command modules use; the client and explorer appear during activation. */
const explorerDeps = {
const explorerDeps: { -readonly [K in keyof SolutionLoaderDeps]: SolutionLoaderDeps[K] } = {
client: (): LanguageClient | undefined => lspClient,
explorer: (): SolutionExplorerProvider | undefined => explorerProvider,
};
Expand All @@ -100,6 +100,7 @@ interface DeploymentResult {
// console where users do not see them — that is the failure mode this prevents.
export async function activate(context: ExtensionContext): Promise<SharpLspExtensionApi> {
log.info('SharpLsp activating…');
explorerDeps.memory = context.workspaceState;
log.info(`File log: ${log.logFilePath()}`);
try {
return await activateInner(context);
Expand Down Expand Up @@ -417,7 +418,7 @@ function registerCommands(context: ExtensionContext): void {
[CMD_SHOW_TRACE]: () => {
log.trace().show();
},
[CMD_SELECT_SOLUTION]: solutions.selectAndLoad,
[CMD_SELECT_SOLUTION]: solutions.pickAndLoad,
[CMD_OPEN_SOLUTION]: async (solutionPath: string) => {
await solutions.load({ path: solutionPath, name: '' });
},
Expand Down
46 changes: 43 additions & 3 deletions src/editors/vscode/src/solution-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* work from, and the debounced tree refresh that follows source or solution
* file changes. Implements [SE-SOLUTION] and [SE-LOADING-FEEDBACK].
*/
import { type ExtensionContext, window, workspace } from 'vscode';
import * as fs from 'node:fs';
import { type ExtensionContext, type Memento, window, workspace } from 'vscode';
import { type LanguageClient } from 'vscode-languageclient/node';
import { VIEW_SOLUTION_EXPLORER } from './constants.js';
import * as log from './log.js';
Expand All @@ -16,12 +17,16 @@ import { getErrorMessage } from './utils.js';
export interface SolutionLoaderDeps {
readonly client: () => LanguageClient | undefined;
readonly explorer: () => SolutionExplorerProvider | undefined;
/** Per-workspace storage that outlives a window reload; absent until activation. */
readonly memory?: Memento;
}

/** Solution selection and loading bound to one extension activation. */
export interface SolutionLoader {
/** Select a solution (auto or user-picked) and load it into the explorer. */
/** Reopen the remembered solution, else select one (auto or user-picked) and load it. */
readonly selectAndLoad: () => Promise<void>;
/** Always ask which solution to load: the user is switching on purpose. */
readonly pickAndLoad: () => Promise<void>;
/** Load a solution into the explorer tree AND the LSP sidecar. */
readonly load: (selected: solution.SolutionSelection) => Promise<void>;
/** Re-fetch workspace symbols when source or solution files change. */
Expand All @@ -31,6 +36,27 @@ export interface SolutionLoader {
const REFRESH_DEBOUNCE_MS = 1_000;
const RELEVANT_LANGUAGES = new Set(['csharp', 'fsharp']);
const SOLUTION_FILE_GLOB = '**/*.{sln,slnx}';
/** The workspace-storage key holding the solution last loaded in this workspace. */
const REMEMBERED_SOLUTION = 'sharplsp.solution';

/** The remembered solution while its file still exists; a deleted one is forgotten. */
function remembered(memory: Memento | undefined): solution.SolutionSelection | undefined {
const stored = memory?.get<string>(REMEMBERED_SOLUTION);
if (stored === undefined || !fs.existsSync(stored)) return undefined;
return solution.toSolutionSelections([stored])[0];
}

/** The configured solution; a server that cannot answer leaves the choice open. */
async function configured(
client: LanguageClient | undefined,
): Promise<solution.SolutionSelection | undefined> {
try {
return await solution.configuredSolution(client);
} catch (err: unknown) {
log.warn(`Configured solution not read: ${getErrorMessage(err)}`);
return undefined;
}
}

/** Build the loader; selection generations make a superseded pick a no-op. */
export function solutionLoader(deps: SolutionLoaderDeps): SolutionLoader {
Expand Down Expand Up @@ -61,12 +87,26 @@ export function solutionLoader(deps: SolutionLoaderDeps): SolutionLoader {
try {
await reloadSidecars(deps.client(), selected.path);
await deps.explorer()?.loadSolution(selected.path);
await deps.memory?.update(REMEMBERED_SOLUTION, selected.path);
} finally {
sharedState.endLoadPhase(phase);
}
};

// `csharp.solution_path` settles the choice, then what this workspace last
// loaded; only a workspace with neither is asked.
// [SHARPLSP-ARCHITECTURE-PROJECTS-SOLUTION-PATH]
const selectAndLoad = async (): Promise<void> => {
const known = (await configured(deps.client())) ?? remembered(deps.memory);
if (known === undefined) {
await pickAndLoad();
return;
}
log.info(`Opening the configured or remembered solution: ${known.path}`);
await load(known);
};

const pickAndLoad = async (): Promise<void> => {
const started = ++generation;
const initialSolution = sharedState.solutionPath.value;
// [SE-LOADING-FEEDBACK]: `window.withProgress` puts a native progress bar in
Expand Down Expand Up @@ -113,7 +153,7 @@ export function solutionLoader(deps: SolutionLoaderDeps): SolutionLoader {
log.traceInfo(`Solution file watcher active: ${SOLUTION_FILE_GLOB}`);
};

return { selectAndLoad, load, wireRefresh };
return { selectAndLoad, pickAndLoad, load, wireRefresh };
}

/** Scan the workspace; a failed scan must still clear the discovery phase. */
Expand Down
34 changes: 33 additions & 1 deletion src/editors/vscode/src/solution.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { fileNameOf } from './paths';
import * as fs from 'node:fs';
import { fileNameOf, isAbsolutePath, joinPath } from './paths';
import { CancellationTokenSource, workspace, window } from 'vscode';
import { type LanguageClient } from 'vscode-languageclient/node';
import * as log from './log.js';

/** Result of solution discovery. */
Expand All @@ -10,6 +12,36 @@ export interface SolutionSelection {
readonly name: string;
}

/** The part of the server's effective configuration that names the solution. */
interface SolutionConfiguration {
readonly csharp?: { readonly solution_path?: string };
}

/**
* The solution `csharp.solution_path` names (sharplsp.toml or an editor
* setting), when its file exists. The server already opened it, so the
* extension shows that one and never asks which of the workspace's solutions to
* load. A stale entry is no choice: the picker follows, as discovery follows on
* the server. Implements [SHARPLSP-ARCHITECTURE-PROJECTS-SOLUTION-PATH].
*/
export async function configuredSolution(
client: LanguageClient | undefined,
): Promise<SolutionSelection | undefined> {
// The server resolves a relative entry against ITS root: the client's folder.
const folder = client?.clientOptions.workspaceFolder ?? workspace.workspaceFolders?.[0];
const root = folder?.uri.fsPath;
if (client === undefined || root === undefined) return undefined;
const resolved = await client.sendRequest<SolutionConfiguration>('sharplsp/configuration', {});
const configured = resolved.csharp?.solution_path ?? '';
if (configured === '') return undefined;
const file = isAbsolutePath(configured) ? configured : joinPath(root, configured);
if (!fs.existsSync(file)) {
log.warn('csharp.solution_path names no existing file; asking which solution to load');
return undefined;
}
return toSolutionSelections([file])[0];
}

/** Discover .sln/.slnx files in the workspace and let the user pick if needed. */
export async function selectSolution(): Promise<SolutionSelection | undefined> {
const solutions = await findSolutions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import {
stopInTestSource,
useDebugTestFixture,
} from './debug-test-harness';
import { assertHandshakeOrder, type TestDebugFixture } from './debug-test-kit';
import {
assertHandshakeOrder,
assertNoTerminalLeft,
type TestDebugFixture,
} from './debug-test-kit';
import { TEST_DEBUG_TERMINAL_NAME } from '../../test-debug';
import { EXPECTO_ALL, EXPECTO_NESTED, EXPECTO_PASSING, EXPECTO_SOURCE } from './expecto-fixture';
import { DebugSessionRecorder } from './run-debug-kit';
import { deepEq, eq, neq } from './test-helpers';
Expand Down Expand Up @@ -96,5 +101,7 @@ suite('Debug an Expecto test — a breakpoint inside a testCase lambda', () => {
eq(sessions.ours.length, 1, 'yet a real session attached and ran it');
deepEq(stubs.log.errorMessages, [], 'and nothing was reported as an error');
assertSessionEnded(recorder, 'the nested Expecto case');
// Run to the END: the `dotnet test` run itself settles and closes its terminal.
await assertNoTerminalLeft(TEST_DEBUG_TERMINAL_NAME, 'the nested case run settled');
});
});
10 changes: 9 additions & 1 deletion src/editors/vscode/src/test/suite/debug-test-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { assertStopReason, topFrame, type Frame } from './debug-drive-kit';
import { assertBoundAtLines, useArmedRecorders } from './debug-suite-kit';
import {
assertHandshakeOrder,
assertNoTerminalLeft,
assertOneTestSession,
breakpointAt,
disposeDebugTestFixture,
Expand All @@ -32,6 +33,7 @@ import {
type FixtureRunner,
type TestDebugFixture,
} from './debug-test-kit';
import { TEST_DEBUG_TERMINAL_NAME } from '../../test-debug';
import { DebugSessionRecorder, type ObservedSession } from './run-debug-kit';
import {
activateTestExplorer,
Expand Down Expand Up @@ -71,7 +73,13 @@ export function useDebugTestFixture(

suiteTeardown(async function () {
this.timeout(FIXTURE_BUILD_MS);
await disposeDebugTestFixture(fixture);
try {
// A debug run outlives its session by the `dotnet test` wrap-up; deleting
// the project under it strands that run and its terminal in the NEXT suite.
await assertNoTerminalLeft(TEST_DEBUG_TERMINAL_NAME, 'every debug run settled first');
} finally {
await disposeDebugTestFixture(fixture);
}
});

return useArmedRecorders(() => ({ fixture }), 'debug-test');
Expand Down
Loading
Loading