Skip to content

Commit

Permalink
Workspace symbol search should be case insensitive
Browse files Browse the repository at this point in the history
Fixes #92
  • Loading branch information
mjbvz committed Nov 4, 2022
1 parent ec9befb commit 75fffb4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.3.0-alpha.1 UNRELEASED
- Added optional `$uri` property on `ITextDocument` which lets implementers provide an actual uri instead of a string. This helps reduce the number of calls to `URI.parse`.
- Workspace symbol search should be case insensitive.

## 0.2.0 October 31, 2022
- Added diagnostics for unused link definitions.
Expand Down
4 changes: 2 additions & 2 deletions src/languageFeatures/workspaceSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class MdWorkspaceSymbolProvider extends Disposable {
readonly #cache: MdWorkspaceInfoCache<lsp.SymbolInformation[]>;
readonly #symbolProvider: MdDocumentSymbolProvider;

public constructor(
constructor(
workspace: IWorkspace,
symbolProvider: MdDocumentSymbolProvider,
) {
Expand All @@ -33,7 +33,7 @@ export class MdWorkspaceSymbolProvider extends Disposable {
}

const normalizedQueryStr = query.toLowerCase();
return allSymbols.flat().filter(symbolInformation => symbolInformation.name.includes(normalizedQueryStr));
return allSymbols.flat().filter(symbolInformation => symbolInformation.name.toLowerCase().includes(normalizedQueryStr));
}

public async provideDocumentSymbolInformation(document: ITextDocument, token: CancellationToken): Promise<lsp.SymbolInformation[]> {
Expand Down
19 changes: 19 additions & 0 deletions src/test/workspaceSymbol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,23 @@ suite('Workspace symbols', () => {
assert.strictEqual(symbols.length, 1);
assert.strictEqual(symbols[0].name, '# header1');
}));

test('Should match case insensitively', withStore(async (store) => {
const workspace = store.add(new InMemoryWorkspace([
new InMemoryDocument(workspacePath('test.md'), `# aBc1\nabc\n## ABc2`)
]));

{
const symbols = await getWorkspaceSymbols(store, workspace, 'ABC');
assert.strictEqual(symbols.length, 2);
assert.strictEqual(symbols[0].name, '# aBc1');
assert.strictEqual(symbols[1].name, '## ABc2');
}
{
const symbols = await getWorkspaceSymbols(store, workspace, 'abc');
assert.strictEqual(symbols.length, 2);
assert.strictEqual(symbols[0].name, '# aBc1');
assert.strictEqual(symbols[1].name, '## ABc2');
}
}));
});

0 comments on commit 75fffb4

Please sign in to comment.