66
77import * as nodes from '../../parser/cssNodes' ;
88import { assertSymbolsInScope , assertScopesAndSymbols , assertHighlights , assertColorSymbols , assertLinks , newRange , getTestResource , assertDocumentSymbols } from '../css/navigation.test' ;
9- import { getSCSSLanguageService , DocumentLink , TextDocument , SymbolKind , LanguageSettings } from '../../cssLanguageService' ;
9+ import { getSCSSLanguageService , DocumentLink , TextDocument , SymbolKind , LanguageSettings , DocumentContext } from '../../cssLanguageService' ;
1010import * as assert from 'assert' ;
1111import * as path from 'path' ;
1212import { URI } from 'vscode-uri' ;
@@ -20,11 +20,11 @@ function getSCSSLS() {
2020function aliasSettings ( ) : LanguageSettings {
2121 return {
2222 "importAliases" : {
23- "@SassStylesheet" : "/src/assets/styles.scss" ,
24- "@NoUnderscoreDir/" : "/noUnderscore/" ,
25- "@UnderscoreDir/" : "/underscore/" ,
26- "@BothDir/" : "/both/" ,
27- }
23+ "@SassStylesheet" : "/src/assets/styles.scss" ,
24+ "@NoUnderscoreDir/" : "/noUnderscore/" ,
25+ "@UnderscoreDir/" : "/underscore/" ,
26+ "@BothDir/" : "/both/" ,
27+ }
2828 } ;
2929}
3030
@@ -57,6 +57,21 @@ async function assertNoDynamicLinks(docUri: string, input: string, extecedTarget
5757
5858}
5959
60+ function createDocument ( contents : string , uri = 'file:///test.scss' ) {
61+ return TextDocument . create ( uri , 'scss' , 0 , contents ) ;
62+ }
63+
64+ const dummyContext : DocumentContext = {
65+ resolveReference : ( ref : string , _base : string ) => ref
66+ } ;
67+
68+ async function getLinks ( contents : string ) {
69+ const ls = getSCSSLS ( ) ;
70+ const doc = createDocument ( contents ) ;
71+ const stylesheet = ls . parseStylesheet ( doc ) ;
72+ return ls . findDocumentLinks2 ( doc , stylesheet , dummyContext ) ;
73+ }
74+
6075suite ( 'SCSS - Navigation' , ( ) => {
6176
6277 suite ( 'Scopes and Symbols' , ( ) => {
@@ -353,4 +368,42 @@ suite('SCSS - Navigation', () => {
353368 } ) ;
354369 } ) ;
355370
371+ suite ( 'URL Scheme Imports' , ( ) => {
372+
373+ test ( 'http scheme import is treated as absolute URL, not bare import' , async ( ) => {
374+ const links = await getLinks ( `@import "http://example.com/foo.css";` ) ;
375+ assert . strictEqual ( links . length , 1 ) ;
376+ assert . strictEqual ( links [ 0 ] . target , 'http://example.com/foo.css' ) ;
377+ } ) ;
378+
379+ test ( 'https scheme import is treated as absolute URL, not bare import' , async ( ) => {
380+ const links = await getLinks ( `@import "https://cdn.example.com/reset.css";` ) ;
381+ assert . strictEqual ( links . length , 1 ) ;
382+ assert . strictEqual ( links [ 0 ] . target , 'https://cdn.example.com/reset.css' ) ;
383+ } ) ;
384+
385+ test ( 'file scheme import is treated as absolute URL, not bare import' , async ( ) => {
386+ const links = await getLinks ( `@import "file:///Users/test/project/styles/base.scss";` ) ;
387+ assert . strictEqual ( links . length , 1 ) ;
388+ assert . strictEqual ( links [ 0 ] . target , 'file:///Users/test/project/styles/base.scss' ) ;
389+ } ) ;
390+
391+ test ( 'custom scheme import (vscode-resource) is treated as absolute URL, not bare import' , async ( ) => {
392+ const links = await getLinks ( `@import "vscode-resource://file/some.css";` ) ;
393+ assert . strictEqual ( links . length , 1 ) ;
394+ assert . strictEqual ( links [ 0 ] . target , 'vscode-resource://file/some.css' ) ;
395+ } ) ;
396+ } ) ;
397+
398+ suite ( 'Bare Imports' , ( ) => {
399+
400+ test ( 'resolves bare import path on Windows' , async ( ) => {
401+ const ls = getSCSSLS ( ) ;
402+
403+ const doc = TextDocument . create ( 'file:///c:/proj/app.scss' , 'scss' , 1 , "@import 'bootstrap/scss/variables';" ) ;
404+ const links = await ls . findDocumentLinks2 ( doc , ls . parseStylesheet ( doc ) , getDocumentContext ( 'c:/proj' ) ) ;
405+ const expected = URI . file ( 'c:/proj/node_modules/bootstrap/scss/_variables.scss' ) . toString ( ) ;
406+ assert . strictEqual ( links [ 0 ] . target , expected ) ;
407+ } ) ;
408+ } ) ;
356409} ) ;
0 commit comments