Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak workspaceSymbols middleware to avoid suboptimal ordering of results #118

Merged
merged 1 commit into from
Jan 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,24 @@ export class ClangdContext implements vscode.Disposable {
return new vscode.CompletionList(items, /*isIncomplete=*/ true);
},
// VSCode applies fuzzy match only on the symbol name, thus it throws
// away
// all results if query token is a prefix qualified name.
// away all results if query token is a prefix qualified name.
// By adding the containerName to the symbol name, it prevents VSCode
// from
// filtering out any results, e.g. enable workspaceSymbols for qualified
// symbols.
// from filtering out any results, e.g. enable workspaceSymbols for
// qualified symbols.
provideWorkspaceSymbols: async (query, token, next) => {
let symbols = await next(query, token);
return symbols.map(symbol => {
if (symbol.containerName)
symbol.name = `${symbol.containerName}::${symbol.name}`;
// Always clean the containerName to avoid displaying it twice.
symbol.containerName = '';
// Only make this adjustment if the query is in fact qualified.
// Otherwise, we get a suboptimal ordering of results because
// including the name's qualifier (if it has one) in symbol.name
// means vscode can no longer tell apart exact matches from
// partial matches.
if (query.includes('::')) {
if (symbol.containerName)
symbol.name = `${symbol.containerName}::${symbol.name}`;
// Clean the containerName to avoid displaying it twice.
symbol.containerName = '';
}
return symbol;
})
},
Expand Down