mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
correctly handle new value and range from html service
This commit is contained in:
@@ -75,7 +75,7 @@ export function providePathSuggestions(value: string, range: Range, activeDocFsP
|
||||
return [];
|
||||
}
|
||||
|
||||
const replaceRange = Range.create(Position.create(range.end.line, range.end.character - valueAfterLastSlash.length), range.end);
|
||||
const replaceRange = getReplaceRange(range, valueAfterLastSlash);
|
||||
|
||||
return fs.readdirSync(parentDir).map(f => {
|
||||
return {
|
||||
@@ -98,6 +98,12 @@ function resolveWorkspaceRoot(activeDoc: TextDocument, workspaceFolders: Propose
|
||||
}
|
||||
}
|
||||
|
||||
function getReplaceRange(valueRange: Range, valueAfterLastSlash: string): Range {
|
||||
const start = Position.create(valueRange.end.line, valueRange.end.character - 1 - valueAfterLastSlash.length);
|
||||
const end = Position.create(valueRange.end.line, valueRange.end.character - 1);
|
||||
return Range.create(start, end);
|
||||
}
|
||||
|
||||
// Selected from https://stackoverflow.com/a/2725168/1780148
|
||||
const PATH_TAG_AND_ATTR: { [tag: string]: string | string[] } = {
|
||||
// HTML 4
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import 'mocha';
|
||||
import * as assert from 'assert';
|
||||
import * as path from 'path';
|
||||
import Uri from 'vscode-uri';
|
||||
import { TextDocument, CompletionList, CompletionItemKind, } from 'vscode-languageserver-types';
|
||||
import { getLanguageModes } from '../modes/languageModes';
|
||||
import { applyEdits } from '../utils/edits';
|
||||
@@ -92,7 +93,7 @@ suite('Completions', () => {
|
||||
]
|
||||
});
|
||||
});
|
||||
/*
|
||||
|
||||
test('Path completion', function (): any {
|
||||
let testUri = Uri.file(path.resolve(__dirname, '../../test/pathCompletionFixtures/foo.html')).fsPath;
|
||||
|
||||
@@ -101,33 +102,34 @@ suite('Completions', () => {
|
||||
{ label: 'about.html', resultText: '<div><a href="about/about.html">' }
|
||||
]
|
||||
}, testUri);
|
||||
assertCompletions(`<div><a href=about/|>`, {
|
||||
items: [
|
||||
{ label: 'about.html', resultText: `<div><a href=about/about.html>` }
|
||||
]
|
||||
}, testUri);
|
||||
// Unquoted value is not supported in language service yet
|
||||
// assertCompletions(`<div><a href=about/|>`, {
|
||||
// items: [
|
||||
// { label: 'about.html', resultText: `<div><a href=about/about.html>` }
|
||||
// ]
|
||||
// }, testUri);
|
||||
assertCompletions(`<div><a href='about/|'>`, {
|
||||
items: [
|
||||
{ label: 'about.html', resultText: `<div><a href='about/about.html'>` }
|
||||
]
|
||||
}, testUri);
|
||||
assertCompletions('<div><a href="about/about|.xml">', {
|
||||
items: [
|
||||
{ label: 'about.html', resultText: '<div><a href="about/about.html">' }
|
||||
]
|
||||
}, testUri);
|
||||
// Don't think this is a common use case
|
||||
// assertCompletions('<div><a href="about/about|.xml">', {
|
||||
// items: [
|
||||
// { label: 'about.html', resultText: '<div><a href="about/about.html">' }
|
||||
// ]
|
||||
// }, testUri);
|
||||
assertCompletions('<div><a href="about/a|">', {
|
||||
items: [
|
||||
{ label: 'about.html', resultText: '<div><a href="about/about.html">' }
|
||||
]
|
||||
}, testUri);
|
||||
assertCompletions('<div><a href="|">', {
|
||||
items: [
|
||||
{ label: 'index.html', resultText: '<div><a href="index.html">' },
|
||||
{ label: 'about', resultText: '<div><a href="about/">' }
|
||||
]
|
||||
}, testUri);
|
||||
|
||||
// We should not prompt suggestion before user enters any trigger character
|
||||
// assertCompletions('<div><a href="|">', {
|
||||
// items: [
|
||||
// { label: 'index.html', resultText: '<div><a href="index.html">' },
|
||||
// { label: 'about', resultText: '<div><a href="about/">' }
|
||||
// ]
|
||||
// }, testUri);
|
||||
});
|
||||
*/
|
||||
});
|
||||
@@ -140,9 +140,12 @@ suite('Path Completion - TextEdit', () => {
|
||||
assert.equal(suggestions[1].textEdit.newText, 'index.html');
|
||||
assert.equal(suggestions[2].textEdit.newText, 'src');
|
||||
|
||||
assert.equal(suggestions[0].textEdit.range.start.character, 5);
|
||||
assert.equal(suggestions[1].textEdit.range.start.character, 5);
|
||||
assert.equal(suggestions[2].textEdit.range.start.character, 5);
|
||||
assert.equal(suggestions[0].textEdit.range.start.character, 4);
|
||||
assert.equal(suggestions[1].textEdit.range.start.character, 4);
|
||||
assert.equal(suggestions[2].textEdit.range.start.character, 4);
|
||||
|
||||
assert.equal(suggestions[0].textEdit.range.end.character, 4);
|
||||
assert.equal(suggestions[1].textEdit.range.end.character, 4);
|
||||
assert.equal(suggestions[2].textEdit.range.end.character, 4);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user