Merge pull request #87 from github/thyeggman/token-completion-range
Set completion range for invalid token key
This commit is contained in:
@@ -372,6 +372,36 @@ jobs:
|
||||
});
|
||||
});
|
||||
|
||||
it("sets a range for token key", async () => {
|
||||
const input = "on: push\njobs:\n build:\n runs-o|";
|
||||
const result = await complete(...getPositionFromCursor(input));
|
||||
|
||||
expect(result).not.toBeUndefined();
|
||||
expect(result.map(e => e.label)).toContain("runs-on");
|
||||
|
||||
let textEdit = result.filter(e => e.label === "runs-on")[0].textEdit as TextEdit;
|
||||
expect(textEdit.newText).toEqual("runs-on");
|
||||
expect(textEdit.range).toEqual({
|
||||
start: {line: 3, character: 4},
|
||||
end: {line: 3, character: 10}
|
||||
});
|
||||
});
|
||||
|
||||
it("sets a 0-length range while no initial token key", async () => {
|
||||
const input = "on: push\njobs:\n build:\n |";
|
||||
const result = await complete(...getPositionFromCursor(input));
|
||||
|
||||
expect(result).not.toBeUndefined();
|
||||
expect(result.map(e => e.label)).toContain("runs-on");
|
||||
|
||||
let textEdit = result.filter(e => e.label === "runs-on")[0].textEdit as TextEdit;
|
||||
expect(textEdit.newText).toEqual("runs-on");
|
||||
expect(textEdit.range).toEqual({
|
||||
start: {line: 3, character: 4},
|
||||
end: {line: 3, character: 4}
|
||||
});
|
||||
});
|
||||
|
||||
describe("completes with indentation", () => {
|
||||
it("default indentation", async () => {
|
||||
const input = `on: push
|
||||
|
||||
@@ -112,6 +112,12 @@ export async function complete(
|
||||
let replaceRange: Range | undefined;
|
||||
if (token?.range) {
|
||||
replaceRange = mapRange(token.range);
|
||||
} else if (!token) {
|
||||
// Not a valid token, create a range from the current position
|
||||
const line = newDoc.getText({start: {line: position.line, character: 0}, end: position});
|
||||
// Get the length of the current word
|
||||
const val = line.match(/[\w_-]*$/)?.[0].length || 0;
|
||||
replaceRange = Range.create({line: position.line, character: position.character - val}, position);
|
||||
}
|
||||
|
||||
return values.map(value => {
|
||||
|
||||
Reference in New Issue
Block a user