Run prettier on language service
This commit is contained in:
@@ -1,26 +1,24 @@
|
||||
import { getPositionFromCursor } from "./cursor-position";
|
||||
import {getPositionFromCursor} from "./cursor-position";
|
||||
|
||||
describe("getPositionFromCursor", () => {
|
||||
it("returns the position of the cursor and the document without that cursor", () => {
|
||||
const input = "on: push\njobs:|";
|
||||
const [newDoc, position] = getPositionFromCursor(input);
|
||||
|
||||
expect(position).toEqual({ line: 1, character: 5 });
|
||||
expect(position).toEqual({line: 1, character: 5});
|
||||
expect(newDoc.getText()).toEqual("on: push\njobs:");
|
||||
});
|
||||
|
||||
it("throws an error if no cursor is found", () => {
|
||||
const input = "on: push\njobs:";
|
||||
expect(() => getPositionFromCursor(input)).toThrowError(
|
||||
"No cursor found in document"
|
||||
);
|
||||
expect(() => getPositionFromCursor(input)).toThrowError("No cursor found in document");
|
||||
});
|
||||
|
||||
it("handles a cursor at the beginning of the document", () => {
|
||||
const input = "|on: push\njobs:";
|
||||
const [newDoc, position] = getPositionFromCursor(input);
|
||||
|
||||
expect(position).toEqual({ line: 0, character: 0 });
|
||||
expect(position).toEqual({line: 0, character: 0});
|
||||
expect(newDoc.getText()).toEqual("on: push\njobs:");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TextDocument, Position } from "vscode-languageserver-textdocument";
|
||||
import {TextDocument, Position} from "vscode-languageserver-textdocument";
|
||||
|
||||
// Calculates the position of the cursor and the document without that cursor
|
||||
// Cursor is represented by a `|` character
|
||||
@@ -11,12 +11,7 @@ export function getPositionFromCursor(input: string): [TextDocument, Position] {
|
||||
}
|
||||
|
||||
const position = doc.positionAt(cursorIndex);
|
||||
const newDoc = TextDocument.create(
|
||||
doc.uri,
|
||||
doc.languageId,
|
||||
doc.version,
|
||||
doc.getText().replace("|", "")
|
||||
);
|
||||
const newDoc = TextDocument.create(doc.uri, doc.languageId, doc.version, doc.getText().replace("|", ""));
|
||||
|
||||
return [newDoc, position];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user