Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to @microsoft/[email protected] #3286

Merged
merged 12 commits into from
Nov 1, 2021
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,18 @@
]
}
],
"configurationDefaults": {
"[dockercompose]": {
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.autoIndent": "advanced",
"editor.quickSuggestions": {
"other": true,
"comments": false,
"strings": true
}
}
},
"configuration": {
"title": "Docker",
"properties": {
Expand Down Expand Up @@ -3039,7 +3051,7 @@
"@azure/storage-blob": "^12.4.1",
"@docker/sdk": "^1.0.3",
"@grpc/grpc-js": "^1.2.12",
"@microsoft/compose-language-service": "^0.0.1-alpha",
"@microsoft/compose-language-service": "^0.0.2-alpha",
"dayjs": "^1.10.4",
"dockerfile-language-server-nodejs": "^0.7.2",
"dockerode": "^3.2.1",
Expand Down
15 changes: 14 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { TelemetryEvent } from '@microsoft/compose-language-service/lib/client/TelemetryEvent';
import * as fse from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
import { callWithTelemetryAndErrorHandling, createAzExtOutputChannel, createExperimentationService, IActionContext, registerErrorHandler, registerReportIssueCommand, registerUIExtensionVariables, UserCancelledError } from 'vscode-azureextensionui';
import { callWithTelemetryAndErrorHandling, createAzExtOutputChannel, createExperimentationService, IActionContext, registerErrorHandler, registerEvent, registerReportIssueCommand, registerUIExtensionVariables, UserCancelledError } from 'vscode-azureextensionui';
import { ConfigurationParams, DidChangeConfigurationNotification, DocumentSelector, LanguageClient, LanguageClientOptions, Middleware, ServerOptions, TransportKind } from 'vscode-languageclient/node';
import * as tas from 'vscode-tas-client';
import { registerCommands } from './commands/registerCommands';
Expand All @@ -23,6 +24,7 @@ import { registerListeners } from './telemetry/registerListeners';
import { registerTrees } from './tree/registerTrees';
import { AzureAccountExtensionListener } from './utils/AzureAccountExtensionListener';
import { cryptoUtils } from './utils/cryptoUtils';
import { DocumentSettingsClientFeature } from './utils/DocumentSettingsClientFeature';
import { isLinux, isMac, isWindows } from './utils/osUtils';

export type KeyInfo = { [keyName: string]: string };
Expand Down Expand Up @@ -314,6 +316,17 @@ function activateComposeLanguageClient(ctx: vscode.ExtensionContext): void {
clientOptions
);
client.registerProposedFeatures();
client.registerFeature(new DocumentSettingsClientFeature(client));

registerEvent('compose-langserver-event', client.onTelemetry, (context: IActionContext, evtArgs: TelemetryEvent) => {
context.telemetry.properties.langServerEventName = evtArgs.eventName;
context.telemetry.suppressAll = evtArgs.suppressAll;
context.telemetry.suppressIfSuccessful = evtArgs.suppressIfSuccessful;

Object.assign(context.telemetry.measurements, evtArgs.measurements);
Object.assign(context.telemetry.properties, evtArgs.properties);
});

ctx.subscriptions.push(client.start());
});
}
71 changes: 71 additions & 0 deletions src/utils/DocumentSettingsClientFeature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*!--------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// Largely copied from https://github.com/microsoft/compose-language-service/blob/main/src/test/clientExtension/DocumentSettingsClientFeature.ts

import * as vscode from 'vscode';
import { ClientCapabilities, StaticFeature } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/node';
import { DocumentSettings, DocumentSettingsNotificationParams, DocumentSettingsParams, DocumentSettingsNotification, DocumentSettingsRequest } from '@microsoft/compose-language-service/lib/client/DocumentSettings';

/**
* This class implements functionality to allow the language server to request information about an open document (including tab size and line endings), and also
* notify the language server if those settings change
*/
export class DocumentSettingsClientFeature implements StaticFeature, vscode.Disposable {
private disposables: vscode.Disposable[] = [];

public constructor(private readonly client: LanguageClient) { }

public fillClientCapabilities(capabilities: ClientCapabilities): void {
const documentSettings = {
notify: true,
request: true,
};

capabilities.experimental = {
...capabilities.experimental,
documentSettings,
};
}

public initialize(): void {
this.disposables.push(
this.client.onRequest(
DocumentSettingsRequest.method,
(params: DocumentSettingsParams): DocumentSettings | undefined => {
const textEditor = vscode.window.visibleTextEditors.find(e => e.document.uri.toString() === params.textDocument.uri);

if (!textEditor) {
return undefined;
}

return {
eol: textEditor.document.eol,
tabSize: Number(textEditor.options.tabSize),
};
}
)
);

this.disposables.push(
vscode.window.onDidChangeTextEditorOptions(
(e: vscode.TextEditorOptionsChangeEvent) => {
const params: DocumentSettingsNotificationParams = {
textDocument: { uri: e.textEditor.document.uri.toString() },
eol: e.textEditor.document.eol,
tabSize: Number(e.options.tabSize),
};

this.client.sendNotification(DocumentSettingsNotification.method, params);
}
)
);
}

public dispose(): void {
this.disposables.forEach(d => d.dispose());
}
}
5 changes: 5 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ const config = {
module: /node_modules\/vscode-extension-telemetry/,
message: /Can't resolve 'applicationinsights-native-metrics'/
},
{
// Ignore a warning for missing optional dependency of `ssh2`
module: /node_modules\/ssh2/,
message: /Can't resolve 'cpu-features'/
},
(warning) => false, // No other warnings should be ignored
],
};
Expand Down