summaryrefslogtreecommitdiff
path: root/tools/vscode/packages/server/src/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tools/vscode/packages/server/src/utils.ts')
-rw-r--r--tools/vscode/packages/server/src/utils.ts83
1 files changed, 36 insertions, 47 deletions
diff --git a/tools/vscode/packages/server/src/utils.ts b/tools/vscode/packages/server/src/utils.ts
index c764aae13..f9f1acf34 100644
--- a/tools/vscode/packages/server/src/utils.ts
+++ b/tools/vscode/packages/server/src/utils.ts
@@ -4,68 +4,61 @@ import { Node } from 'vscode-html-languageservice';
/** Normalizes a document URI */
export function normalizeUri(uri: string): string {
- return URI.parse(uri).toString();
+ return URI.parse(uri).toString();
}
/** Turns a URL into a normalized FS Path */
export function urlToPath(stringUrl: string): string | null {
- const url = URI.parse(stringUrl);
- if (url.scheme !== 'file') {
- return null;
- }
- return url.fsPath.replace(/\\/g, '/');
+ const url = URI.parse(stringUrl);
+ if (url.scheme !== 'file') {
+ return null;
+ }
+ return url.fsPath.replace(/\\/g, '/');
}
/** Converts a path to a URL */
export function pathToUrl(path: string) {
- return URI.file(path).toString();
+ return URI.file(path).toString();
}
-
/**
-*
-* The language service is case insensitive, and would provide
-* hover info for Svelte components like `Option` which have
-* the same name like a html tag.
-*/
+ *
+ * The language service is case insensitive, and would provide
+ * hover info for Svelte components like `Option` which have
+ * the same name like a html tag.
+ */
export function isPossibleComponent(node: Node): boolean {
- return !!node.tag?.[0].match(/[A-Z]/);
+ return !!node.tag?.[0].match(/[A-Z]/);
}
/**
-*
-* The language service is case insensitive, and would provide
-* hover info for Svelte components like `Option` which have
-* the same name like a html tag.
-*/
+ *
+ * The language service is case insensitive, and would provide
+ * hover info for Svelte components like `Option` which have
+ * the same name like a html tag.
+ */
export function isPossibleClientComponent(node: Node): boolean {
- return isPossibleComponent(node) && (node.tag?.indexOf(':') ?? -1) > -1;
+ return isPossibleComponent(node) && (node.tag?.indexOf(':') ?? -1) > -1;
}
/** Flattens an array */
export function flatten<T>(arr: T[][]): T[] {
- return arr.reduce((all, item) => [...all, ...item], []);
+ return arr.reduce((all, item) => [...all, ...item], []);
}
/** Clamps a number between min and max */
export function clamp(num: number, min: number, max: number): number {
- return Math.max(min, Math.min(max, num));
+ return Math.max(min, Math.min(max, num));
}
/** Checks if a position is inside range */
export function isInRange(positionToTest: Position, range: Range): boolean {
- return (
- isBeforeOrEqualToPosition(range.end, positionToTest) &&
- isBeforeOrEqualToPosition(positionToTest, range.start)
- );
+ return isBeforeOrEqualToPosition(range.end, positionToTest) && isBeforeOrEqualToPosition(positionToTest, range.start);
}
/** */
export function isBeforeOrEqualToPosition(position: Position, positionToTest: Position): boolean {
- return (
- positionToTest.line < position.line ||
- (positionToTest.line === position.line && positionToTest.character <= position.character)
- );
+ return positionToTest.line < position.line || (positionToTest.line === position.line && positionToTest.character <= position.character);
}
/**
@@ -76,23 +69,19 @@ export function isBeforeOrEqualToPosition(position: Position, positionToTest: Po
* @param determineIfSame The function which determines if the previous invocation should be canceld or not
* @param miliseconds Number of miliseconds to debounce
*/
-export function debounceSameArg<T>(
- fn: (arg: T) => void,
- shouldCancelPrevious: (newArg: T, prevArg?: T) => boolean,
- miliseconds: number
-): (arg: T) => void {
- let timeout: any;
- let prevArg: T | undefined;
+export function debounceSameArg<T>(fn: (arg: T) => void, shouldCancelPrevious: (newArg: T, prevArg?: T) => boolean, miliseconds: number): (arg: T) => void {
+ let timeout: any;
+ let prevArg: T | undefined;
- return (arg: T) => {
- if (shouldCancelPrevious(arg, prevArg)) {
- clearTimeout(timeout);
- }
+ return (arg: T) => {
+ if (shouldCancelPrevious(arg, prevArg)) {
+ clearTimeout(timeout);
+ }
- prevArg = arg;
- timeout = setTimeout(() => {
- fn(arg);
- prevArg = undefined;
- }, miliseconds);
- };
+ prevArg = arg;
+ timeout = setTimeout(() => {
+ fn(arg);
+ prevArg = undefined;
+ }, miliseconds);
+ };
}