Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed May 28, 2021
1 parent 86c8a58 commit fc554e6
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/services/cssNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import {
Color, ColorInformation, ColorPresentation, DocumentHighlight, DocumentHighlightKind, DocumentLink, Location,
Position, Range, SymbolInformation, SymbolKind, TextEdit, WorkspaceEdit, TextDocument, DocumentContext, FileSystemProvider, DocumentUri, FileType
Position, Range, SymbolInformation, SymbolKind, TextEdit, WorkspaceEdit, TextDocument, DocumentContext, FileSystemProvider, FileType
} from '../cssLanguageTypes';
import * as nls from 'vscode-nls';
import * as nodes from '../parser/cssNodes';
Expand All @@ -17,6 +17,8 @@ import { dirname, joinPath } from '../utils/resources';

const localize = nls.loadMessageBundle();

type UnresolvedLinkData = { link: DocumentLink, isRawLink: boolean }

export class CSSNavigation {

constructor(protected fileSystemProvider: FileSystemProvider | undefined) {
Expand Down Expand Up @@ -96,26 +98,30 @@ export class CSSNavigation {
}

public findDocumentLinks(document: TextDocument, stylesheet: nodes.Stylesheet, documentContext: DocumentContext): DocumentLink[] {
const links = this.findUnresolvedLinks(document, stylesheet);
for (let i = 0; i < links.length; i++) {
const target = links[i].target;
const linkData = this.findUnresolvedLinks(document, stylesheet);
const resolvedLinks: DocumentLink[] = [];
for (let data of linkData) {
const link = data.link;
const target = link.target;
if (target && !(/^\w+:\/\//g.test(target))) {
const resolved = documentContext.resolveReference(target, document.uri);
if (resolved) {
links[i].target = resolved;
link.target = resolved;
}
}
resolvedLinks.push(link);
}
return links;
return resolvedLinks;
}

public async findDocumentLinks2(document: TextDocument, stylesheet: nodes.Stylesheet, documentContext: DocumentContext): Promise<DocumentLink[]> {
const links = this.findUnresolvedLinks(document, stylesheet);
const linkData = this.findUnresolvedLinks(document, stylesheet);
const resolvedLinks: DocumentLink[] = [];
for (let link of links) {
for (let data of linkData) {
const link = data.link;
const target = link.target;
if (target && !(/^\w+:\/\//g.test(target))) {
const resolvedTarget = await this.resolveRelativeReference(target, document.uri, documentContext, link.isRawLink);
const resolvedTarget = await this.resolveRelativeReference(target, document.uri, documentContext, data.isRawLink);
if (resolvedTarget !== undefined) {
link.target = resolvedTarget;
resolvedLinks.push(link);
Expand All @@ -128,8 +134,8 @@ export class CSSNavigation {
}


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

const collect = (uriStringNode: nodes.Node) => {
let rawUri = uriStringNode.getText();
Expand All @@ -144,7 +150,7 @@ export class CSSNavigation {
}

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

stylesheet.accept(candidate => {
Expand Down

0 comments on commit fc554e6

Please sign in to comment.