| 1 | import { AutocompleteLanguageInfo } from "../constants/AutocompleteLanguageInfo"; |
| 2 | import { HelperVars } from "../util/HelperVars"; |
| 3 | |
| 4 | function isMidlineCompletion(prefix: string, suffix: string): boolean { |
| 5 | return !suffix.startsWith("\n"); |
| 6 | } |
| 7 | |
| 8 | function shouldCompleteMultilineBasedOnLanguage( |
| 9 | language: AutocompleteLanguageInfo, |
| 10 | prefix: string, |
| 11 | suffix: string, |
| 12 | ) { |
| 13 | return language.useMultiline?.({ prefix, suffix }) ?? true; |
| 14 | } |
| 15 | |
| 16 | export function shouldCompleteMultiline(helper: HelperVars) { |
| 17 | switch (helper.options.multilineCompletions) { |
| 18 | case "always": |
| 19 | return true; |
| 20 | case "never": |
| 21 | return false; |
| 22 | default: |
| 23 | break; |
| 24 | } |
| 25 | |
| 26 | // Always single-line if an intellisense option is selected |
| 27 | if (helper.input.selectedCompletionInfo) { |
| 28 | return true; |
| 29 | } |
| 30 | |
| 31 | // // Don't complete multi-line if you are mid-line |
| 32 | // if (isMidlineCompletion(helper.fullPrefix, helper.fullSuffix)) { |
| 33 | // return false; |
| 34 | // } |
| 35 | |
| 36 | // Don't complete multi-line for single-line comments |
| 37 | if ( |
| 38 | helper.lang.singleLineComment && |
| 39 | helper.fullPrefix |
| 40 | .split("\n") |
| 41 | .slice(-1)[0] |
| 42 | ?.trimStart() |
| 43 | .startsWith(helper.lang.singleLineComment) |
| 44 | ) { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | return shouldCompleteMultilineBasedOnLanguage( |
| 49 | helper.lang, |
| 50 | helper.prunedPrefix, |
| 51 | helper.prunedSuffix, |
| 52 | ); |
| 53 | } |