@shopify/theme-language-server-common
Version:
<h1 align="center" style="position: relative;" > <br> <img src="https://github.com/Shopify/theme-check-vscode/blob/main/images/shopify_glyph.png?raw=true" alt="logo" width="141" height="160"> <br> Theme Language Server </h1>
35 lines (31 loc) • 1.11 kB
text/typescript
import { RawMatcherFn } from '@vitest/expect';
import { TextEdit } from 'vscode-languageserver-protocol';
import { TextDocument } from 'vscode-languageserver-textdocument';
interface CustomMatchers<R = unknown> {
applyEdits: (source: string | TextDocument, expected: string) => R;
}
declare module 'vitest' {
interface Assertion<T = any> extends CustomMatchers<TextEdit | TextEdit[]> {}
interface AsymmetricMatchersContaining extends CustomMatchers {}
}
export const applyEdits: RawMatcherFn = (
received: TextEdit | TextEdit[],
source: TextDocument | string,
expected: string,
) => {
const textDocument =
typeof source === 'string'
? TextDocument.create('file:///file.liquid', 'liquid', 1, source.replace('█', ''))
: source;
const actual = TextDocument.applyEdits(
textDocument,
Array.isArray(received) ? received : [received],
);
return {
message: () => `expected following edit[1] to change source[2] to equal expected[3]
[1]: ${JSON.stringify(received, null, 2)}
[2]: ${textDocument.getText()}
[3]: ${expected}`,
pass: actual === expected,
};
};