strict warnings in pathCompletion

This commit is contained in:
Martin Aeschlimann
2018-08-27 12:13:15 +02:00
parent bfa0463154
commit 1047f48993
2 changed files with 20 additions and 14 deletions

View File

@@ -63,16 +63,19 @@ function shouldDoPathCompletion(tag: string, attr: string, value: string) {
* Get a list of path suggestions. Folder suggestions are suffixed with a slash.
*/
function providePaths(valueBeforeCursor: string, activeDocFsPath: string, root?: string): string[] {
if (startsWith(valueBeforeCursor, '/') && !root) {
return [];
}
const lastIndexOfSlash = valueBeforeCursor.lastIndexOf('/');
const valueBeforeLastSlash = valueBeforeCursor.slice(0, lastIndexOfSlash + 1);
const parentDir = startsWith(valueBeforeCursor, '/')
? path.resolve(root, '.' + valueBeforeLastSlash)
: path.resolve(activeDocFsPath, '..', valueBeforeLastSlash);
const startsWithSlash = startsWith(valueBeforeCursor, '/');
let parentDir: string;
if (startsWithSlash) {
if (!root) {
return [];
}
parentDir = path.resolve(root, '.' + valueBeforeLastSlash);
} else {
parentDir = path.resolve(activeDocFsPath, '..', valueBeforeLastSlash);
}
try {
return fs.readdirSync(parentDir).map(f => {