Skip to content

Commit

Permalink
Add maxNumberOfSymbols setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
valderman committed Jul 4, 2020
1 parent 1e4326c commit 81a34cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ to regenerate your tags whenever you make changes to your source.
## Extension Settings
* `ctagsymbols.tagsFile`: path to the ctags file to read symbols from, relative to the workspace root.
* `ctagsymbols.hideDuplicateTags`: when there are multiple tags with the same name in the same source file, hide all but the first one.
* `ctagsymbols.maxNumberOfSymbols`: never display more than this many symbols, regardless of the number of matches.
* `ctagsymbols.minQueryLength`: don't process symbol queries shorter than this. May improve performance for large code bases since it avoids listing every single symbol in the entire project.


Expand Down
6 changes: 5 additions & 1 deletion extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,18 @@ const provideWorkspaceSymbols = async query => {
const tagsFileName = config.get("tagsFileName")
const minQueryLength = config.get("minQueryLength")
const hideDuplicateTags = config.get("hideDuplicateTags")
const maxNumberOfSymbols = config.get("maxNumberOfSymbols")
if(query.length < minQueryLength) {
return []
}
const projectRoot = vscode.workspace.workspaceFolders[0].uri.fsPath
const tagsFile = vscode.Uri.file(path.join(projectRoot, tagsFileName))
const queryRegex = new RegExp(query, "i")
await ensureSymbolCacheCoherency(tagsFile, projectRoot, hideDuplicateTags)
return symbolCache.entries.filter(entry => entry.name.match(queryRegex))
const filteredEntries = symbolCache.entries.filter(entry => entry.name.match(queryRegex))
return maxNumberOfSymbols
? filteredEntries.slice(0, maxNumberOfSymbols)
: filteredEntries
}

const resolveWorkspaceSymbol = async symbol => {
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@
"default": true,
"description": "When there are multiple identical tags in the same source file, only display the first one."
},
"ctagsymbols.maxNumberOfSymbols": {
"type": ["number", "null"],
"default": null,
"description": "Never show more than this many tags, regardless of the number of matches."
},
"ctagsymbols.minQueryLength": {
"type": "number",
"default": "0",
"type": ["number", "null"],
"default": null,
"description": "Only process searches of at least this many characters. May help performance for large code bases."
}
}
Expand Down

0 comments on commit 81a34cd

Please sign in to comment.