decide multiline per language
This commit is contained in:
parent
c15e9787d9
commit
35ba50ff1d
2 changed files with 42 additions and 4 deletions
|
|
@ -346,10 +346,16 @@ export async function getTabCompletion(
|
|||
...lang.topLevelKeywords.map((word) => `\n${word}`),
|
||||
];
|
||||
|
||||
const multiline =
|
||||
!input.selectedCompletionInfo && // Only ever single-line if using intellisense selected value
|
||||
options.multilineCompletions !== "never" &&
|
||||
(options.multilineCompletions === "always" || completeMultiline);
|
||||
let langMultilineDecision = lang.useMultiline?.({ prefix, suffix });
|
||||
let multiline: boolean = false;
|
||||
if (langMultilineDecision) {
|
||||
multiline = langMultilineDecision;
|
||||
} else {
|
||||
multiline =
|
||||
!input.selectedCompletionInfo && // Only ever single-line if using intellisense selected value
|
||||
options.multilineCompletions !== "never" &&
|
||||
(options.multilineCompletions === "always" || completeMultiline);
|
||||
}
|
||||
|
||||
// Try to reuse pending requests if what the user typed matches start of completion
|
||||
const generator = generatorReuseManager.getGenerator(
|
||||
|
|
@ -391,8 +397,10 @@ export async function getTabCompletion(
|
|||
);
|
||||
charGenerator = bracketMatchingService.stopOnUnmatchedClosingBracket(
|
||||
charGenerator,
|
||||
prefix,
|
||||
suffix,
|
||||
filepath,
|
||||
multiline,
|
||||
);
|
||||
|
||||
let lineGenerator = streamLines(charGenerator);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@ export interface AutocompleteLanguageInfo {
|
|||
endOfLine: string[];
|
||||
stopWords?: string[];
|
||||
lineFilters?: LineFilter[];
|
||||
useMultiline?: (args: {
|
||||
prefix: string;
|
||||
suffix: string;
|
||||
}) => boolean | undefined;
|
||||
}
|
||||
|
||||
// TypeScript
|
||||
|
|
@ -253,6 +257,30 @@ export const YAML: AutocompleteLanguageInfo = {
|
|||
],
|
||||
};
|
||||
|
||||
export const Markdown: AutocompleteLanguageInfo = {
|
||||
topLevelKeywords: [],
|
||||
singleLineComment: "",
|
||||
endOfLine: [],
|
||||
useMultiline: ({ prefix, suffix }) => {
|
||||
const singleLineStarters = ["- ", "* ", /^\d+\. /, "> ", "```", /^#{1,6} /];
|
||||
let currentLine = prefix.split("\n").pop();
|
||||
if (!currentLine) {
|
||||
return undefined;
|
||||
}
|
||||
currentLine = currentLine.trim();
|
||||
for (const starter of singleLineStarters) {
|
||||
if (
|
||||
typeof starter === "string"
|
||||
? currentLine.startsWith(starter)
|
||||
: starter.test(currentLine)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
|
||||
export const LANGUAGES: { [extension: string]: AutocompleteLanguageInfo } = {
|
||||
ts: Typescript,
|
||||
js: Typescript,
|
||||
|
|
@ -291,4 +319,6 @@ export const LANGUAGES: { [extension: string]: AutocompleteLanguageInfo } = {
|
|||
dart: Dart,
|
||||
sol: Solidity,
|
||||
yaml: YAML,
|
||||
yml: YAML,
|
||||
md: Markdown,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue