import { Configuration , ImportedCompiledCssFile , ImportedFile , Importer , NodeJsImporter , Syntax } from "@css-blocks/core" ; import { TextDocuments } from "vscode-languageserver" ; import { URI } from "vscode-uri" ; /**
 * Imports the contents of the file from the language server client if its
 * already opened on the client. Otherwise, it proxies to the NodeJSImporter to
 * read the file from the disk
 */ export class LSImporter implements Importer { baseImporter : Importer ; documents : TextDocuments ; constructor ( documents , baseImporter ? ) { this . baseImporter = baseImporter || new NodeJsImporter ( ) ; this . documents = documents ; } async import ( identifier , config ) { return this . importSync ( identifier , config ) ; } importSync ( identifier , config ) { let path = this . filesystemPath ( identifier , config ) ; let clientDocument = path && this . documents . get ( URI . file ( path ) . toString ( ) ) ; if ( clientDocument ) { return { syntax : this . syntax ( identifier , config ) , identifier , defaultName : this . defaultName ( identifier , config ) , contents : clientDocument . getText ( ) , } ; } return this . baseImporter . importSync ( identifier , config ) ; } identifier ( fromIdentifier , importPath , config ) { return this . baseImporter . identifier ( fromIdentifier , importPath , config ) ; } defaultName ( identifier , configuration ) { return this . baseImporter . defaultName ( identifier , configuration ) ; } filesystemPath ( identifier , config ) { return this . baseImporter . filesystemPath ( identifier , config ) ; } debugIdentifier ( identifier , config ) { return this . baseImporter . debugIdentifier ( identifier , config ) ; } syntax ( identifier , config ) { return this . baseImporter . syntax ( identifier , config ) ; } }