33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { commands , CompletionItem , CompletionItemKind , ExtensionContext , languages , Position , Range , SnippetString , TextEdit , window , TextDocument , CompletionContext , CancellationToken , ProviderResult , CompletionList , extensions } from 'vscode' ;
7- import { Disposable , LanguageClient , LanguageClientOptions , ServerOptions , TransportKind , ProvideCompletionItemsSignature , NotificationType } 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' ;
88import * as nls from 'vscode-nls' ;
99import { getCustomDataSource } from './customData' ;
1010import { RequestService , serveFileSystemRequests } from './requests' ;
@@ -15,28 +15,12 @@ namespace CustomDataChangedNotification {
1515
1616const localize = nls . loadMessageBundle ( ) ;
1717
18- export function startClient ( context : ExtensionContext , runtime : { fs ?: RequestService } ) {
18+ export type LanguageClientConstructor = ( name : string , description : string , clientOptions : LanguageClientOptions ) => CommonLanguageClient ;
1919
20- const clientMain = extensions . getExtension ( 'vscode.css-language-features' ) ?. packageJSON ?. main ;
21- const serverMain = clientMain ?. replace ( 'client' , 'server' ) . replace ( 'cssClientMain' , 'cssServerMain' ) ;
22- if ( ! serverMain ) {
23- throw new Error ( 'Unable to compute CSS server module path. Client: ' + clientMain ) ;
24- }
25-
26- const serverModule = context . asAbsolutePath ( serverMain ) ;
20+ export function startClient ( context : ExtensionContext , newLanguageClient : LanguageClientConstructor , runtime : { fs ?: RequestService } ) {
2721
2822 const customDataSource = getCustomDataSource ( context . subscriptions ) ;
2923
30- // The debug options for the server
31- let debugOptions = { execArgv : [ '--nolazy' , '--inspect=6044' ] } ;
32-
33- // If the extension is launch in debug mode the debug server options are use
34- // Otherwise the run options are used
35- let serverOptions : ServerOptions = {
36- run : { module : serverModule , transport : TransportKind . ipc } ,
37- debug : { module : serverModule , transport : TransportKind . ipc , options : debugOptions }
38- } ;
39-
4024 let documentSelector = [ 'css' , 'scss' , 'less' ] ;
4125
4226 // Options to control the language client
@@ -86,7 +70,7 @@ export function startClient(context: ExtensionContext, runtime: { fs?: RequestSe
8670 } ;
8771
8872 // Create the language client and start the client.
89- let client = new LanguageClient ( 'css' , localize ( 'cssserver.name' , 'CSS Language Server' ) , serverOptions , clientOptions ) ;
73+ let client = newLanguageClient ( 'css' , localize ( 'cssserver.name' , 'CSS Language Server' ) , clientOptions ) ;
9074 client . registerProposedFeatures ( ) ;
9175 client . onReady ( ) . then ( ( ) => {
9276
@@ -131,7 +115,7 @@ export function startClient(context: ExtensionContext, runtime: { fs?: RequestSe
131115 const regionCompletionRegExpr = / ^ ( \s * ) ( \/ ( \* \s * ( # \w * ) ? ) ? ) ? $ / ;
132116
133117 return languages . registerCompletionItemProvider ( documentSelector , {
134- provideCompletionItems ( doc , pos ) {
118+ provideCompletionItems ( doc : TextDocument , pos : Position ) {
135119 let lineUntilPos = doc . getText ( new Range ( new Position ( pos . line , 0 ) , pos ) ) ;
136120 let match = lineUntilPos . match ( regionCompletionRegExpr ) ;
137121 if ( match ) {
0 commit comments