diff --git a/CHANGELOG.md b/CHANGELOG.md index f89f3ec6f..7afcebdf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ - Debug from .csproj and .sln [#5876](https://github.com/dotnet/vscode-csharp/issues/5876) # Latest +* Update Roslyn to 4.13.0-1.24503.11 (PR: [#7618](https://github.com/dotnet/vscode-csharp/pull/7618)) + * LSP hover responses escape backticks within inline code (PR: [#75364](https://github.com/dotnet/roslyn/pull/75364)) + * Localize build host message output (PR: [#74910](https://github.com/dotnet/roslyn/pull/74910)) + * Log and report NFW when we fail to apply project system update (PR: [#75362](https://github.com/dotnet/roslyn/pull/75362)) + * Reduce allocations and UI thread CPU costs in WithDoNotCreateCreationPolicy (PR: [#75358](https://github.com/dotnet/roslyn/pull/75358)) + * Enable support for an LSP client to open source generated files (PR: [#75180](https://github.com/dotnet/roslyn/pull/75180)) + * Improve error reporting when reading bad metadata during EnC (PR: [#75304](https://github.com/dotnet/roslyn/pull/75304)) * Suppress recoverable errors from razor LSP (PR: [#7624](https://github.com/dotnet/vscode-csharp/pull/7624)) * NOTE: this can be re-enabled by setting `razor.languageServer.suppressLspErrorToasts = false` * Update Roslyn to 4.13.0-1.24501.3 (PR: [#7618](https://github.com/dotnet/vscode-csharp/pull/7618)) diff --git a/package.json b/package.json index 1f4ba076b..3ebf0521a 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ } }, "defaults": { - "roslyn": "4.13.0-1.24501.3", + "roslyn": "4.13.0-1.24503.11", "omniSharp": "1.39.11", "razor": "9.0.0-preview.24480.1", "razorOmnisharp": "7.0.0-preview.23363.1", diff --git a/src/lsptoolshost/roslynLanguageServer.ts b/src/lsptoolshost/roslynLanguageServer.ts index 023608c54..83f11799b 100644 --- a/src/lsptoolshost/roslynLanguageServer.ts +++ b/src/lsptoolshost/roslynLanguageServer.ts @@ -74,6 +74,7 @@ import { showErrorMessage, showInformationMessage, } from '../shared/observers/utils/showMessage'; +import { registerSourceGeneratedFilesContentProvider } from './sourceGeneratedFilesContentProvider'; let _channel: vscode.OutputChannel; let _traceChannel: vscode.OutputChannel; @@ -1068,6 +1069,8 @@ export async function activateRoslynLanguageServer( registerRestoreCommands(context, languageServer, dotnetChannel); + registerSourceGeneratedFilesContentProvider(context, languageServer); + context.subscriptions.push(registerLanguageServerOptionChanges(optionObservable)); return languageServer; diff --git a/src/lsptoolshost/roslynProtocol.ts b/src/lsptoolshost/roslynProtocol.ts index 9c612502b..9ba43d4af 100644 --- a/src/lsptoolshost/roslynProtocol.ts +++ b/src/lsptoolshost/roslynProtocol.ts @@ -230,6 +230,14 @@ export interface CopilotRelatedDocumentsReport { _vs_file_paths?: string[]; } +export interface SourceGeneratorGetRequestParams { + textDocument: lsp.TextDocumentIdentifier; +} + +export interface SourceGeneratedDocumentText { + text: string; +} + export namespace WorkspaceDebugConfigurationRequest { export const method = 'workspace/debugConfiguration'; export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer; @@ -351,3 +359,9 @@ export namespace CopilotRelatedDocumentsRequest { void >(method); } + +export namespace SourceGeneratorGetTextRequest { + export const method = 'sourceGeneratedDocument/_roslyn_getText'; + export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer; + export const type = new lsp.RequestType(method); +} diff --git a/src/lsptoolshost/sourceGeneratedFilesContentProvider.ts b/src/lsptoolshost/sourceGeneratedFilesContentProvider.ts new file mode 100644 index 000000000..6d070b590 --- /dev/null +++ b/src/lsptoolshost/sourceGeneratedFilesContentProvider.ts @@ -0,0 +1,31 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as vscode from 'vscode'; +import * as RoslynProtocol from './roslynProtocol'; +import { RoslynLanguageServer } from './roslynLanguageServer'; +import { UriConverter } from './uriConverter'; +import * as lsp from 'vscode-languageserver-protocol'; + +export function registerSourceGeneratedFilesContentProvider( + context: vscode.ExtensionContext, + languageServer: RoslynLanguageServer +) { + context.subscriptions.push( + vscode.workspace.registerTextDocumentContentProvider( + 'roslyn-source-generated', + new (class implements vscode.TextDocumentContentProvider { + async provideTextDocumentContent(uri: vscode.Uri, token: vscode.CancellationToken): Promise { + const result = await languageServer.sendRequest( + RoslynProtocol.SourceGeneratorGetTextRequest.type, + { textDocument: lsp.TextDocumentIdentifier.create(UriConverter.serialize(uri)) }, + token + ); + return result.text; + } + })() + ) + ); +}