mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
Adopt LS service/client that has common & node
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { commands, CompletionItem, CompletionItemKind, ExtensionContext, languages, Position, Range, SnippetString, TextEdit, window, TextDocument, CompletionContext, CancellationToken, ProviderResult, CompletionList, extensions } from 'vscode';
|
||||
import { Disposable, LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, ProvideCompletionItemsSignature, NotificationType } from 'vscode-languageclient';
|
||||
import { commands, CompletionItem, CompletionItemKind, ExtensionContext, languages, Position, Range, SnippetString, TextEdit, window, TextDocument, CompletionContext, CancellationToken, ProviderResult, CompletionList } from 'vscode';
|
||||
import { Disposable, LanguageClientOptions, ProvideCompletionItemsSignature, NotificationType, CommonLanguageClient } from 'vscode-languageclient';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { getCustomDataSource } from './customData';
|
||||
import { RequestService, serveFileSystemRequests } from './requests';
|
||||
@@ -15,28 +15,12 @@ namespace CustomDataChangedNotification {
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export function startClient(context: ExtensionContext, runtime: { fs?: RequestService }) {
|
||||
export type LanguageClientConstructor = (name: string, description: string, clientOptions: LanguageClientOptions) => CommonLanguageClient;
|
||||
|
||||
const clientMain = extensions.getExtension('vscode.css-language-features')?.packageJSON?.main;
|
||||
const serverMain = clientMain?.replace('client', 'server').replace('cssClientMain', 'cssServerMain');
|
||||
if (!serverMain) {
|
||||
throw new Error('Unable to compute CSS server module path. Client: ' + clientMain);
|
||||
}
|
||||
|
||||
const serverModule = context.asAbsolutePath(serverMain);
|
||||
export function startClient(context: ExtensionContext, newLanguageClient: LanguageClientConstructor, runtime: { fs?: RequestService }) {
|
||||
|
||||
const customDataSource = getCustomDataSource(context.subscriptions);
|
||||
|
||||
// The debug options for the server
|
||||
let debugOptions = { execArgv: ['--nolazy', '--inspect=6044'] };
|
||||
|
||||
// If the extension is launch in debug mode the debug server options are use
|
||||
// Otherwise the run options are used
|
||||
let serverOptions: ServerOptions = {
|
||||
run: { module: serverModule, transport: TransportKind.ipc },
|
||||
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
|
||||
};
|
||||
|
||||
let documentSelector = ['css', 'scss', 'less'];
|
||||
|
||||
// Options to control the language client
|
||||
@@ -86,7 +70,7 @@ export function startClient(context: ExtensionContext, runtime: { fs?: RequestSe
|
||||
};
|
||||
|
||||
// Create the language client and start the client.
|
||||
let client = new LanguageClient('css', localize('cssserver.name', 'CSS Language Server'), serverOptions, clientOptions);
|
||||
let client = newLanguageClient('css', localize('cssserver.name', 'CSS Language Server'), clientOptions);
|
||||
client.registerProposedFeatures();
|
||||
client.onReady().then(() => {
|
||||
|
||||
@@ -131,7 +115,7 @@ export function startClient(context: ExtensionContext, runtime: { fs?: RequestSe
|
||||
const regionCompletionRegExpr = /^(\s*)(\/(\*\s*(#\w*)?)?)?$/;
|
||||
|
||||
return languages.registerCompletionItemProvider(documentSelector, {
|
||||
provideCompletionItems(doc, pos) {
|
||||
provideCompletionItems(doc: TextDocument, pos: Position) {
|
||||
let lineUntilPos = doc.getText(new Range(new Position(pos.line, 0), pos));
|
||||
let match = lineUntilPos.match(regionCompletionRegExpr);
|
||||
if (match) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { workspace, extensions, Uri, EventEmitter, Disposable } from 'vscode';
|
||||
import { resolvePath } from './requests';
|
||||
import { resolvePath, joinPath } from './requests';
|
||||
|
||||
export function getCustomDataSource(toDispose: Disposable[]) {
|
||||
let pathsInWorkspace = getCustomDataPathsInAllWorkspaces();
|
||||
@@ -83,7 +83,7 @@ function getCustomDataPathsFromAllExtensions(): string[] {
|
||||
if (contributes && contributes.css && contributes.css.customData && Array.isArray(contributes.css.customData)) {
|
||||
const relativePaths: string[] = contributes.css.customData;
|
||||
relativePaths.forEach(rp => {
|
||||
dataPaths.push(Uri.joinPath(extension.extensionUri, rp).toString());
|
||||
dataPaths.push(joinPath(extension.extensionUri, rp).toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,35 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { getNodeFSRequestService } from './nodeFs';
|
||||
import { ExtensionContext } from 'vscode';
|
||||
import { startClient } from '../cssClient';
|
||||
import { ExtensionContext, extensions } from 'vscode';
|
||||
import { startClient, LanguageClientConstructor } from '../cssClient';
|
||||
|
||||
import { ServerOptions, TransportKind, LanguageClientOptions, LanguageClient } from 'vscode-languageclient/node';
|
||||
|
||||
// this method is called when vs code is activated
|
||||
export function activate(context: ExtensionContext) {
|
||||
startClient(context, { fs: getNodeFSRequestService() });
|
||||
|
||||
const clientMain = extensions.getExtension('vscode.css-language-features')?.packageJSON?.main;
|
||||
const serverMain = clientMain?.replace('client', 'server').replace('cssClientMain', 'cssServerMain');
|
||||
if (!serverMain) {
|
||||
throw new Error('Unable to compute CSS server module path. Client: ' + clientMain);
|
||||
}
|
||||
|
||||
const serverModule = context.asAbsolutePath(serverMain);
|
||||
|
||||
// The debug options for the server
|
||||
const debugOptions = { execArgv: ['--nolazy', '--inspect=6044'] };
|
||||
|
||||
// If the extension is launch in debug mode the debug server options are use
|
||||
// Otherwise the run options are used
|
||||
const serverOptions: ServerOptions = {
|
||||
run: { module: serverModule, transport: TransportKind.ipc },
|
||||
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
|
||||
};
|
||||
|
||||
const newLanguageClient: LanguageClientConstructor = (id: string, name: string, clientOptions: LanguageClientOptions) => {
|
||||
return new LanguageClient(id, name, serverOptions, clientOptions);
|
||||
};
|
||||
|
||||
startClient(context, newLanguageClient, { fs: getNodeFSRequestService() });
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Uri, workspace } from 'vscode';
|
||||
import { RequestType, LanguageClient } from 'vscode-languageclient';
|
||||
import { RequestType, CommonLanguageClient } from 'vscode-languageclient';
|
||||
import { TextDecoder } from 'util';
|
||||
|
||||
export namespace FsContentRequest {
|
||||
@@ -18,7 +18,7 @@ export namespace FsReadDirRequest {
|
||||
export const type: RequestType<string, [string, FileType][], any, any> = new RequestType('fs/readDir');
|
||||
}
|
||||
|
||||
export function serveFileSystemRequests(client: LanguageClient, runtime: { fs?: RequestService; }) {
|
||||
export function serveFileSystemRequests(client: CommonLanguageClient, runtime: { fs?: RequestService; }) {
|
||||
client.onRequest(FsContentRequest.type, (param: { uri: string; encoding?: string; }) => {
|
||||
const uri = Uri.parse(param.uri);
|
||||
if (uri.scheme === 'file' && runtime.fs) {
|
||||
@@ -113,6 +113,16 @@ export function resolvePath(uri: Uri, path: string): Uri {
|
||||
if (isAbsolutePath(path)) {
|
||||
return uri.with({ path: path });
|
||||
}
|
||||
return Uri.joinPath(uri, path);
|
||||
return joinPath(uri, path);
|
||||
}
|
||||
|
||||
export function joinPath(uri: Uri, ...paths: string[]): Uri {
|
||||
let uriPath = uri.path;
|
||||
for (let path of paths) {
|
||||
if (path.charCodeAt(path.length - 1) !== Slash && path.charCodeAt(0) !== Slash) {
|
||||
uriPath += '/';
|
||||
}
|
||||
uriPath += path;
|
||||
}
|
||||
return uri.with({ path: uriPath });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user