Skip to content

Commit 426622c

Browse files
committed
Merge remote-tracking branch 'origin/master' into rebornix/notebookMoveNSplit
2 parents 8317591 + b0d0562 commit 426622c

139 files changed

Lines changed: 2944 additions & 1907 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/launch.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,7 @@
217217
"type": "node",
218218
"request": "launch",
219219
"name": "VS Code (Web)",
220-
"runtimeExecutable": "yarn",
221-
"runtimeArgs": [
222-
"web"
223-
],
220+
"program": "${workspaceFolder}/scripts/code-web.js",
224221
"presentation": {
225222
"group": "0_vscode",
226223
"order": 2
@@ -274,7 +271,7 @@
274271
{
275272
"type": "node",
276273
"request": "launch",
277-
"name": "HTML Unit Tests",
274+
"name": "HTML Server Unit Tests",
278275
"program": "${workspaceFolder}/extensions/html-language-features/server/test/index.js",
279276
"stopOnEntry": false,
280277
"cwd": "${workspaceFolder}/extensions/html-language-features/server",
@@ -286,6 +283,21 @@
286283
"order": 10
287284
}
288285
},
286+
{
287+
"type": "node",
288+
"request": "launch",
289+
"name": "CSS Server Unit Tests",
290+
"program": "${workspaceFolder}/extensions/css-language-features/server/test/index.js",
291+
"stopOnEntry": false,
292+
"cwd": "${workspaceFolder}/extensions/css-language-features/server",
293+
"outFiles": [
294+
"${workspaceFolder}/extensions/css-language-features/server/out/**/*.js"
295+
],
296+
"presentation": {
297+
"group": "5_tests",
298+
"order": 10
299+
}
300+
},
289301
{
290302
"type": "extensionHost",
291303
"request": "launch",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 { ExtensionContext } from 'vscode';
7+
import { LanguageClientOptions } from 'vscode-languageclient';
8+
import { startClient, LanguageClientConstructor } from '../cssClient';
9+
import { LanguageClient } from 'vscode-languageclient/browser';
10+
11+
declare const Worker: {
12+
new(stringUrl: string): any;
13+
};
14+
declare const TextDecoder: {
15+
new(encoding?: string): { decode(buffer: ArrayBuffer): string; };
16+
};
17+
18+
// this method is called when vs code is activated
19+
export function activate(context: ExtensionContext) {
20+
const serverMain = context.asAbsolutePath('server/dist/browser/cssServerMain.js');
21+
try {
22+
const worker = new Worker(serverMain);
23+
const newLanguageClient: LanguageClientConstructor = (id: string, name: string, clientOptions: LanguageClientOptions) => {
24+
return new LanguageClient(id, name, clientOptions, worker);
25+
};
26+
27+
startClient(context, newLanguageClient, { TextDecoder });
28+
29+
} catch (e) {
30+
console.log(e);
31+
}
32+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 interface Options {
7+
locale?: string;
8+
cacheLanguageResolution?: boolean;
9+
}
10+
export interface LocalizeInfo {
11+
key: string;
12+
comment: string[];
13+
}
14+
export interface LocalizeFunc {
15+
(info: LocalizeInfo, message: string, ...args: any[]): string;
16+
(key: string, message: string, ...args: any[]): string;
17+
}
18+
export interface LoadFunc {
19+
(file?: string): LocalizeFunc;
20+
}
21+
22+
function format(message: string, args: any[]): string {
23+
let result: string;
24+
25+
if (args.length === 0) {
26+
result = message;
27+
} else {
28+
result = message.replace(/\{(\d+)\}/g, (match, rest) => {
29+
let index = rest[0];
30+
return typeof args[index] !== 'undefined' ? args[index] : match;
31+
});
32+
}
33+
return result;
34+
}
35+
36+
function localize(_key: string | LocalizeInfo, message: string, ...args: any[]): string {
37+
return format(message, args);
38+
}
39+
40+
export function loadMessageBundle(_file?: string): LocalizeFunc {
41+
return localize;
42+
}
43+
44+
export function config(_opt?: Options | string): LoadFunc {
45+
return loadMessageBundle;
46+
}

extensions/css-language-features/client/src/cssMain.ts renamed to extensions/css-language-features/client/src/cssClient.ts

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

6-
import * as fs from 'fs';
7-
import * as path from 'path';
8-
import { commands, CompletionItem, CompletionItemKind, ExtensionContext, languages, Position, Range, SnippetString, TextEdit, window, workspace, TextDocument, CompletionContext, CancellationToken, ProviderResult, CompletionList } from 'vscode';
9-
import { Disposable, LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, ProvideCompletionItemsSignature } from 'vscode-languageclient';
6+
import { commands, CompletionItem, CompletionItemKind, ExtensionContext, languages, Position, Range, SnippetString, TextEdit, window, TextDocument, CompletionContext, CancellationToken, ProviderResult, CompletionList } from 'vscode';
7+
import { Disposable, LanguageClientOptions, ProvideCompletionItemsSignature, NotificationType, CommonLanguageClient } from 'vscode-languageclient';
108
import * as nls from 'vscode-nls';
11-
import { getCustomDataPathsFromAllExtensions, getCustomDataPathsInAllWorkspaces } from './customData';
9+
import { getCustomDataSource } from './customData';
10+
import { RequestService, serveFileSystemRequests } from './requests';
11+
12+
namespace CustomDataChangedNotification {
13+
export const type: NotificationType<string[]> = new NotificationType('css/customDataChanged');
14+
}
1215

1316
const localize = nls.loadMessageBundle();
1417

15-
// this method is called when vs code is activated
16-
export function activate(context: ExtensionContext) {
18+
export type LanguageClientConstructor = (name: string, description: string, clientOptions: LanguageClientOptions) => CommonLanguageClient;
1719

18-
let serverMain = readJSONFile(context.asAbsolutePath('./server/package.json')).main;
19-
let serverModule = context.asAbsolutePath(path.join('server', serverMain));
20+
export interface Runtime {
21+
TextDecoder: { new(encoding?: string): { decode(buffer: ArrayBuffer): string; } };
22+
fs?: RequestService;
23+
}
2024

21-
// The debug options for the server
22-
let debugOptions = { execArgv: ['--nolazy', '--inspect=6044'] };
25+
export function startClient(context: ExtensionContext, newLanguageClient: LanguageClientConstructor, runtime: Runtime) {
2326

24-
// If the extension is launch in debug mode the debug server options are use
25-
// Otherwise the run options are used
26-
let serverOptions: ServerOptions = {
27-
run: { module: serverModule, transport: TransportKind.ipc },
28-
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
29-
};
27+
const customDataSource = getCustomDataSource(context.subscriptions);
3028

3129
let documentSelector = ['css', 'scss', 'less'];
3230

33-
let dataPaths = [
34-
...getCustomDataPathsInAllWorkspaces(workspace.workspaceFolders),
35-
...getCustomDataPathsFromAllExtensions()
36-
];
37-
3831
// Options to control the language client
3932
let clientOptions: LanguageClientOptions = {
4033
documentSelector,
4134
synchronize: {
4235
configurationSection: ['css', 'scss', 'less']
4336
},
4437
initializationOptions: {
45-
dataPaths
38+
handledSchemas: ['file']
4639
},
4740
middleware: {
4841
provideCompletionItem(document: TextDocument, position: Position, context: CompletionContext, token: CancellationToken, next: ProvideCompletionItemsSignature): ProviderResult<CompletionItem[] | CompletionList> {
@@ -82,8 +75,17 @@ export function activate(context: ExtensionContext) {
8275
};
8376

8477
// Create the language client and start the client.
85-
let client = new LanguageClient('css', localize('cssserver.name', 'CSS Language Server'), serverOptions, clientOptions);
78+
let client = newLanguageClient('css', localize('cssserver.name', 'CSS Language Server'), clientOptions);
8679
client.registerProposedFeatures();
80+
client.onReady().then(() => {
81+
82+
client.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);
83+
customDataSource.onDidChange(() => {
84+
client.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);
85+
});
86+
87+
serveFileSystemRequests(client, runtime);
88+
});
8789

8890
let disposable = client.start();
8991
// Push the disposable to the context's subscriptions so that the
@@ -118,7 +120,7 @@ export function activate(context: ExtensionContext) {
118120
const regionCompletionRegExpr = /^(\s*)(\/(\*\s*(#\w*)?)?)?$/;
119121

120122
return languages.registerCompletionItemProvider(documentSelector, {
121-
provideCompletionItems(doc, pos) {
123+
provideCompletionItems(doc: TextDocument, pos: Position) {
122124
let lineUntilPos = doc.getText(new Range(new Position(pos.line, 0), pos));
123125
let match = lineUntilPos.match(regionCompletionRegExpr);
124126
if (match) {
@@ -162,13 +164,3 @@ export function activate(context: ExtensionContext) {
162164
}
163165
}
164166
}
165-
166-
function readJSONFile(location: string) {
167-
try {
168-
return JSON.parse(fs.readFileSync(location).toString());
169-
} catch (e) {
170-
console.log(`Problems reading ${location}: ${e}`);
171-
return {};
172-
}
173-
}
174-

extensions/css-language-features/client/src/customData.ts

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

6-
import * as path from 'path';
7-
import { workspace, WorkspaceFolder, extensions } from 'vscode';
6+
import { workspace, extensions, Uri, EventEmitter, Disposable } from 'vscode';
7+
import { resolvePath, joinPath } from './requests';
88

9-
interface ExperimentalConfig {
10-
customData?: string[];
11-
experimental?: {
12-
customData?: string[];
9+
export function getCustomDataSource(toDispose: Disposable[]) {
10+
let pathsInWorkspace = getCustomDataPathsInAllWorkspaces();
11+
let pathsInExtensions = getCustomDataPathsFromAllExtensions();
12+
13+
const onChange = new EventEmitter<void>();
14+
15+
toDispose.push(extensions.onDidChange(_ => {
16+
const newPathsInExtensions = getCustomDataPathsFromAllExtensions();
17+
if (newPathsInExtensions.length !== pathsInExtensions.length || !newPathsInExtensions.every((val, idx) => val === pathsInExtensions[idx])) {
18+
pathsInExtensions = newPathsInExtensions;
19+
onChange.fire();
20+
}
21+
}));
22+
toDispose.push(workspace.onDidChangeConfiguration(e => {
23+
if (e.affectsConfiguration('css.customData')) {
24+
pathsInWorkspace = getCustomDataPathsInAllWorkspaces();
25+
onChange.fire();
26+
}
27+
}));
28+
29+
return {
30+
get uris() {
31+
return pathsInWorkspace.concat(pathsInExtensions);
32+
},
33+
get onDidChange() {
34+
return onChange.event;
35+
}
1336
};
1437
}
1538

16-
export function getCustomDataPathsInAllWorkspaces(workspaceFolders: readonly WorkspaceFolder[] | undefined): string[] {
39+
40+
function getCustomDataPathsInAllWorkspaces(): string[] {
41+
const workspaceFolders = workspace.workspaceFolders;
42+
1743
const dataPaths: string[] = [];
1844

1945
if (!workspaceFolders) {
2046
return dataPaths;
2147
}
2248

23-
workspaceFolders.forEach(wf => {
24-
const allCssConfig = workspace.getConfiguration(undefined, wf.uri);
25-
const wfCSSConfig = allCssConfig.inspect<ExperimentalConfig>('css');
26-
if (wfCSSConfig && wfCSSConfig.workspaceFolderValue && wfCSSConfig.workspaceFolderValue.customData) {
27-
const customData = wfCSSConfig.workspaceFolderValue.customData;
28-
if (Array.isArray(customData)) {
29-
customData.forEach(t => {
30-
if (typeof t === 'string') {
31-
dataPaths.push(path.resolve(wf.uri.fsPath, t));
32-
}
33-
});
49+
const collect = (paths: string[] | undefined, rootFolder: Uri) => {
50+
if (Array.isArray(paths)) {
51+
for (const path of paths) {
52+
if (typeof path === 'string') {
53+
dataPaths.push(resolvePath(rootFolder, path).toString());
54+
}
55+
}
56+
}
57+
};
58+
59+
for (let i = 0; i < workspaceFolders.length; i++) {
60+
const folderUri = workspaceFolders[i].uri;
61+
const allCssConfig = workspace.getConfiguration('css', folderUri);
62+
const customDataInspect = allCssConfig.inspect<string[]>('customData');
63+
if (customDataInspect) {
64+
collect(customDataInspect.workspaceFolderValue, folderUri);
65+
if (i === 0) {
66+
if (workspace.workspaceFile) {
67+
collect(customDataInspect.workspaceValue, workspace.workspaceFile);
68+
}
69+
collect(customDataInspect.globalValue, folderUri);
3470
}
3571
}
36-
});
3772

73+
}
3874
return dataPaths;
3975
}
4076

41-
export function getCustomDataPathsFromAllExtensions(): string[] {
77+
function getCustomDataPathsFromAllExtensions(): string[] {
4278
const dataPaths: string[] = [];
4379

4480
for (const extension of extensions.all) {
@@ -47,7 +83,7 @@ export function getCustomDataPathsFromAllExtensions(): string[] {
4783
if (contributes && contributes.css && contributes.css.customData && Array.isArray(contributes.css.customData)) {
4884
const relativePaths: string[] = contributes.css.customData;
4985
relativePaths.forEach(rp => {
50-
dataPaths.push(path.resolve(extension.extensionPath, rp));
86+
dataPaths.push(joinPath(extension.extensionUri, rp).toString());
5187
});
5288
}
5389
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 { getNodeFSRequestService } from './nodeFs';
7+
import { ExtensionContext, extensions } from 'vscode';
8+
import { startClient, LanguageClientConstructor } from '../cssClient';
9+
import { ServerOptions, TransportKind, LanguageClientOptions, LanguageClient } from 'vscode-languageclient/node';
10+
import { TextDecoder } from 'util';
11+
12+
// this method is called when vs code is activated
13+
export function activate(context: ExtensionContext) {
14+
15+
const clientMain = extensions.getExtension('vscode.css-language-features')?.packageJSON?.main;
16+
const serverMain = clientMain?.replace('client', 'server').replace('cssClientMain', 'cssServerMain');
17+
if (!serverMain) {
18+
throw new Error('Unable to compute CSS server module path. Client: ' + clientMain);
19+
}
20+
21+
const serverModule = context.asAbsolutePath(serverMain);
22+
23+
// The debug options for the server
24+
const debugOptions = { execArgv: ['--nolazy', '--inspect=6044'] };
25+
26+
// If the extension is launch in debug mode the debug server options are use
27+
// Otherwise the run options are used
28+
const serverOptions: ServerOptions = {
29+
run: { module: serverModule, transport: TransportKind.ipc },
30+
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
31+
};
32+
33+
const newLanguageClient: LanguageClientConstructor = (id: string, name: string, clientOptions: LanguageClientOptions) => {
34+
return new LanguageClient(id, name, serverOptions, clientOptions);
35+
};
36+
37+
startClient(context, newLanguageClient, { fs: getNodeFSRequestService(), TextDecoder });
38+
}

0 commit comments

Comments
 (0)