Skip to content

Commit

Permalink
Tweak workspaceSymbols middleware to avoid suboptimal ordering of res…
Browse files Browse the repository at this point in the history
…ults (#118)

Fixes #81
  • Loading branch information
HighCommander4 committed Jan 8, 2021
1 parent cf65a5a commit e548f9e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,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

0 comments on commit e548f9e

Please sign in to comment.