Skip to content

Commit

Permalink
Fix #4441 Remove % components from macro suggestion snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Oct 17, 2024
1 parent 6392b48 commit a090650
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/completion/completer/macro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,11 @@ function entryCmdToCompletion(item: MacroRaw, packageName?: string, postAction?:
if (! (item.arg.snippet.match(/\$\{?2/) || (item.arg.snippet.match(/\$\{?0/) && item.arg.snippet.match(/\$\{?1/)))) {
item.arg.snippet = item.arg.snippet.replace(/\$1|\$\{1\}/, '$${1:$${TM_SELECTED_TEXT}}').replace(/\$\{1:([^$}]+)\}/, '$${1:$${TM_SELECTED_TEXT:$1}}')
}
// Remove the %keyvals component
item.arg.snippet = item.arg.snippet.replace(/%keyvals/g, '')
item.arg.snippet = item.arg.snippet
// Remove the %:translatable component
.replace(/%:translatable/g, '')
// Remove the %randomword component
.replace(/%\w+/g, '')
suggestion.insertText = new vscode.SnippetString(item.arg.snippet)
} else {
suggestion.insertText = item.name
Expand Down
20 changes: 20 additions & 0 deletions test/units/15_completion_macro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ describe(path.basename(__filename).split('.')[0] + ':', () => {
assert.ok(!snippet.value.includes('%keyvals'), snippet.value)
})

it('should remove `%:translatable` from macro argument hints', async () => {
readStub.resolves('\\usepackage{amsmath}')
await lw.cache.refreshCache(texPath)

const suggestion = getSuggestions().find(s => s.label === '\\dfrac{}{}')
const snippet = suggestion?.insertText
assert.ok(snippet instanceof vscode.SnippetString)
assert.ok(!snippet.value.includes('%:translatable'), snippet.value)
})

it('should remove other `%` components from macro argument hints', async () => {
readStub.resolves('\\usepackage{acro}')
await lw.cache.refreshCache(texPath)

const suggestion = getSuggestions().find(s => s.label === '\\acrotranslate{}')
const snippet = suggestion?.insertText
assert.ok(snippet instanceof vscode.SnippetString)
assert.ok(!snippet.value.includes('%'), snippet.value)
})

it('should not provide argument hints if `intellisense.argumentHint.enabled` is false', async () => {
readStub.resolves('\\usepackage{import}')
await lw.cache.refreshCache(texPath)
Expand Down

0 comments on commit a090650

Please sign in to comment.