提交 d9d762d1 编写于 作者: M Martin Aeschlimann

[css] .asar file breaks CSS path completion. Fixes #46638

上级 9e0374f2
......@@ -10,7 +10,7 @@ import URI from 'vscode-uri';
import { TextDocument, CompletionList, CompletionItemKind, CompletionItem, TextEdit, Range, Position } from 'vscode-languageserver-types';
import { WorkspaceFolder } from 'vscode-languageserver';
import { ICompletionParticipant } from 'vscode-css-languageservice';
import { ICompletionParticipant, URILiteralCompletionContext } from 'vscode-css-languageservice';
import { startsWith } from './utils/strings';
......@@ -20,7 +20,7 @@ export function getPathCompletionParticipant(
result: CompletionList
): ICompletionParticipant {
return {
onURILiteralValue: (context: { uriValue: string, position: Position, range: Range; }) => {
onURILiteralValue: (context: URILiteralCompletionContext) => {
if (!workspaceFolders || workspaceFolders.length === 0) {
return;
}
......@@ -91,7 +91,11 @@ export function providePathSuggestions(value: string, range: Range, activeDocFsP
}
const isDir = (p: string) => {
return fs.statSync(p).isDirectory();
try {
return fs.statSync(p).isDirectory();
} catch (e) {
return false;
}
};
function resolveWorkspaceRoot(activeDoc: TextDocument, workspaceFolders: WorkspaceFolder[]): string | undefined {
......
......@@ -77,5 +77,19 @@ suite('Completions', () => {
{ label: 'src/', resultText: `html { background-image: url('../src/')` }
]
}, testUri);
assertCompletions(`html { background-image: url('../src/a|')`, {
items: [
{ label: 'feature.js', resultText: `html { background-image: url('../src/feature.js')` },
{ label: 'data/', resultText: `html { background-image: url('../src/data/')` },
{ label: 'test.js', resultText: `html { background-image: url('../src/test.js')` }
]
}, testUri);
assertCompletions(`html { background-image: url('../src/data/f|.asar')`, {
items: [
{ label: 'foo.asar', resultText: `html { background-image: url('../src/data/foo.asar')` }
]
}, testUri);
});
});
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
\ No newline at end of file
......@@ -82,7 +82,7 @@ function providePaths(valueBeforeCursor: string, activeDocFsPath: string, root?:
try {
return fs.readdirSync(parentDir).map(f => {
return fs.statSync(path.resolve(parentDir, f)).isDirectory()
return isDir(path.resolve(parentDir, f))
? f + '/'
: f;
});
......@@ -91,6 +91,14 @@ function providePaths(valueBeforeCursor: string, activeDocFsPath: string, root?:
}
}
function isDir(p: string) {
try {
return fs.statSync(p).isDirectory();
} catch (e) {
return false;
}
}
function pathToSuggestion(p: string, valueBeforeCursor: string, fullValue: string, range: Range): CompletionItem {
const isDir = p[p.length - 1] === '/';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册