Skip to content

Commit

Permalink
Update VSCode
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbrandenburg committed May 19, 2020
1 parent bf19395 commit 4f7a155
Show file tree
Hide file tree
Showing 20 changed files with 314 additions and 338 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public static class LanguageServerConstants

public const string CursorPlaceholderString = "__placeholder__";

public const string RazorSemanticTokensEndpoint = "razor/semanticTokens";
public const string RazorSemanticTokensEndpoint = "_ms_/textDocument/semanticTokens";

public const string RazorSemanticTokenLegendEndpoint = "razor/semanticTokensLegend";
public const string RazorSemanticTokenLegendEndpoint = "_ms_/textDocument/semanticTokensLegend";

public const string RazorRangeFormattingEndpoint = "razor/rangeFormatting";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal interface ISemanticTokenHandler :
IJsonRpcRequestHandler<SemanticTokenParams, SemanticTokens>,
IRequestHandler<SemanticTokenParams, SemanticTokens>,
IJsonRpcHandler,
ICapability<SemanticTokenCapability>
ICapability<SemanticTokensCapability>
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic
{
internal class RazorSemanticTokenEndpoint : ISemanticTokenHandler
{
private SemanticTokenCapability _capability;
private SemanticTokensCapability _capability;
private readonly ILogger _logger;
private readonly ForegroundDispatcher _foregroundDispatcher;
private readonly DocumentResolver _documentResolver;
Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task<SemanticTokens> Handle(SemanticTokenParams request, Cancellati
return tokens;
}

public void SetCapability(SemanticTokenCapability capability)
public void SetCapability(SemanticTokensCapability capability)
{
_capability = capability;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic
{
public class SemanticTokenCapability : DynamicCapability
public class SemanticTokensCapability : DynamicCapability
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"enableProposedApi": true,
"publisher": "ms-dotnettools",
"engines": {
"vscode": "^1.31.0"
"vscode": "^1.45.1"
},
"categories": [
"Other"
Expand Down Expand Up @@ -116,77 +116,26 @@
"description": "A Razor TagHelper Attribute"
},
{
"id": "razorTagHelperTransition",
"description": "A Razor TagHelper transition"
"id": "razorTransition",
"description": "A Razor transition"
},
{
"id": "razorTagHelperColon",
"id": "razorDirectiveAttribute",
"description": "A Razor Directive Attribute"
},
{
"id": "razorDirectiveColon",
"description": "A colon between directive attribute parameters"
}
],
"semanticTokenStyleDefaults": [
{
"selector": "razorTagHelperElement",
"scope": [ "razor.taghelpers.element" ],
"light": {
"foreground": "#800080",
"fontStyle": "bold"
},
"dark": {
"foreground": "#009696",
"fontStyle": "bold"
}
},
"semanticTokenScopes": [
{
"selector": "razorTagHelperAttribute",
"scope": [ "razor.taghelpers.attribute" ],
"light": {
"foreground": "#800080",
"fontStyle": "bold"
},
"dark": {
"foreground": "#009696",
"fontStyle": "bold"
}
},
{
"selector": "razorTagHelperColon",
"scope": [ "razor.taghelper.colon"],
"light": {
"foreground": "#C586C0"
},
"dark": {
"foreground": "#C586C0"
}
},
{
"selector": "razorTransition",
"scope": [ "razor.transition"],
"light": {
"foreground": "#C586C0"
},
"dark": {
"foreground": "#C586C0"
}
},
{
"selector": "razorDirectiveAttribute",
"scope": [ "razor.directive.attribute"],
"light": {
"foreground": "#C586C0"
},
"dark": {
"foreground": "#C586C0"
}
},
{
"selector": "razorDirectiveAttributeParameter",
"scope": [ "razor.directive.parameter"],
"light": {
"foreground": "#C586C0"
},
"dark": {
"foreground": "#C586C0"
"scopes": {
"razorTagHelperElement": [ "entity.name.class.element.taghelper" ],
"razorTagHelperAttribute": [ "entity.name.class.attribute.taghelper" ],
"razorTransition": [ "keyword.control.razor.transition" ],
"razorDirectiveAttribute": [ "keyword.control.razor.directive.attribute", "keyword.control.cshtml.directive.attribute" ],
"razorDirectiveColon": [ "keyword.control.razor.directive.colon", "keyword.control.cshtml.directive.colon" ]
}
}
],
Expand Down Expand Up @@ -302,7 +251,7 @@
},
"devDependencies": {
"@types/node": "9.4.7",
"@types/vscode": "1.31.0",
"@types/vscode": "1.45.1",
"cross-env": "^5.2.0",
"js-yaml": ">=3.13.1",
"rimraf": "2.6.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.7.tgz#57d81cd98719df2c9de118f2d5f3b1120dcd7275"
integrity sha512-4Ba90mWNx8ddbafuyGGwjkZMigi+AWfYLSDCpovwsE63ia8w93r3oJ8PIAQc3y8U+XHcnMOHPIzNe3o438Ywcw==

"@types/vscode@1.31.0":
version "1.31.0"
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.31.0.tgz#6238228482f8cae4973e50091153e3125f067044"
integrity sha512-uUpjvtrQ14ZEqqRE/EGuBvGbm9GuxDp76mtsnw3goMogsWmEEYS/y4eL2Zwf0rbFMh/hg3hEs+E3CvuuNEs+GA==
"@types/vscode@1.45.1":
version "1.45.1"
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.45.1.tgz#672fb8c2cc33cf14cd4d3bdaa19bb294fe2b2706"
integrity sha512-0NO9qrrEJBO8FsqHCrFMgR2suKnwCsKBWvRSb2OzH5gs4i3QO5AhEMQYrSzDbU/wLPt7N617/rN9lPY213gmwg==

ansi-styles@^3.2.1:
version "3.2.1"
Expand Down
4 changes: 2 additions & 2 deletions src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description": "VS Code library for Razor language support.",
"devDependencies": {
"@types/node": "^10.9.4",
"@types/vscode": "1.31.0",
"@types/vscode": "1.45.1",
"js-yaml": ">=3.13.1",
"rimraf": "2.6.3",
"tslint": "^5.11.0",
Expand All @@ -22,7 +22,7 @@
"main": "./dist/extension.js",
"types": "./dist/extension.d.ts",
"engines": {
"vscode": "1.31.0"
"vscode": "1.45.1"
},
"scripts": {
"clean": "rimraf out && rimraf dist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class HtmlTagCompletionProvider {

private async onDidChangeTextDocument(
document: vscode.TextDocument,
changes: vscode.TextDocumentContentChangeEvent[]) {
changes: ReadonlyArray<vscode.TextDocumentContentChangeEvent>) {
if (!this.enabled) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,11 @@

import * as vscode from 'vscode';
import * as vscodeapi from 'vscode';
import { RazorDocumentManager } from './RazorDocumentManager';
import { RazorDocumentSynchronizer } from './RazorDocumentSynchronizer';
import { RazorLanguage } from './RazorLanguage';
import { RazorLanguageServiceClient } from './RazorLanguageServiceClient';
import { RazorLogger } from './RazorLogger';
import { RazorDocumentSemanticTokensProvider } from './Semantic/RazorDocumentSemanticTokensProvider';
export class ProposedApisFeature {
constructor(
private documentSynchronizer: RazorDocumentSynchronizer,
private documentManager: RazorDocumentManager,
private languageServiceClient: RazorLanguageServiceClient,
private logger: RazorLogger,
) {
}

export class ProposedApisFeature {
public async register(vscodeType: typeof vscodeapi, localRegistrations: vscode.Disposable[]) {
if (vscodeType.env.appName.endsWith('Insiders')) {
const legend = await this.languageServiceClient.getSemanticTokenLegend();
const semanticTokenProvider = new RazorDocumentSemanticTokensProvider(this.documentSynchronizer, this.documentManager, this.languageServiceClient, this.logger);
if (legend) {
localRegistrations.push(vscodeType.languages.registerDocumentSemanticTokensProvider(RazorLanguage.id, semanticTokenProvider, legend));
}
return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class RazorCompletionItemProvider
(range as any).replacing = new vscode.Range(replacingRangeStart, replacingRangeEnd);
}

if (range.start && range.end) {
if (range instanceof vscode.Range && range.start && range.end) {
const rangeStart = this.offsetColumn(completionCharacterOffset, hostDocumentPosition.line, range.start);
const rangeEnd = this.offsetColumn(completionCharacterOffset, hostDocumentPosition.line, range.end);
completionItem.range = new vscode.Range(rangeStart, rangeEnd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class RazorLanguageServiceClient {
public async getSemanticTokenLegend(): Promise<vscode.SemanticTokensLegend | undefined> {
await this.ensureStarted();

const response = await this.serverClient.sendRequest<vscode.SemanticTokensLegend>('razor/semanticTokensLegend', /*request param*/null);
const response = await this.serverClient.sendRequest<vscode.SemanticTokensLegend>('_ms_/textDocument/semanticTokensLegend', /*request param*/null);

if (response.tokenTypes && response.tokenTypes.length > 0) {
return response;
Expand All @@ -53,7 +53,7 @@ export class RazorLanguageServiceClient {
await this.ensureStarted();

const request = new SemanticTokensRequest(languageKind, uri);
const response = await this.serverClient.sendRequest<vscode.SemanticTokens>('razor/semanticTokens', request);
const response = await this.serverClient.sendRequest<vscode.SemanticTokens>('_ms_/textDocument/semanticTokens', request);

if (response.data && response.data.length > 0) {
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ export class RazorDocumentSemanticTokensProvider
extends RazorLanguageFeatureBase
implements vscode.DocumentSemanticTokensProvider {

public async provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken) {
const semanticTokenResponse = await this.serviceClient.mapSemanticTokens(LanguageKind.Razor, document.uri);
public async provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.SemanticTokens | undefined> {
let semanticTokenResponse = await this.serviceClient.mapSemanticTokens(LanguageKind.Razor, document.uri);

if (semanticTokenResponse) {
// However we're serializing into Uint32Array doesn't set byteLength, which is checked by some stuff under the covers.
// Solution? Create a new one, blat it over the old one, go home for the weekend.
semanticTokenResponse.data = new Uint32Array(semanticTokenResponse.data);
const fixedArray = new Uint32Array(semanticTokenResponse.data);
semanticTokenResponse = new vscode.SemanticTokens(fixedArray, semanticTokenResponse.resultId);
}

return semanticTokenResponse;
Expand Down
16 changes: 11 additions & 5 deletions src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { RazorLogger } from './RazorLogger';
import { RazorReferenceProvider } from './RazorReferenceProvider';
import { RazorRenameProvider } from './RazorRenameProvider';
import { RazorSignatureHelpProvider } from './RazorSignatureHelpProvider';
import { RazorDocumentSemanticTokensProvider } from './Semantic/RazorDocumentSemanticTokensProvider';
import { TelemetryReporter } from './TelemetryReporter';

// We specifically need to take a reference to a particular instance of the vscode namespace,
Expand Down Expand Up @@ -125,6 +126,15 @@ export async function activate(vscodeType: typeof vscodeapi, context: ExtensionC
documentManager,
languageServiceClient,
logger);
const legend = await languageServiceClient.getSemanticTokenLegend();
const semanticTokenProvider = new RazorDocumentSemanticTokensProvider(
documentSynchronizer,
documentManager,
languageServiceClient,
logger);
if (legend) {
localRegistrations.push(vscodeType.languages.registerDocumentSemanticTokensProvider(RazorLanguage.id, semanticTokenProvider, legend));
}

localRegistrations.push(
languageConfiguration.register(),
Expand Down Expand Up @@ -166,11 +176,7 @@ export async function activate(vscodeType: typeof vscodeapi, context: ExtensionC
listenToConfigurationChanges(languageServerClient));

if (enableProposedApis) {
const proposedApisFeature = new ProposedApisFeature(
documentSynchronizer,
documentManager,
languageServiceClient,
logger);
const proposedApisFeature = new ProposedApisFeature();

await proposedApisFeature.register(vscodeType, localRegistrations);
}
Expand Down
Loading

0 comments on commit 4f7a155

Please sign in to comment.