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

Introduce configuration for "Go to Symbol in Workspace" #2487

Merged
merged 18 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0900d11
Support for omnisharp.maxFindSymbolsItems/minFindSymbolsFilterLength
dmgonch Sep 2, 2018
9844eda
Fixed test checking for default option values
dmgonch Sep 2, 2018
ddfde5f
Merge branch 'master' into feature/minFindSymbolsFilterLength
dmgonch Sep 3, 2018
792af4c
Merge branch 'master' into feature/minFindSymbolsFilterLength
akshita31 Sep 5, 2018
1cd56f4
Merge branch 'master' into feature/minFindSymbolsFilterLength
dmgonch Sep 8, 2018
ffc8ccb
Passed FindSymbol options via FindSymbolsRequest
dmgonch Sep 9, 2018
e23143d
Updated defaults for "Go To Symbol" as per PR discussion
dmgonch Sep 9, 2018
258faea
Fixed UTs; minFindSymbolsFilterLength default to 0
dmgonch Sep 9, 2018
3527407
Merge branch 'feature/minFindSymbolsFilterLength' of https://github.c…
dmgonch Sep 10, 2018
90dd6c8
Merge branch 'master' into feature/minFindSymbolsFilterLength
dmgonch Sep 11, 2018
242d169
Revert changes to OptionsChangeObserver.* since FindSymbolsRequest is…
dmgonch Sep 12, 2018
d8695b2
Clarify comment in package.json as well
dmgonch Sep 12, 2018
5447623
Revert changes to package-lock.json
dmgonch Sep 12, 2018
51516ef
Merge branch 'master' into feature/minFindSymbolsFilterLength
dmgonch Sep 15, 2018
9b9eb0b
Make MinFilterLength and MaxItemsToReturn in FindSymbolsRequest optional
dmgonch Sep 19, 2018
e5e70d8
Merge branch 'master' into feature/minFindSymbolsFilterLength
dmgonch Sep 19, 2018
2ef0f0e
Merge branch 'master' into feature/minFindSymbolsFilterLength
dmgonch Sep 20, 2018
1c88289
Fix 'npm run compile' after merge with latest
dmgonch Sep 20, 2018
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
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,16 @@
"default": true,
"description": "Specifes whether OmniSharp should use VS Code editor settings for C# code formatting (use of tabs, indentation size)."
},
"omnisharp.minFindSymbolsFilterLength": {
"type": "number",
"default": 0,
"description": "The minimum number of characters to enter before 'Go to Symbol in Workspace' operation shows any results."
},
"omnisharp.maxFindSymbolsItems": {
"type": "number",
"default": 1000,
"description": "The maximum number of items that 'Go to Symbol in Workspace' operation can show. The limit is applied only when a positive number is specified here."
},
"omnisharp.disableMSBuildDiagnosticWarning": {
"type": "boolean",
"default": false,
Expand Down
119 changes: 63 additions & 56 deletions src/features/workspaceSymbolProvider.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,63 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import AbstractSupport from './abstractProvider';
import * as protocol from '../omnisharp/protocol';
import * as serverUtils from '../omnisharp/utils';
import {toRange} from '../omnisharp/typeConvertion';
import {CancellationToken, Uri, WorkspaceSymbolProvider, SymbolInformation, SymbolKind} from 'vscode';


export default class OmnisharpWorkspaceSymbolProvider extends AbstractSupport implements WorkspaceSymbolProvider {

public async provideWorkspaceSymbols(search: string, token: CancellationToken): Promise<SymbolInformation[]> {

return serverUtils.findSymbols(this._server, { Filter: search, FileName: '' }, token).then(res => {
if (res && Array.isArray(res.QuickFixes)) {
return res.QuickFixes.map(OmnisharpWorkspaceSymbolProvider._asSymbolInformation);
}
});
}

private static _asSymbolInformation(symbolInfo: protocol.SymbolLocation): SymbolInformation {

return new SymbolInformation(symbolInfo.Text, OmnisharpWorkspaceSymbolProvider._toKind(symbolInfo),
toRange(symbolInfo),
Uri.file(symbolInfo.FileName));
}

private static _toKind(symbolInfo: protocol.SymbolLocation): SymbolKind {
switch (symbolInfo.Kind) {
case 'Method':
return SymbolKind.Method;
case 'Field':
return SymbolKind.Field;
case 'Property':
return SymbolKind.Property;
case 'Interface':
return SymbolKind.Interface;
case 'Enum':
return SymbolKind.Enum;
case 'Struct':
return SymbolKind.Struct;
case 'Event':
return SymbolKind.Event;
case 'EnumMember':
return SymbolKind.EnumMember;
case 'Class':
return SymbolKind.Class;
default:
return SymbolKind.Class;

}
}
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import AbstractSupport from './abstractProvider';
import { OmniSharpServer } from '../omnisharp/server';
import OptionProvider from '../observers/OptionProvider';
import * as protocol from '../omnisharp/protocol';
import * as serverUtils from '../omnisharp/utils';
import {toRange} from '../omnisharp/typeConvertion';
import {CancellationToken, Uri, WorkspaceSymbolProvider, SymbolInformation, SymbolKind} from 'vscode';


export default class OmnisharpWorkspaceSymbolProvider extends AbstractSupport implements WorkspaceSymbolProvider {

constructor(server: OmniSharpServer, private optionProvider: OptionProvider) {
super(server);
}

public async provideWorkspaceSymbols(search: string, token: CancellationToken): Promise<SymbolInformation[]> {

let options = this.optionProvider.GetLatestOptions();
return serverUtils.findSymbols(this._server, { Filter: search, MinFilterLength: options.minFindSymbolsFilterLength, MaxItemsToReturn: options.maxFindSymbolsItems, FileName: '' }, token).then(res => {
if (res && Array.isArray(res.QuickFixes)) {
return res.QuickFixes.map(OmnisharpWorkspaceSymbolProvider._asSymbolInformation);
}
});
}

private static _asSymbolInformation(symbolInfo: protocol.SymbolLocation): SymbolInformation {

return new SymbolInformation(symbolInfo.Text, OmnisharpWorkspaceSymbolProvider._toKind(symbolInfo),
toRange(symbolInfo),
Uri.file(symbolInfo.FileName));
}

private static _toKind(symbolInfo: protocol.SymbolLocation): SymbolKind {
switch (symbolInfo.Kind) {
case 'Method':
return SymbolKind.Method;
case 'Field':
return SymbolKind.Field;
case 'Property':
return SymbolKind.Property;
case 'Interface':
return SymbolKind.Interface;
case 'Enum':
return SymbolKind.Enum;
case 'Struct':
return SymbolKind.Struct;
case 'Event':
return SymbolKind.Event;
case 'EnumMember':
return SymbolKind.EnumMember;
case 'Class':
return SymbolKind.Class;
default:
return SymbolKind.Class;

}
}
}
2 changes: 1 addition & 1 deletion src/omnisharp/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function activate(context: vscode.ExtensionContext, packageJSON: an
localDisposables.add(vscode.languages.registerOnTypeFormattingEditProvider(documentSelector, new FormatProvider(server), '}', ';'));
}
localDisposables.add(vscode.languages.registerCompletionItemProvider(documentSelector, new CompletionItemProvider(server), '.', ' '));
localDisposables.add(vscode.languages.registerWorkspaceSymbolProvider(new WorkspaceSymbolProvider(server)));
localDisposables.add(vscode.languages.registerWorkspaceSymbolProvider(new WorkspaceSymbolProvider(server, optionProvider)));
localDisposables.add(vscode.languages.registerSignatureHelpProvider(documentSelector, new SignatureHelpProvider(server), '(', ','));
const codeActionProvider = new CodeActionProvider(server, optionProvider);
localDisposables.add(codeActionProvider);
Expand Down
7 changes: 7 additions & 0 deletions src/omnisharp/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class Options {
public showTestsCodeLens: boolean,
public disableCodeActions: boolean,
public disableMSBuildDiagnosticWarning: boolean,
public minFindSymbolsFilterLength: number,
public maxFindSymbolsItems: number,
public defaultLaunchSolution?: string,
public monoPath?: string) { }

Expand Down Expand Up @@ -63,6 +65,9 @@ export class Options {

const disableMSBuildDiagnosticWarning = omnisharpConfig.get<boolean>('disableMSBuildDiagnosticWarning', false);

const minFindSymbolsFilterLength = omnisharpConfig.get<number>('minFindSymbolsFilterLength', 0);
const maxFindSymbolsItems = omnisharpConfig.get<number>('maxFindSymbolsItems', 1000); // The limit is applied only when this setting is set to a number greater than zero

return new Options(
path,
useGlobalMono,
Expand All @@ -77,6 +82,8 @@ export class Options {
showTestsCodeLens,
disableCodeActions,
disableMSBuildDiagnosticWarning,
minFindSymbolsFilterLength,
maxFindSymbolsItems,
defaultLaunchSolution,
monoPath,
);
Expand Down
2 changes: 2 additions & 0 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export interface FindUsagesRequest extends Request {

export interface FindSymbolsRequest extends Request {
Filter: string;
MinFilterLength: number;
MaxItemsToReturn: number;
}

export interface FormatRequest extends Request {
Expand Down
4 changes: 3 additions & 1 deletion test/unitTests/optionStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ suite('OptionStream', () => {
options.showReferencesCodeLens.should.equal(true);
options.showTestsCodeLens.should.equal(true);
options.disableCodeActions.should.equal(false);
expect(options.defaultLaunchSolution).to.be.undefined;
options.minFindSymbolsFilterLength.should.equal(0);
options.maxFindSymbolsItems.should.equal(1000);
expect(options.defaultLaunchSolution).to.be.undefined;
});

test('Gives the changed option when the omnisharp config changes', () => {
Expand Down
2 changes: 2 additions & 0 deletions test/unitTests/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ suite("Options tests", () => {
options.showTestsCodeLens.should.equal(true);
options.disableCodeActions.should.equal(false);
options.disableCodeActions.should.equal(false);
options.minFindSymbolsFilterLength.should.equal(0);
options.maxFindSymbolsItems.should.equal(1000);
expect(options.defaultLaunchSolution).to.be.undefined;
});

Expand Down