mirror of
https://github.com/EthanMarti/infio-copilot.git
synced 2026-06-12 08:01:02 +00:00
init
This commit is contained in:
34
src/core/autocomplete/pre-processors/data-view-remover.ts
Normal file
34
src/core/autocomplete/pre-processors/data-view-remover.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { generateRandomString } from "../utils";
|
||||
import Context from "../context-detection";
|
||||
import { PrefixAndSuffix, PreProcessor } from "../types";
|
||||
|
||||
const DATA_VIEW_REGEX = /```dataview(js){0,1}(.|\n)*?```/gm;
|
||||
const UNIQUE_CURSOR = `${generateRandomString(16)}`;
|
||||
|
||||
class DataViewRemover implements PreProcessor {
|
||||
process(prefix: string, suffix: string, context: Context): PrefixAndSuffix {
|
||||
let text = prefix + UNIQUE_CURSOR + suffix;
|
||||
text = text.replace(DATA_VIEW_REGEX, "");
|
||||
const [prefixNew, suffixNew] = text.split(UNIQUE_CURSOR);
|
||||
|
||||
return { prefix: prefixNew, suffix: suffixNew };
|
||||
}
|
||||
|
||||
removesCursor(prefix: string, suffix: string): boolean {
|
||||
const text = prefix + UNIQUE_CURSOR + suffix;
|
||||
const dataviewAreasWithCursor = text
|
||||
.match(DATA_VIEW_REGEX)
|
||||
?.filter((dataviewArea) => dataviewArea.includes(UNIQUE_CURSOR));
|
||||
|
||||
if (
|
||||
dataviewAreasWithCursor !== undefined &&
|
||||
dataviewAreasWithCursor.length > 0
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default DataViewRemover;
|
||||
24
src/core/autocomplete/pre-processors/length-limiter.ts
Normal file
24
src/core/autocomplete/pre-processors/length-limiter.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import Context from "../context-detection";
|
||||
import { PrefixAndSuffix, PreProcessor } from "../types";
|
||||
|
||||
class LengthLimiter implements PreProcessor {
|
||||
private readonly maxPrefixChars: number;
|
||||
private readonly maxSuffixChars: number;
|
||||
|
||||
constructor(maxPrefixChars: number, maxSuffixChars: number) {
|
||||
this.maxPrefixChars = maxPrefixChars;
|
||||
this.maxSuffixChars = maxSuffixChars;
|
||||
}
|
||||
|
||||
process(prefix: string, suffix: string, context: Context): PrefixAndSuffix {
|
||||
prefix = prefix.slice(-this.maxPrefixChars);
|
||||
suffix = suffix.slice(0, this.maxSuffixChars);
|
||||
return { prefix, suffix };
|
||||
}
|
||||
|
||||
removesCursor(prefix: string, suffix: string): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default LengthLimiter;
|
||||
Reference in New Issue
Block a user