Skip to content

Commit e027ca8

Browse files
authored
[automated] Merge branch 'main' => 'prerelease' (#8242)
2 parents e222f25 + 3377b3e commit e027ca8

32 files changed

+501
-114
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
- Diagnostics related feature requests and improvements [#5951](https://github.com/dotnet/vscode-csharp/issues/5951)
44
- Debug from .csproj and .sln [#5876](https://github.com/dotnet/vscode-csharp/issues/5876)
55

6+
# 2.76.x
7+
68
# 2.75.x
9+
* Bump Razor to 10.0.0-preview.25228.4 (PR: [#8225](https://github.com/dotnet/vscode-csharp/pull/8225))
10+
* Don't return null if we couldn't sync the document for breakpoint validation (PR: [#11790](https://github.com/dotnet/razor/pull/11790))
11+
* Add VS Code IMappingService (PR: [#11760](https://github.com/dotnet/razor/pull/11760))
12+
* Fix cases where there is a space in the URI (PR: [#11745](https://github.com/dotnet/razor/pull/11745))
713
* Bump Roslyn to 5.0.0-1.25224.9 (PR: [#8211](https://github.com/dotnet/vscode-csharp/pull/8211))
814
* Update ICSharpCode.Decompiler to 9.1.0.7988(PR: [#78270](https://github.com/dotnet/roslyn/pull/78270))
915
* Reduce allocations in NamespaceSymbol.GetExtensionContainers(PR: [#78243](https://github.com/dotnet/roslyn/pull/78243))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"defaults": {
4343
"roslyn": "5.0.0-1.25224.9",
4444
"omniSharp": "1.39.12",
45-
"razor": "10.0.0-preview.25251.2",
45+
"razor": "10.0.0-preview.25228.4",
4646
"razorOmnisharp": "7.0.0-preview.23363.1",
4747
"xamlTools": "17.14.36010.33"
4848
},

src/lsptoolshost/razor/htmlDocumentContentProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class HtmlDocumentContentProvider implements vscode.TextDocumentContentPr
2828
if (!document) {
2929
// Document was removed from the document manager, meaning there's no more content for this
3030
// file. Report an empty document.
31-
this.logger.logVerbose(
31+
this.logger.logTrace(
3232
`Could not find document '${getUriPath(
3333
uri
3434
)}' when updating the HTML buffer. This typically happens when a document is removed.`

src/lsptoolshost/razor/htmlDocumentManager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export class HtmlDocumentManager {
2727
const didCloseRegistration = vscode.workspace.onDidCloseTextDocument(async (document) => {
2828
// We log when a virtual document is closed just in case it helps track down future bugs
2929
if (document.uri.scheme === HtmlDocumentContentProvider.scheme) {
30-
this.logger.logVerbose(`Virtual document '${document.uri}' timed out.`);
30+
this.logger.logTrace(`Virtual document '${document.uri}' timed out.`);
3131
return;
3232
}
3333

3434
// When a Razor document is closed, only then can we be sure its okay to remove the virtual document.
3535
if (document.languageId === 'aspnetcorerazor') {
36-
this.logger.logVerbose(`Document '${document.uri}' was closed.`);
36+
this.logger.logTrace(`Document '${document.uri}' was closed.`);
3737

3838
await this.closeDocument(document.uri);
3939

@@ -52,7 +52,7 @@ export class HtmlDocumentManager {
5252
public async updateDocumentText(uri: vscode.Uri, text: string) {
5353
const document = await this.getDocument(uri);
5454

55-
this.logger.logVerbose(`New content for '${uri}', updating '${document.path}'.`);
55+
this.logger.logTrace(`New content for '${uri}', updating '${document.path}'.`);
5656

5757
document.setContent(text);
5858

@@ -63,7 +63,7 @@ export class HtmlDocumentManager {
6363
const document = await this.findDocument(uri);
6464

6565
if (document) {
66-
this.logger.logVerbose(`Removing '${document.uri}' from the document manager.`);
66+
this.logger.logTrace(`Removing '${document.uri}' from the document manager.`);
6767

6868
delete this.htmlDocuments[document.path];
6969
}
@@ -74,7 +74,7 @@ export class HtmlDocumentManager {
7474

7575
// This might happen in the case that a file is opened outside the workspace
7676
if (!document) {
77-
this.logger.logMessage(
77+
this.logger.logInfo(
7878
`File '${uri}' didn't exist in the Razor document list. This is likely because it's from outside the workspace.`
7979
);
8080
document = this.addDocument(uri);
@@ -88,7 +88,7 @@ export class HtmlDocumentManager {
8888
private addDocument(uri: vscode.Uri): HtmlDocument {
8989
let document = this.findDocument(uri);
9090
if (document) {
91-
this.logger.logMessage(`Skipping document creation for '${document.path}' because it already exists.`);
91+
this.logger.logInfo(`Skipping document creation for '${document.path}' because it already exists.`);
9292
return document;
9393
}
9494

src/lsptoolshost/razor/razorEndpoints.ts

Lines changed: 180 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,29 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { RoslynLanguageServer } from '../server/roslynLanguageServer';
76
import * as vscode from 'vscode';
7+
import { RoslynLanguageServer } from '../server/roslynLanguageServer';
88
import {
99
ColorInformation,
1010
ColorPresentationParams,
1111
ColorPresentationRequest,
12+
CompletionList,
13+
CompletionParams,
14+
CompletionRequest,
1215
DocumentColorParams,
1316
DocumentColorRequest,
17+
DocumentHighlight,
18+
DocumentHighlightKind,
19+
DocumentHighlightParams,
20+
DocumentHighlightRequest,
21+
FoldingRange,
22+
FoldingRangeParams,
23+
FoldingRangeRequest,
24+
Hover,
25+
HoverParams,
26+
HoverRequest,
1427
LogMessageParams,
28+
MarkupKind,
1529
NotificationType,
1630
RequestType,
1731
} from 'vscode-languageclient';
@@ -24,51 +38,150 @@ import { DocumentColorHandler } from '../../razor/src/documentColor/documentColo
2438
import { razorOptions } from '../../shared/options';
2539
import { ColorPresentationHandler } from '../../razor/src/colorPresentation/colorPresentationHandler';
2640
import { ColorPresentation } from 'vscode-html-languageservice';
41+
import { convertRangeToSerializable } from '../../razor/src/rpc/serializableRange';
42+
import { FoldingRangeHandler } from '../../razor/src/folding/foldingRangeHandler';
43+
import { CompletionHandler } from '../../razor/src/completion/completionHandler';
44+
import { DynamicFileInfoHandler } from '../../razor/src/dynamicFile/dynamicFileInfoHandler';
45+
import { ProvideDynamicFileParams } from '../../razor/src/dynamicFile/provideDynamicFileParams';
46+
import { ProvideDynamicFileResponse } from '../../razor/src/dynamicFile/provideDynamicFileResponse';
47+
import { RazorMapSpansParams } from '../../razor/src/mapping/razorMapSpansParams';
48+
import { RazorMapSpansResponse } from '../../razor/src/mapping/razorMapSpansResponse';
49+
import { MappingHandler } from '../../razor/src/mapping/mappingHandler';
50+
import { RazorMapTextChangesParams } from '../../razor/src/mapping/razorMapTextChangesParams';
51+
import { RazorMapTextChangesResponse } from '../../razor/src/mapping/razorMapTextChangesResponse';
2752

2853
export function registerRazorEndpoints(
2954
context: vscode.ExtensionContext,
30-
languageServer: RoslynLanguageServer,
55+
roslynLanguageServer: RoslynLanguageServer,
3156
razorLogger: RazorLogger,
3257
platformInfo: PlatformInformation
3358
) {
3459
const logNotificationType = new NotificationType<LogMessageParams>('razor/log');
35-
languageServer.registerOnNotificationWithParams(logNotificationType, (params) =>
60+
roslynLanguageServer.registerOnNotificationWithParams(logNotificationType, (params) =>
3661
razorLogger.log(params.message, params.type)
3762
);
3863

39-
if (!razorOptions.cohostingEnabled) {
40-
return;
64+
if (razorOptions.cohostingEnabled) {
65+
registerCohostingEndpoints();
66+
} else {
67+
registerNonCohostingEndpoints();
4168
}
4269

43-
const documentManager = new HtmlDocumentManager(platformInfo, razorLogger);
44-
context.subscriptions.push(documentManager.register());
70+
return;
4571

46-
registerRequestHandler<HtmlUpdateParameters, void>('razor/updateHtml', async (params) => {
47-
const uri = UriConverter.deserialize(params.textDocument.uri);
48-
await documentManager.updateDocumentText(uri, params.text);
49-
});
72+
//
73+
// Local Functions
74+
//
75+
function registerCohostingEndpoints() {
76+
const documentManager = new HtmlDocumentManager(platformInfo, razorLogger);
77+
context.subscriptions.push(documentManager.register());
5078

51-
registerRequestHandler<DocumentColorParams, ColorInformation[]>(DocumentColorRequest.method, async (params) => {
52-
const uri = UriConverter.deserialize(params.textDocument.uri);
53-
const document = await documentManager.getDocument(uri);
79+
registerRequestHandler<HtmlUpdateParameters, void>('razor/updateHtml', async (params) => {
80+
const uri = UriConverter.deserialize(params.textDocument.uri);
81+
await documentManager.updateDocumentText(uri, params.text);
82+
});
5483

55-
return await DocumentColorHandler.doDocumentColorRequest(document.uri);
56-
});
84+
registerRequestHandler<DocumentColorParams, ColorInformation[]>(DocumentColorRequest.method, async (params) => {
85+
const uri = UriConverter.deserialize(params.textDocument.uri);
86+
const document = await documentManager.getDocument(uri);
87+
88+
return await DocumentColorHandler.doDocumentColorRequest(document.uri);
89+
});
90+
91+
registerRequestHandler<ColorPresentationParams, ColorPresentation[]>(
92+
ColorPresentationRequest.method,
93+
async (params) => {
94+
const uri = UriConverter.deserialize(params.textDocument.uri);
95+
const document = await documentManager.getDocument(uri);
96+
97+
return await ColorPresentationHandler.doColorPresentationRequest(document.uri, params);
98+
}
99+
);
57100

58-
registerRequestHandler<ColorPresentationParams, ColorPresentation[]>(
59-
ColorPresentationRequest.method,
60-
async (params) => {
101+
registerRequestHandler<FoldingRangeParams, FoldingRange[]>(FoldingRangeRequest.method, async (params) => {
61102
const uri = UriConverter.deserialize(params.textDocument.uri);
62103
const document = await documentManager.getDocument(uri);
63104

64-
return await ColorPresentationHandler.doColorPresentationRequest(document.uri, params);
65-
}
66-
);
105+
const results = await vscode.commands.executeCommand<vscode.FoldingRange[]>(
106+
'vscode.executeFoldingRangeProvider',
107+
document.uri
108+
);
109+
110+
return FoldingRangeHandler.convertFoldingRanges(results, razorLogger);
111+
});
112+
113+
registerRequestHandler<HoverParams, Hover | undefined>(HoverRequest.method, async (params) => {
114+
const uri = UriConverter.deserialize(params.textDocument.uri);
115+
const document = await documentManager.getDocument(uri);
116+
117+
const results = await vscode.commands.executeCommand<vscode.Hover[]>(
118+
'vscode.executeHoverProvider',
119+
document.uri,
120+
params.position
121+
);
122+
const applicableHover = results.filter((item) => item.range)[0];
123+
124+
return rewriteHover(applicableHover);
125+
});
126+
127+
registerRequestHandler<DocumentHighlightParams, DocumentHighlight[]>(
128+
DocumentHighlightRequest.method,
129+
async (params) => {
130+
const uri = UriConverter.deserialize(params.textDocument.uri);
131+
const document = await documentManager.getDocument(uri);
132+
133+
const results = await vscode.commands.executeCommand<vscode.DocumentHighlight[]>(
134+
'vscode.executeDocumentHighlights',
135+
document.uri,
136+
params.position
137+
);
138+
139+
return rewriteHighlight(results);
140+
}
141+
);
142+
143+
registerRequestHandler<CompletionParams, CompletionList>(CompletionRequest.method, async (params) => {
144+
const uri = UriConverter.deserialize(params.textDocument.uri);
145+
const document = await documentManager.getDocument(uri);
146+
147+
return CompletionHandler.provideVscodeCompletions(
148+
document.uri,
149+
params.position,
150+
params.context?.triggerCharacter
151+
);
152+
});
153+
}
154+
155+
function registerNonCohostingEndpoints() {
156+
registerRequestHandler<ProvideDynamicFileParams, ProvideDynamicFileResponse>(
157+
'razor/provideDynamicFileInfo',
158+
async (params) =>
159+
vscode.commands.executeCommand(DynamicFileInfoHandler.provideDynamicFileInfoCommand, params)
160+
);
161+
162+
registerRequestHandler<ProvideDynamicFileParams, ProvideDynamicFileResponse>(
163+
'razor/removeDynamicFileInfo',
164+
async (params) =>
165+
vscode.commands.executeCommand(DynamicFileInfoHandler.provideDynamicFileInfoCommand, params)
166+
);
167+
registerRequestHandler<RazorMapSpansParams, RazorMapSpansResponse>('razor/mapSpans', async (params) => {
168+
return await vscode.commands.executeCommand<RazorMapSpansResponse>(MappingHandler.MapSpansCommand, params);
169+
});
170+
registerRequestHandler<RazorMapTextChangesParams, RazorMapTextChangesResponse>(
171+
'razor/mapTextChanges',
172+
async (params) => {
173+
return await vscode.commands.executeCommand<RazorMapTextChangesResponse>(
174+
MappingHandler.MapChangesCommand,
175+
params
176+
);
177+
}
178+
);
179+
}
67180

68181
// Helper method that registers a request handler, and logs errors to the Razor logger.
69182
function registerRequestHandler<Params, Result>(method: string, invocation: (params: Params) => Promise<Result>) {
70183
const requestType = new RequestType<Params, Result, Error>(method);
71-
languageServer.registerOnRequest(requestType, async (params) => {
184+
roslynLanguageServer.registerOnRequest(requestType, async (params) => {
72185
try {
73186
return await invocation(params);
74187
} catch (error) {
@@ -78,3 +191,47 @@ export function registerRazorEndpoints(
78191
});
79192
}
80193
}
194+
195+
function rewriteHover(hover: vscode.Hover): Hover | undefined {
196+
if (!hover) {
197+
return undefined;
198+
}
199+
200+
const markdownString = new vscode.MarkdownString();
201+
for (const content of hover.contents) {
202+
if ((content as { language: string; value: string }).language) {
203+
const contentObject = content as { language: string; value: string };
204+
markdownString.appendCodeblock(contentObject.value, contentObject.language);
205+
} else {
206+
const contentValue = (content as vscode.MarkdownString).value;
207+
markdownString.appendMarkdown(contentValue);
208+
}
209+
}
210+
211+
return {
212+
contents: { kind: MarkupKind.Markdown, value: markdownString.value },
213+
range: hover.range ? convertRangeToSerializable(hover.range) : undefined,
214+
};
215+
}
216+
217+
function rewriteHighlight(highlights: vscode.DocumentHighlight[]): DocumentHighlight[] {
218+
return highlights.map((highlight) => {
219+
return {
220+
range: convertRangeToSerializable(highlight.range),
221+
kind: convertHighlightKind(highlight.kind),
222+
};
223+
});
224+
}
225+
226+
function convertHighlightKind(kind: vscode.DocumentHighlightKind | undefined): DocumentHighlightKind | undefined {
227+
switch (kind) {
228+
case vscode.DocumentHighlightKind.Text:
229+
return DocumentHighlightKind.Text;
230+
case vscode.DocumentHighlightKind.Read:
231+
return DocumentHighlightKind.Read;
232+
case vscode.DocumentHighlightKind.Write:
233+
return DocumentHighlightKind.Write;
234+
default:
235+
return undefined;
236+
}
237+
}

src/lsptoolshost/workspace/miscellaneousFileNotifier.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export function registerMiscellaneousFileNotifier(
2020
languageServer._projectContextService.onActiveFileContextChanged((e) => {
2121
// Only warn for C# miscellaneous files when the workspace is fully initialized.
2222
if (
23+
e.uri.scheme !== 'file' ||
2324
e.languageId !== 'csharp' ||
2425
!e.isVerified ||
2526
!e.context._vs_is_miscellaneous ||

src/razor/src/blazorDebug/terminateDebugHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const killProcess = (targetPid: number | undefined, logger: RazorLogger) => {
2121
}
2222

2323
try {
24-
logger.logVerbose(`[DEBUGGER] Terminating debugging session with PID ${targetPid}...`);
24+
logger.logTrace(`[DEBUGGER] Terminating debugging session with PID ${targetPid}...`);
2525
process.kill(targetPid);
2626
} catch (error) {
2727
logger.logError(`[DEBUGGER] Error terminating debug processes with PID ${targetPid}: `, error as Error);

src/razor/src/completion/completionHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class CompletionHandler {
137137
}
138138

139139
// HTML completion - provided via vscode command
140-
return this.provideVscodeCompletions(
140+
return CompletionHandler.provideVscodeCompletions(
141141
virtualDocument.uri,
142142
delegatedCompletionParams.projectedPosition,
143143
modifiedTriggerCharacter
@@ -372,7 +372,7 @@ export class CompletionHandler {
372372

373373
// Provide completions using standard vscode executeCompletionItemProvider command
374374
// Used in HTML context
375-
private async provideVscodeCompletions(
375+
public static async provideVscodeCompletions(
376376
virtualDocumentUri: vscode.Uri,
377377
projectedPosition: Position,
378378
triggerCharacter: string | undefined

src/razor/src/csharp/csharpProjectedDocumentContentProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export class CSharpProjectedDocumentContentProvider implements vscode.TextDocume
3535
// Document was removed from the document manager, meaning there's no more content for this
3636
// file. Report an empty document.
3737

38-
if (this.logger.verboseEnabled) {
39-
this.logger.logVerbose(
38+
if (this.logger.traceEnabled) {
39+
this.logger.logTrace(
4040
`Could not find document '${getUriPath(
4141
uri
4242
)}' when updating the C# buffer. This typically happens when a document is removed.`

0 commit comments

Comments
 (0)