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

Fixed disabling of code lens references #1782

Merged
merged 4 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@
"default": true,
"description": "Specifies whether the references CodeLens show be shown."
},
"csharp.showTestsCodeLens": {
"type": "boolean",
"default": true,
"description": "Specifies whether the run and debug test CodeLens show be shown."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "should be should". It looks like the same typo appears above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

},
"omnisharp.path": {
"type": [
"string",
Expand Down
13 changes: 9 additions & 4 deletions src/features/codeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ class OmniSharpCodeLens extends vscode.CodeLens {
export default class OmniSharpCodeLensProvider extends AbstractProvider implements vscode.CodeLensProvider {

private _testManager: TestManager;
private _options: Options;

constructor(server: OmniSharpServer, reporter: TelemetryReporter, testManager: TestManager)
{
super(server, reporter);

this._testManager = testManager;
this._options = Options.Read();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, do we still turn codelens on/off as you switch between the prefernces tab and file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. I would expect that this will require a restart of the extension to take effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah indeed. Though I think this is consistent with the rest of the extension at the moment - we don't read any options in "real time" I think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're just inconsistent. For example, setting csharp.suppressDotnetRestoreNotification will take effect immediately. So will csharp.disableCodeActions. Maybe it's worth adding the extra logic to listen for vscode.workspace.onDidChangeConfiguration? Check out what we do in CodeActionProvider here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the tip - I did not see that before. I pushed the appropriate change. Indeed, the experience is much nicer now 👍

}

private static filteredSymbolNames: { [name: string]: boolean } = {
Expand All @@ -44,8 +46,7 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen
};

provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.CodeLens[] | Thenable<vscode.CodeLens[]> {
const options = Options.Read();
if (!options.showReferencesCodeLens)
if (!this._options.showReferencesCodeLens && !this._options.showTestsCodeLens)
{
return [];
}
Expand All @@ -64,13 +65,17 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen
}

let lens = new OmniSharpCodeLens(fileName, toRange(node.Location));
bucket.push(lens);
if (this._options.showReferencesCodeLens) {
bucket.push(lens);
}

for (let child of node.ChildNodes) {
this._convertQuickFix(bucket, fileName, child);
}

this._updateCodeLensForTest(bucket, fileName, node);
if (this._options.showTestsCodeLens) {
this._updateCodeLensForTest(bucket, fileName, node);
}
}

resolveCodeLens(codeLens: vscode.CodeLens, token: vscode.CancellationToken): Thenable<vscode.CodeLens> {
Expand Down
7 changes: 5 additions & 2 deletions src/omnisharp/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export class Options {
public maxProjectResults?: number,
public useEditorFormattingSettings?: boolean,
public useFormatting?: boolean,
public showReferencesCodeLens?: boolean) { }
public showReferencesCodeLens?: boolean,
public showTestsCodeLens?: boolean) { }

public static Read(): Options {
// Extra effort is taken below to ensure that legacy versions of options
Expand Down Expand Up @@ -53,6 +54,7 @@ export class Options {
const useFormatting = csharpConfig.get<boolean>('format.enable', true);

const showReferencesCodeLens = csharpConfig.get<boolean>('showReferencesCodeLens', true);
const showTestsCodeLens = csharpConfig.get<boolean>('showTestsCodeLens', true);

return new Options(path,
useMono,
Expand All @@ -63,6 +65,7 @@ export class Options {
maxProjectResults,
useEditorFormattingSettings,
useFormatting,
showReferencesCodeLens);
showReferencesCodeLens,
showTestsCodeLens);
}
}