Skip to content

Commit 24a94ce

Browse files
committed
fix: don't enable method snippets before ( in some edge-cases
1 parent 8f512fc commit 24a94ce

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/onCompletionAccepted.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ export default (tsApi: { onCompletionAccepted }) => {
5555
if (!documentation?.startsWith(dataMarker)) return
5656
const parsed = JSON.parse(documentation.slice(dataMarker.length, documentation.indexOf('e-->')))
5757
const { methodSnippet: params, isAmbiguous } = parsed
58-
if (!params) return
58+
// nextChar check also duplicated in completionEntryDetails for perf, but we need to run this check again with correct position
59+
const startPos = editor.selection.start
60+
const nextChar = editor.document.getText(new vscode.Range(startPos, startPos.translate(0, 1)))
61+
if (!params || ['(', '.', '`'].includes(nextChar)) return
5962

6063
if (isAmbiguous && lastAcceptedAmbiguousMethodSnippetSuggestion !== suggestionName) {
6164
lastAcceptedAmbiguousMethodSnippetSuggestion = suggestionName

src/specialCommands.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,11 @@ export default () => {
281281
},
282282
)
283283
})
284+
285+
registerExtensionCommand('copyFullType', async () => {
286+
const response = await sendCommand<RequestResponseTypes['getFullType']>('getFullType')
287+
if (!response) return
288+
const { text } = response
289+
await vscode.env.clipboard.writeText(text)
290+
})
284291
}

typescript/src/completionEntryDetails.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default function completionEntryDetails(
4949
prior.displayParts = [{ kind: 'text', text: detailPrepend }, ...prior.displayParts]
5050
}
5151
if (!prior) return
52+
// might be incorrect: write [].entries() -> []|.entries|() -> []./*position*/e
5253
const nextChar = sourceFile.getFullText().slice(position, position + 1)
5354

5455
if (enableMethodCompletion && c('enableMethodSnippets') && !['(', '.', '`'].includes(nextChar)) {

typescript/src/completions/objectLiteralCompletions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ export default (prior: ts.CompletionInfo): ts.CompletionEntry[] | void => {
6666
const insertSnippetVariant = completingStyleMap.find(([, detector]) => detector(type!, typeChecker))?.[0] ?? fallbackSnippet
6767
if (!insertSnippetVariant) continue
6868
const [insertSnippetText, insertSnippetPreview] = typeof insertSnippetVariant === 'function' ? insertSnippetVariant() : insertSnippetVariant
69-
const insertText = entry.name + insertSnippetText
69+
const insertText = entry.name.replace(/\$/g, '\\$') + insertSnippetText
7070
const index = entries.indexOf(entry)
7171
entries.splice(index + (keepOriginal === 'before' ? 1 : 0), keepOriginal === 'remove' ? 1 : 0, {
7272
...entry,
73-
name: entry.name.replace(/\$/g, '\\$'),
7473
// todo setting incompatible!!!
7574
sortText: entry.sortText,
7675
labelDetails: {

0 commit comments

Comments
 (0)