Skip to content

Commit

Permalink
feat(completion): add reTriggerAfterIndent (#5009)
Browse files Browse the repository at this point in the history
to control re-trigger or not after indent changes

Closes #4713
  • Loading branch information
fannheyward authored May 15, 2024
1 parent c7e92a7 commit fce6804
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,12 @@
"description": "How should completion be triggered",
"enum": ["always", "trigger", "none"]
},
"suggest.reTriggerAfterIndent": {
"type": "boolean",
"description": "Re-Trigger completion after indent changes",
"scope": "language-overridable",
"default": true
},
"suggest.completionItemKindLabels": {
"type": "object",
"default": {},
Expand Down
12 changes: 12 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# 2024-05-14

- Added `suggest.reTriggerAfterIndent` to control re-trigger or not after indent changes

# 2024-05-07

- Allow `CocInstall` to install extension from Github in development mode

# 2024-04-12

- Change scope of codeLens configuration to `language-overridable`

# 2024-03-26

- Added new `--workspace-folder` argument for diagnostics lists
Expand Down
24 changes: 24 additions & 0 deletions src/__tests__/completion/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,30 @@ describe('completion', () => {
return completion.option?.col
}, 0)
})

it('should not trigger completion after indent change with reTriggerAfterIndent = false', async () => {
helper.updateConfiguration('suggest.reTriggerAfterIndent', false)
await helper.createDocument('t')
let source: ISource = {
name: 'source1',
priority: 90,
enable: true,
sourceType: SourceType.Native,
doComplete: async () => Promise.resolve({
items: [{ word: 'endif' }]
})
}
disposables.push(sources.addSource(source))
await nvim.input('i')
await nvim.input(' endi')
await helper.waitPopup()
await nvim.input('f')
await helper.wait(10)
await nvim.call('setline', ['.', 'endif'])
await helper.wait(10)
let visible = await pumvisible()
expect(visible).toBe(false)
})
})

describe('sortItems', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/completion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class Completion implements Disposable {
floatConfig: toObject(suggest.floatConfig),
pumFloatConfig: suggest.pumFloatConfig,
labelMaxLength: suggest.labelMaxLength,
reTriggerAfterIndent: !!suggest.reTriggerAfterIndent,
reversePumAboveCursor: !!suggest.reversePumAboveCursor,
snippetIndicator: toText(suggest.snippetIndicator),
noselect: !!suggest.noselect,
Expand Down Expand Up @@ -264,7 +265,7 @@ export class Completion implements Disposable {
}
}
// retrigger after indent
if (info.pre.match(/^\s*/)[0] !== option.line.match(/^\s*/)[0]) {
if (this.staticConfig.reTriggerAfterIndent && info.pre.match(/^\s*/)[0] !== option.line.match(/^\s*/)[0]) {
await this.triggerCompletion(doc, info)
return
}
Expand Down
1 change: 1 addition & 0 deletions src/completion/pum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface PopupMenuConfig {
virtualText: boolean
detailMaxLength: number
detailField: string
reTriggerAfterIndent: boolean
invalidInsertCharacters: string[]
}

Expand Down

0 comments on commit fce6804

Please sign in to comment.