Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanp413 committed May 3, 2021
1 parent 9655cf1 commit 19982f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
12 changes: 7 additions & 5 deletions src/services/cssNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class CSSNavigation {
for (let link of links) {
const target = link.target;
if (target && !(/^\w+:\/\//g.test(target))) {
const resolvedTarget = await this.resolveRelativeReference(target, document.uri, documentContext);
const resolvedTarget = await this.resolveRelativeReference(target, document.uri, documentContext, link.isRawLink);
if (resolvedTarget !== undefined) {
link.target = resolvedTarget;
resolvedLinks.push(link);
Expand All @@ -128,8 +128,8 @@ export class CSSNavigation {
}


private findUnresolvedLinks(document: TextDocument, stylesheet: nodes.Stylesheet): DocumentLink[] {
const result: DocumentLink[] = [];
private findUnresolvedLinks(document: TextDocument, stylesheet: nodes.Stylesheet): (DocumentLink & { isRawLink: boolean })[] {
const result: (DocumentLink & { isRawLink: boolean })[] = [];

const collect = (uriStringNode: nodes.Node) => {
let rawUri = uriStringNode.getText();
Expand All @@ -142,7 +142,9 @@ export class CSSNavigation {
if (startsWith(rawUri, `'`) || startsWith(rawUri, `"`)) {
rawUri = rawUri.slice(1, -1);
}
result.push({ target: rawUri, range });

const isRawLink = uriStringNode.parent ? this.isRawStringDocumentLinkNode(uriStringNode.parent) : false;
result.push({ target: rawUri, range, isRawLink });
};

stylesheet.accept(candidate => {
Expand Down Expand Up @@ -275,7 +277,7 @@ export class CSSNavigation {
};
}

protected async resolveRelativeReference(ref: string, documentUri: string, documentContext: DocumentContext): Promise<string | undefined> {
protected async resolveRelativeReference(ref: string, documentUri: string, documentContext: DocumentContext, isRawLink?: boolean): Promise<string | undefined> {
// Following [css-loader](https://github.com/webpack-contrib/css-loader#url)
// and [sass-loader's](https://github.com/webpack-contrib/sass-loader#imports)
// convention, if an import path starts with ~ then use node module resolution
Expand Down
25 changes: 11 additions & 14 deletions src/services/scssNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,24 @@ export class SCSSNavigation extends CSSNavigation {
);
}

protected async resolveRelativeReference(ref: string, documentUri: string, documentContext: DocumentContext): Promise<string | undefined> {
protected async resolveRelativeReference(ref: string, documentUri: string, documentContext: DocumentContext, isRawLink?: boolean): Promise<string | undefined> {
if (startsWith(ref, 'sass:')) {
return undefined; // sass library
}
const target = await super.resolveRelativeReference(ref, documentUri, documentContext);
if (this.fileSystemProvider && target) {
const target = await super.resolveRelativeReference(ref, documentUri, documentContext, isRawLink);
if (this.fileSystemProvider && target && isRawLink) {
const parsedUri = URI.parse(target);
if (parsedUri.path && Utils.extname(parsedUri).length === 0) {
try {
const pathVariations = toPathVariations(parsedUri);
if (pathVariations) {
for (let j = 0; j < pathVariations.length; j++) {
if (await this.fileExists(pathVariations[j])) {
return pathVariations[j];
}
try {
const pathVariations = toPathVariations(parsedUri);
if (pathVariations) {
for (let j = 0; j < pathVariations.length; j++) {
if (await this.fileExists(pathVariations[j])) {
return pathVariations[j];
}
}
return undefined;
} catch (e) {
// ignore
}
} catch (e) {
// ignore
}
}
return target;
Expand Down

0 comments on commit 19982f0

Please sign in to comment.