Run prettier on language service

This commit is contained in:
Josh Gross
2022-11-15 14:08:12 -05:00
parent 85ee2f6bb0
commit 3a816b2a74
16 changed files with 139 additions and 231 deletions
@@ -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];
}