Skip to content

Commit

Permalink
feat: add coc.preferences.tagDefinitionTimeout (#4601)
Browse files Browse the repository at this point in the history
  • Loading branch information
gou4shi1 committed Apr 11, 2023
1 parent 43f4daa commit 3014125
Show file tree
Hide file tree
Showing 3 changed files with 23 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 @@ -686,6 +686,12 @@
"maximum": 5000,
"description": "Will save handler timeout"
},
"coc.preferences.tagDefinitionTimeout": {
"type": "integer",
"scope": "application",
"default": 0,
"description": "The timeout of CocTagFunc, default is infinity"
},
"coc.source.around.disableSyntaxes": {
"type": "array",
"default": [],
Expand Down
5 changes: 5 additions & 0 deletions doc/coc-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,11 @@ Preferences~

Scope: `application`, default: `500`

"coc.preferences.tagDefinitionTimeout" *coc-preferences-tagDefinitionTimeout*

The timeout of CocTagFunc.
Scope: `application`, default: `0`

------------------------------------------------------------------------------
Float configuration~
*coc-config-float*
Expand Down
13 changes: 12 additions & 1 deletion src/handler/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,18 @@ export default class LocationsHandler {
if (!word) return null
if (!languages.hasProvider(ProviderName.Definition, doc.textDocument)) return null
let tokenSource = new CancellationTokenSource()
let definitions = await languages.getDefinition(doc.textDocument, position, tokenSource.token)
let definitions = []
try {
let timeout = workspace.initialConfiguration.get<number>('coc.preferences.tagDefinitionTimeout', 0)
if (timeout> 0) {
const abort = new Promise<[]>((_, rej) => setTimeout(() => rej(new Error('timeout')), timeout))
definitions = await Promise.race([languages.getDefinition(doc.textDocument, position, tokenSource.token), abort])
} else {
definitions = await languages.getDefinition(doc.textDocument, position, tokenSource.token)
}
} catch (e) {
return null
}
if (!definitions || !definitions.length) return null
return definitions.map(location => {
let parsedURI = URI.parse(location.uri)
Expand Down

0 comments on commit 3014125

Please sign in to comment.