Skip to content

Commit e342e51

Browse files
author
Andrew Hall
authored
Add .razorExtension (#8096)
Depends on the following PRs: dotnet/razor#11510 dotnet/roslyn#77715
2 parents 656334a + 56b6465 commit e342e51

File tree

11 files changed

+55
-24
lines changed

11 files changed

+55
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ out
1313
.razoromnisharp/
1414
.razortelemetry/
1515
.razorDevKit/
16+
.razorExtension/
1617
.vscode-test/
1718
msbuild/signing/signJs/*.log
1819
msbuild/signing/signVsix/*.log

.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
!.razor/**
88
!.razorDevKit/**
99
!.razoromnisharp/**
10+
!.razorExtension/**
1011
.rpt2_cache/**
1112
.config/**
1213
.devcontainer/**

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
}
3838
},
3939
"defaults": {
40-
"roslyn": "4.14.0-3.25164.3",
40+
"roslyn": "4.14.0-3.25175.12",
4141
"omniSharp": "1.39.12",
42-
"razor": "9.0.0-preview.25161.2",
42+
"razor": "9.0.0-preview.25177.4",
4343
"razorOmnisharp": "7.0.0-preview.23363.1",
4444
"xamlTools": "17.14.35927.264"
4545
},

src/lsptoolshost/extensions/builtInComponents.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export const componentInfo: { [key: string]: ComponentInfo } = {
3232
optionName: 'razorDevKit',
3333
componentDllPaths: ['Microsoft.VisualStudio.DevKit.Razor.dll'],
3434
},
35+
razorExtension: {
36+
defaultFolderName: '.razorExtension',
37+
optionName: 'razorExtension',
38+
componentDllPaths: ['Microsoft.VisualStudioCode.RazorExtension.dll'],
39+
},
3540
};
3641

3742
export function getComponentPaths(componentName: string, options: LanguageServerOptions | undefined): string[] {

src/lsptoolshost/server/roslynLanguageServer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,10 @@ export class RoslynLanguageServer {
619619
path.join(razorPath, 'Targets', 'Microsoft.NET.Sdk.Razor.DesignTime.targets')
620620
);
621621

622+
getComponentPaths('razorExtension', languageServerOptions).forEach((path) =>
623+
additionalExtensionPaths.push(path)
624+
);
625+
622626
// Get the brokered service pipe name from C# Dev Kit (if installed).
623627
// We explicitly call this in the LSP server start action instead of awaiting it
624628
// in our activation because C# Dev Kit depends on C# activation completing.
@@ -966,6 +970,7 @@ export class RoslynLanguageServer {
966970
additionalExtensionPaths.push(path)
967971
);
968972
}
973+
969974
return args;
970975
}
971976

src/razor/src/dynamicFile/dynamicFileInfoHandler.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import { UriConverter } from '../../../lsptoolshost/utils/uriConverter';
88
import { RazorDocumentManager } from '../document/razorDocumentManager';
99
import { RazorLogger } from '../razorLogger';
1010
import { ProvideDynamicFileParams } from './provideDynamicFileParams';
11-
import { ProvideDynamicFileResponse, DynamicFileUpdate } from './provideDynamicFileResponse';
11+
import { ProvideDynamicFileResponse } from './provideDynamicFileResponse';
1212
import { RemoveDynamicFileParams } from './removeDynamicFileParams';
1313
import { CSharpProjectedDocument } from '../csharp/csharpProjectedDocument';
1414
import { RazorDocumentChangeKind } from '../document/razorDocumentChangeKind';
1515
import { RazorDynamicFileChangedParams } from './dynamicFileUpdatedParams';
1616
import { TextDocumentIdentifier } from 'vscode-languageserver-protocol';
17-
import { ServerTextChange } from '../rpc/serverTextChange';
17+
import { razorTextChange } from './razorTextChange';
18+
import { razorTextSpan } from './razorTextSpan';
1819

1920
// Handles Razor generated doc communication between the Roslyn workspace and Razor.
2021
// didChange behavior for Razor generated docs is handled in the RazorDocumentManager.
@@ -75,19 +76,11 @@ export class DynamicFileInfoHandler {
7576
if (request.fullText) {
7677
// The server asked for a full replace so the newtext is the important
7778
// thing here, the span doesn't matter.
78-
const change: ServerTextChange = {
79-
newText: razorDocument.csharpDocument.getContent(),
80-
span: {
81-
start: 0,
82-
length: 0,
83-
},
84-
};
85-
86-
const update = new DynamicFileUpdate([change]);
79+
const change = new razorTextChange(razorDocument.csharpDocument.getContent(), new razorTextSpan(0, 0));
8780

8881
return new ProvideDynamicFileResponse(
8982
request.razorDocument,
90-
[update],
83+
[change],
9184
csharpDocument.checksum,
9285
csharpDocument.checksumAlgorithm,
9386
csharpDocument.encodingCodePage
@@ -99,22 +92,18 @@ export class DynamicFileInfoHandler {
9992
if (this.documentManager.isRazorDocumentOpenInCSharpWorkspace(vscodeUri)) {
10093
// Open documents have didOpen/didChange to update the csharp buffer. Razor
10194
// does not send edits and instead lets vscode handle them.
102-
return new ProvideDynamicFileResponse(
103-
{ uri: virtualCsharpUri },
104-
null,
105-
csharpDocument.checksum,
106-
csharpDocument.checksumAlgorithm,
107-
csharpDocument.encodingCodePage
108-
);
95+
return null;
10996
} else {
11097
// Closed documents provide edits since the last time they were requested since
11198
// there is no open buffer in vscode corresponding to the csharp content.
11299
const response = csharpDocument.applyEdits();
113-
const updates = response.edits?.map((e) => new DynamicFileUpdate(e.changes)) ?? null;
100+
const updates = response.edits?.flatMap((e) =>
101+
e.changes.map((c) => new razorTextChange(c.newText, new razorTextSpan(c.span.start, c.span.length)))
102+
);
114103

115104
return new ProvideDynamicFileResponse(
116105
{ uri: virtualCsharpUri },
117-
updates,
106+
updates ?? [],
118107
response.originalChecksum,
119108
response.originalChecksumAlgorithm,
120109
response.originalEncodingCodePage

src/razor/src/dynamicFile/provideDynamicFileResponse.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
import { TextDocumentIdentifier } from 'vscode-languageserver-protocol';
77
import { ServerTextChange } from '../rpc/serverTextChange';
8+
import { razorTextChange } from './razorTextChange';
89

910
// matches https://github.com/dotnet/roslyn/blob/9e91ca6590450e66e0041ee3135bbf044ac0687a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/RazorDynamicFileInfoProvider.cs#L28
1011
export class ProvideDynamicFileResponse {
1112
constructor(
1213
public readonly csharpDocument: TextDocumentIdentifier | null,
13-
public readonly updates: DynamicFileUpdate[] | null,
14+
public readonly edits: razorTextChange[],
1415
public readonly checksum: string,
1516
public readonly checksumAlgorithm: number,
1617
public readonly encodingCodePage: number | null
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { razorTextSpan } from './razorTextSpan';
7+
8+
export class razorTextChange {
9+
constructor(public readonly newText: string | null, public readonly span: razorTextSpan) {}
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
export class razorTextSpan {
7+
constructor(public readonly start: number, public readonly length: number) {}
8+
}

tasks/offlinePackagingTasks.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
xamlToolsDirectory,
2828
razorLanguageServerDirectory,
2929
razorDevKitDirectory,
30+
razorExtensionDirectory,
3031
} from '../tasks/projectPaths';
3132
import { getPackageJSON } from '../tasks/packageJson';
3233
import { createPackageAsync, generateVsixManifest } from '../tasks/vsceTasks';
@@ -98,6 +99,12 @@ export const allNugetPackages: { [key: string]: NugetPackageInfo } = {
9899
getPackageContentPath: (_platformInfo) => 'content',
99100
vsixOutputPath: razorDevKitDirectory,
100101
},
102+
razorExtension: {
103+
getPackageName: (_platformInfo) => 'Microsoft.VisualStudioCode.RazorExtension',
104+
packageJsonName: 'razor',
105+
getPackageContentPath: (_platformInfo) => 'content',
106+
vsixOutputPath: razorExtensionDirectory,
107+
},
101108
};
102109

103110
const vsixTasks: string[] = [];
@@ -185,6 +192,9 @@ gulp.task(
185192

186193
// Also pull in the Razor DevKit dependencies nuget package.
187194
await acquireNugetPackage(allNugetPackages.razorDevKit, undefined, getPackageJSON(), true);
195+
196+
// Pull in the .razorExtension code that gets loaded in the roslyn language server
197+
await acquireNugetPackage(allNugetPackages.razorExtension, undefined, getPackageJSON(), true);
188198
}, 'installDependencies')
189199
);
190200

0 commit comments

Comments
 (0)