55'use strict' ;
66
77import {
8- Color , ColorInformation , ColorPresentation , DocumentHighlight , DocumentHighlightKind , DocumentLink , Location ,
8+ AliasSettings , Color , ColorInformation , ColorPresentation , DocumentHighlight , DocumentHighlightKind , DocumentLink , Location ,
99 Position , Range , SymbolInformation , SymbolKind , TextEdit , WorkspaceEdit , TextDocument , DocumentContext , FileSystemProvider , FileType , DocumentSymbol
1010} from '../cssLanguageTypes' ;
1111import * as l10n from '@vscode/l10n' ;
@@ -24,10 +24,15 @@ const startsWithSchemeRegex = /^\w+:\/\//;
2424const startsWithData = / ^ d a t a : / ;
2525
2626export class CSSNavigation {
27+ protected defaultSettings ?: AliasSettings ;
2728
2829 constructor ( protected fileSystemProvider : FileSystemProvider | undefined , private readonly resolveModuleReferences : boolean ) {
2930 }
3031
32+ public configure ( settings : AliasSettings | undefined ) {
33+ this . defaultSettings = settings ;
34+ }
35+
3136 public findDefinition ( document : TextDocument , position : Position , stylesheet : nodes . Node ) : Location | null {
3237
3338 const symbols = new Symbols ( stylesheet ) ;
@@ -228,7 +233,7 @@ export class CSSNavigation {
228233 if ( ! selectionRange || ! containsRange ( range , selectionRange ) ) {
229234 selectionRange = Range . create ( range . start , range . start ) ;
230235 }
231-
236+
232237 const entry : DocumentSymbol = {
233238 name : name || l10n . t ( '<undefined>' ) ,
234239 kind,
@@ -376,7 +381,7 @@ export class CSSNavigation {
376381 return target ;
377382 }
378383
379- protected async resolveReference ( target : string , documentUri : string , documentContext : DocumentContext , isRawLink = false ) : Promise < string | undefined > {
384+ protected async resolveReference ( target : string , documentUri : string , documentContext : DocumentContext , isRawLink = false , settings = this . defaultSettings ) : Promise < string | undefined > {
380385
381386 // Following [css-loader](https://github.com/webpack-contrib/css-loader#url)
382387 // and [sass-loader's](https://github.com/webpack-contrib/sass-loader#imports)
@@ -403,6 +408,26 @@ export class CSSNavigation {
403408 return moduleReference ;
404409 }
405410 }
411+
412+ // Try resolving the reference from the language configuration alias settings
413+ if ( ref && ! ( await this . fileExists ( ref ) ) ) {
414+ const rootFolderUri = documentContext . resolveReference ( '/' , documentUri ) ;
415+ if ( settings && rootFolderUri ) {
416+ // Specific file reference
417+ if ( target in settings ) {
418+ return this . mapReference ( joinPath ( rootFolderUri , settings [ target ] ) , isRawLink ) ;
419+ }
420+ // Reference folder
421+ const firstSlash = target . indexOf ( '/' ) ;
422+ const prefix = `${ target . substring ( 0 , firstSlash ) } /` ;
423+ if ( prefix in settings ) {
424+ const aliasPath = ( settings [ prefix ] ) . slice ( 0 , - 1 ) ;
425+ let newPath = joinPath ( rootFolderUri , aliasPath ) ;
426+ return this . mapReference ( newPath = joinPath ( newPath , target . substring ( prefix . length - 1 ) ) , isRawLink ) ;
427+ }
428+ }
429+ }
430+
406431 // fall back. it might not exists
407432 return ref ;
408433 }
@@ -522,4 +547,4 @@ function getModuleNameFromPath(path: string) {
522547 }
523548 // Otherwise get until first instance of '/'
524549 return path . substring ( 0 , firstSlash ) ;
525- }
550+ }
0 commit comments