Skip to content

Commit 29425b0

Browse files
authored
Merge pull request #7442 from ryzngard/fix_utf_handling
Fix handling files with non-Ascii characters by sending a TextDocumentIdentifier for dynamic file requests/responses
2 parents 3e516d7 + b7dd2ff commit 29425b0

File tree

9 files changed

+50
-36
lines changed

9 files changed

+50
-36
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
- Debug from .csproj and .sln [#5876](https://github.com/dotnet/vscode-csharp/issues/5876)
55

66
# Latest
7-
* Bump Roslyn to 4.12.0-2.24408.4 (PR: [#7429](https://github.com/dotnet/vscode-csharp/pull/7429))
7+
* Fix handling Razor files with non-ascii characters (PR: [#7442](https://github.com/dotnet/vscode-csharp/pull/7442))
8+
* Bump Roslyn to 4.12.0-2.24413.5 (PR: [#7442](https://github.com/dotnet/vscode-csharp/pull/7442))
9+
* Fix URI comparisons for different casing (PR: [#74746](https://github.com/dotnet/roslyn/pull/74746))
10+
* Remove implicit unsafe cast in foreach(PR: [#74747](https://github.com/dotnet/roslyn/pull/74747))
11+
* Send a TextDocumentidentifier for razor dynamic file requests/responses (PR: [#74727](https://github.com/dotnet/roslyn/pull/74727))
12+
* Fix issues with VSCode LSP EA causing handlers to fail to load (PR: [#74700](https://github.com/dotnet/roslyn/pull/74700))
813
* Reduce allocations in SyntaxEquivalence.AreEquivalent by using a more appropriate pooling mechanism for the stack it uses to walk trees. (PR: [#74610](https://github.com/dotnet/roslyn/pull/74610))
914
* Reduce allocations in SyntaxNodeExtensions.GetMembers to instead execute a given lambda over the collection. (PR: [#74628](https://github.com/dotnet/roslyn/pull/74628))
1015
* Modify ISyntaxFacts methods to allocate less (PR: [#74596](https://github.com/dotnet/roslyn/pull/74596))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
}
3838
},
3939
"defaults": {
40-
"roslyn": "4.12.0-2.24408.4",
40+
"roslyn": "4.12.0-2.24413.5",
4141
"omniSharp": "1.39.11",
4242
"razor": "9.0.0-preview.24366.2",
4343
"razorOmnisharp": "7.0.0-preview.23363.1",

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ import { getComponentPaths } from './builtInComponents';
6666
import { OnAutoInsertFeature } from './onAutoInsertFeature';
6767
import { registerLanguageStatusItems } from './languageStatusBar';
6868
import { ProjectContextService } from './services/projectContextService';
69+
import { ProvideDynamicFileResponse } from '../razor/src/dynamicFile/provideDynamicFileResponse';
70+
import { ProvideDynamicFileParams } from '../razor/src/dynamicFile/provideDynamicFileParams';
6971

7072
let _channel: vscode.OutputChannel;
7173
let _traceChannel: vscode.OutputChannel;
@@ -730,11 +732,16 @@ export class RoslynLanguageServer {
730732
};
731733
}
732734

735+
private ProvideDyanmicFileInfoType: RequestType<ProvideDynamicFileParams, ProvideDynamicFileResponse, any> =
736+
new RequestType(RoslynLanguageServer.provideRazorDynamicFileInfoMethodName);
737+
733738
private registerDynamicFileInfo() {
734739
// When the Roslyn language server sends a request for Razor dynamic file info, we forward that request along to Razor via
735740
// a command.
736-
this._languageClient.onRequest(RoslynLanguageServer.provideRazorDynamicFileInfoMethodName, async (request) =>
737-
vscode.commands.executeCommand(DynamicFileInfoHandler.provideDynamicFileInfoCommand, request)
741+
this._languageClient.onRequest<ProvideDynamicFileParams, ProvideDynamicFileResponse, any>(
742+
this.ProvideDyanmicFileInfoType,
743+
async (request) =>
744+
vscode.commands.executeCommand(DynamicFileInfoHandler.provideDynamicFileInfoCommand, request)
738745
);
739746
this._languageClient.onNotification(
740747
RoslynLanguageServer.removeRazorDynamicFileInfoMethodName,

src/lsptoolshost/services/projectContextService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ export class ProjectContextService {
8585
private async getVirtualCSharpUri(uri: vscode.Uri): Promise<vscode.Uri | undefined> {
8686
const response = await vscode.commands.executeCommand<ProvideDynamicFileResponse>(
8787
DynamicFileInfoHandler.provideDynamicFileInfoCommand,
88-
new ProvideDynamicFileParams([uri.fsPath])
88+
new ProvideDynamicFileParams({ uri: UriConverter.serialize(uri) })
8989
);
9090

91-
const responseUri = response.generatedFiles[0];
91+
const responseUri = response.csharpDocument?.uri;
9292
if (!responseUri) {
9393
return undefined;
9494
}

src/lsptoolshost/uriConverter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ export class UriConverter {
2424
}
2525

2626
public static deserialize(value: string): vscode.Uri {
27-
return vscode.Uri.parse(value);
27+
return vscode.Uri.parse(value, true);
2828
}
2929
}

src/razor/src/dynamicFile/dynamicFileInfoHandler.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,21 @@ export class DynamicFileInfoHandler {
3636
}
3737

3838
// Given Razor document URIs, returns associated generated doc URIs
39-
private async provideDynamicFileInfo(request: ProvideDynamicFileParams): Promise<ProvideDynamicFileResponse> {
40-
const uris = request.razorFiles;
41-
const virtualUris = new Array<DocumentUri | null>();
39+
private async provideDynamicFileInfo(
40+
request: ProvideDynamicFileParams
41+
): Promise<ProvideDynamicFileResponse | null> {
42+
let virtualUri: DocumentUri | null = null;
4243
try {
43-
for (const razorDocumentPath of uris) {
44-
const vscodeUri = vscode.Uri.file(razorDocumentPath);
45-
const razorDocument = await this.documentManager.getDocument(vscodeUri);
46-
if (razorDocument === undefined) {
47-
virtualUris.push(null);
48-
this.logger.logWarning(
49-
`Could not find Razor document ${razorDocumentPath}; adding null as a placeholder in URI array.`
50-
);
51-
} else {
52-
// Retrieve generated doc URIs for each Razor URI we are given
53-
const virtualCsharpUri = UriConverter.serialize(razorDocument.csharpDocument.uri);
54-
virtualUris.push(virtualCsharpUri);
55-
}
44+
const vscodeUri = vscode.Uri.parse(request.razorDocument.uri, true);
45+
const razorDocument = await this.documentManager.getDocument(vscodeUri);
46+
if (razorDocument === undefined) {
47+
this.logger.logWarning(
48+
`Could not find Razor document ${vscodeUri.fsPath}; adding null as a placeholder in URI array.`
49+
);
50+
} else {
51+
// Retrieve generated doc URIs for each Razor URI we are given
52+
const virtualCsharpUri = UriConverter.serialize(razorDocument.csharpDocument.uri);
53+
virtualUri = virtualCsharpUri;
5654
}
5755

5856
this.documentManager.roslynActivated = true;
@@ -64,17 +62,18 @@ export class DynamicFileInfoHandler {
6462
this.logger.logWarning(`${DynamicFileInfoHandler.provideDynamicFileInfoCommand} failed with ${error}`);
6563
}
6664

67-
return new ProvideDynamicFileResponse(virtualUris);
65+
if (virtualUri) {
66+
return new ProvideDynamicFileResponse({ uri: virtualUri });
67+
}
68+
69+
return null;
6870
}
6971

7072
private async removeDynamicFileInfo(request: RemoveDynamicFileParams) {
7173
try {
72-
const uris = request.razorFiles;
73-
for (const razorDocumentPath of uris) {
74-
const vscodeUri = vscode.Uri.file(razorDocumentPath);
75-
if (this.documentManager.isRazorDocumentOpenInCSharpWorkspace(vscodeUri)) {
76-
this.documentManager.didCloseRazorCSharpDocument(vscodeUri);
77-
}
74+
const vscodeUri = UriConverter.deserialize(request.csharpDocument.uri);
75+
if (this.documentManager.isRazorDocumentOpenInCSharpWorkspace(vscodeUri)) {
76+
this.documentManager.didCloseRazorCSharpDocument(vscodeUri);
7877
}
7978
} catch (error) {
8079
this.logger.logWarning(`${DynamicFileInfoHandler.removeDynamicFileInfoCommand} failed with ${error}`);

src/razor/src/dynamicFile/provideDynamicFileParams.ts

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

6-
import { DocumentUri } from 'vscode-languageclient/node';
6+
import { TextDocumentIdentifier } from 'vscode-languageserver-protocol';
77

8+
// matches https://github.com/dotnet/roslyn/blob/9e91ca6590450e66e0041ee3135bbf044ac0687a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/RazorDynamicFileInfoProvider.cs#L22
89
export class ProvideDynamicFileParams {
9-
constructor(public readonly razorFiles: DocumentUri[]) {}
10+
constructor(public readonly razorDocument: TextDocumentIdentifier) {}
1011
}

src/razor/src/dynamicFile/provideDynamicFileResponse.ts

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

6-
import { DocumentUri } from 'vscode-languageclient/node';
6+
import { TextDocumentIdentifier } from 'vscode-languageclient/node';
77

8+
// matches https://github.com/dotnet/roslyn/blob/9e91ca6590450e66e0041ee3135bbf044ac0687a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/RazorDynamicFileInfoProvider.cs#L28
89
export class ProvideDynamicFileResponse {
9-
constructor(public readonly generatedFiles: (DocumentUri | null)[]) {}
10+
constructor(public readonly csharpDocument: TextDocumentIdentifier | null) {}
1011
}

src/razor/src/dynamicFile/removeDynamicFileParams.ts

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

6-
import { DocumentUri } from 'vscode-languageclient/node';
6+
import { TextDocumentIdentifier } from 'vscode-languageclient/node';
77

8+
// matches https://github.com/dotnet/roslyn/blob/9e91ca6590450e66e0041ee3135bbf044ac0687a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/RazorDynamicFileInfoProvider.cs#L28
89
export class RemoveDynamicFileParams {
9-
constructor(public readonly razorFiles: DocumentUri[]) {}
10+
constructor(public readonly csharpDocument: TextDocumentIdentifier) {}
1011
}

0 commit comments

Comments
 (0)