@@ -7,13 +7,15 @@ import {
77 createConnection , IConnection , TextDocuments , InitializeParams , InitializeResult , ServerCapabilities , ConfigurationRequest , WorkspaceFolder
88} from 'vscode-languageserver' ;
99import URI from 'vscode-uri' ;
10+ import * as fs from 'fs' ;
1011import { TextDocument , CompletionList } from 'vscode-languageserver-types' ;
1112
12- import { getCSSLanguageService , getSCSSLanguageService , getLESSLanguageService , LanguageSettings , LanguageService , Stylesheet } from 'vscode-css-languageservice' ;
13+ import { getCSSLanguageService , getSCSSLanguageService , getLESSLanguageService , LanguageSettings , LanguageService , Stylesheet , CSSData } from 'vscode-css-languageservice' ;
1314import { getLanguageModelCache } from './languageModelCache' ;
1415import { getPathCompletionParticipant } from './pathCompletion' ;
1516import { formatError , runSafe } from './utils/runner' ;
1617import { getDocumentContext } from './utils/documentContext' ;
18+ import { parseCSSData } from './utils/languageFacts' ;
1719
1820export interface Settings {
1921 css : LanguageSettings ;
@@ -50,6 +52,8 @@ let scopedSettingsSupport = false;
5052let foldingRangeLimit = Number . MAX_VALUE ;
5153let workspaceFolders : WorkspaceFolder [ ] ;
5254
55+ const languageServices : { [ id : string ] : LanguageService } = { } ;
56+
5357// After the server has started the client sends an initialize request. The server receives
5458// in the passed params the rootPath of the workspace plus the client capabilities.
5559connection . onInitialize ( ( params : InitializeParams ) : InitializeResult => {
@@ -61,6 +65,19 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
6165 }
6266 }
6367
68+ const dataPaths : string [ ] = params . initializationOptions . dataPaths ;
69+
70+ const customDataCollections : CSSData [ ] = [ ] ;
71+
72+ dataPaths . forEach ( p => {
73+ if ( fs . existsSync ( p ) ) {
74+ const data = parseCSSData ( fs . readFileSync ( p , 'utf-8' ) ) ;
75+ customDataCollections . push ( data ) ;
76+ } else {
77+ return ;
78+ }
79+ } ) ;
80+
6481 function getClientCapability < T > ( name : string , def : T ) {
6582 const keys = name . split ( '.' ) ;
6683 let c : any = params . capabilities ;
@@ -76,6 +93,10 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
7693 scopedSettingsSupport = ! ! getClientCapability ( 'workspace.configuration' , false ) ;
7794 foldingRangeLimit = getClientCapability ( 'textDocument.foldingRange.rangeLimit' , Number . MAX_VALUE ) ;
7895
96+ languageServices . css = getCSSLanguageService ( { customDataCollections } ) ;
97+ languageServices . scss = getSCSSLanguageService ( { customDataCollections } ) ;
98+ languageServices . less = getLESSLanguageService ( { customDataCollections } ) ;
99+
79100 const capabilities : ServerCapabilities = {
80101 // Tell the client that the server works in FULL text document sync mode
81102 textDocumentSync : documents . syncKind ,
@@ -96,12 +117,6 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
96117 return { capabilities } ;
97118} ) ;
98119
99- const languageServices : { [ id : string ] : LanguageService } = {
100- css : getCSSLanguageService ( ) ,
101- scss : getSCSSLanguageService ( ) ,
102- less : getLESSLanguageService ( )
103- } ;
104-
105120function getLanguageService ( document : TextDocument ) {
106121 let service = languageServices [ document . languageId ] ;
107122 if ( ! service ) {
0 commit comments