Adopt LS service/client that has common & node
This commit is contained in:
parent
d1a3e6ede6
commit
2d47826dac
9 changed files with 67 additions and 43 deletions
|
@ -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 });
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
},
|
||||
"main": "./out/node/cssServerMain",
|
||||
"dependencies": {
|
||||
"vscode-css-languageservice": "4.3.0-next.0",
|
||||
"vscode-css-languageservice": "4.3.0-next.1",
|
||||
"vscode-languageserver": "^6.1.1",
|
||||
"vscode-uri": "^2.1.1"
|
||||
},
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import {
|
||||
IConnection, TextDocuments, InitializeParams, InitializeResult, ServerCapabilities, ConfigurationRequest, WorkspaceFolder, TextDocumentSyncKind, NotificationType
|
||||
Connection, TextDocuments, InitializeParams, InitializeResult, ServerCapabilities, ConfigurationRequest, WorkspaceFolder, TextDocumentSyncKind, NotificationType
|
||||
} from 'vscode-languageserver';
|
||||
import { URI } from 'vscode-uri';
|
||||
import { getCSSLanguageService, getSCSSLanguageService, getLESSLanguageService, LanguageSettings, LanguageService, Stylesheet, TextDocument, Position } from 'vscode-css-languageservice';
|
||||
|
@ -29,7 +29,7 @@ export interface RuntimeEnvironment {
|
|||
http?: RequestService
|
||||
}
|
||||
|
||||
export function startServer(connection: IConnection, runtime: RuntimeEnvironment) {
|
||||
export function startServer(connection: Connection, runtime: RuntimeEnvironment) {
|
||||
|
||||
// Create a text document manager.
|
||||
const documents = new TextDocuments(TextDocument);
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IConnection, createConnection } from 'vscode-languageserver';
|
||||
import { createConnection, Connection } from 'vscode-languageserver/node';
|
||||
import { formatError } from '../utils/runner';
|
||||
import { startServer } from '../cssServer';
|
||||
import { getNodeFSRequestService } from './nodeFs';
|
||||
|
||||
// Create a connection for the server.
|
||||
const connection: IConnection = createConnection();
|
||||
const connection: Connection = createConnection();
|
||||
|
||||
console.log = connection.console.log.bind(connection.console);
|
||||
console.error = connection.console.error.bind(connection.console);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { URI } from 'vscode-uri';
|
||||
import { endsWith, startsWith } from './utils/strings';
|
||||
import { RequestType, IConnection } from 'vscode-languageserver';
|
||||
import { RequestType, Connection } from 'vscode-languageserver';
|
||||
import { RuntimeEnvironment } from './cssServer';
|
||||
|
||||
export namespace FsContentRequest {
|
||||
|
@ -65,7 +65,7 @@ export interface RequestService {
|
|||
}
|
||||
|
||||
|
||||
export function getRequestService(handledSchemas: string[], connection: IConnection, runtime: RuntimeEnvironment): RequestService {
|
||||
export function getRequestService(handledSchemas: string[], connection: Connection, runtime: RuntimeEnvironment): RequestService {
|
||||
const builtInHandlers: { [protocol: string]: RequestService | undefined } = {};
|
||||
for (let protocol of handledSchemas) {
|
||||
if (protocol === 'file') {
|
||||
|
|
|
@ -701,13 +701,13 @@ to-regex-range@^5.0.1:
|
|||
dependencies:
|
||||
is-number "^7.0.0"
|
||||
|
||||
vscode-css-languageservice@4.3.0-next.0:
|
||||
version "4.3.0-next.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-4.3.0-next.0.tgz#70ca6e192e1d7fb904867e696851b14401da9573"
|
||||
integrity sha512-OwYavU+gqocK3YQi484CrGkGMMRRmzJdeNMfgAr/SssKJVJuvkLec7NbAopM42KTE6OPaqU3AFgI5AMERmIJ4A==
|
||||
vscode-css-languageservice@4.3.0-next.1:
|
||||
version "4.3.0-next.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-4.3.0-next.1.tgz#6e1ddf5c469468585bdb91b554ffdf961915cd10"
|
||||
integrity sha512-Ks/MbHDyUFMMF5DQ3hqh6xjT+EoEjWsdeOwgWTCg+caConhweO2Y8VpZO3qDpbBO5dTnGlcxVG07sxOZyxF77Q==
|
||||
dependencies:
|
||||
vscode-languageserver-textdocument "^1.0.1"
|
||||
vscode-languageserver-types "^3.15.1"
|
||||
vscode-languageserver-types "3.16.0-next.1"
|
||||
vscode-nls "^4.1.2"
|
||||
vscode-uri "^2.1.1"
|
||||
|
||||
|
@ -729,11 +729,16 @@ vscode-languageserver-textdocument@^1.0.1:
|
|||
resolved "https://registry.yarnpkg.com/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.1.tgz#178168e87efad6171b372add1dea34f53e5d330f"
|
||||
integrity sha512-UIcJDjX7IFkck7cSkNNyzIz5FyvpQfY7sdzVy+wkKN/BLaD4DQ0ppXQrKePomCxTS7RrolK1I0pey0bG9eh8dA==
|
||||
|
||||
vscode-languageserver-types@3.15.1, vscode-languageserver-types@^3.15.1:
|
||||
vscode-languageserver-types@3.15.1:
|
||||
version "3.15.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.15.1.tgz#17be71d78d2f6236d414f0001ce1ef4d23e6b6de"
|
||||
integrity sha512-+a9MPUQrNGRrGU630OGbYVQ+11iOIovjCkqxajPa9w57Sd5ruK8WQNsslzpa0x/QJqC8kRc2DUxWjIFwoNm4ZQ==
|
||||
|
||||
vscode-languageserver-types@3.16.0-next.1:
|
||||
version "3.16.0-next.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0-next.1.tgz#97e9803c4a999e81e3ff000a91b630173eaaf28c"
|
||||
integrity sha512-tZFUSbyjUcrh+qQf13ALX4QDdOfDX0cVaBFgy7ktJ0VwS7AW/yRKgGPSxVqqP9OCMNPdqP57O5q47w2pEwfaUg==
|
||||
|
||||
vscode-languageserver@^6.1.1:
|
||||
version "6.1.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-6.1.1.tgz#d76afc68172c27d4327ee74332b468fbc740d762"
|
||||
|
|
Loading…
Reference in a new issue