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

Add AnalyzeOpenDocumentsOnly #5088

Merged
merged 7 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,11 @@
"default": false,
"description": "(EXPERIMENTAL) Enables support for resolving completion edits asynchronously. This can speed up time to show the completion list, particularly override and partial method completion lists, at the cost of slight delays after inserting a completion item. Most completion items will have no noticeable impact with this feature, but typing immediately after inserting an override or partial method completion, before the insert is completed, can have unpredictable results."
},
"omnisharp.analyzeOpenDocumentsOnly": {
"type": "boolean",
"default": false,
"description": "Only run analyzers against open files when 'enableRoslynAnalyzers' is true"
},
"omnisharp.testRunSettings": {
"type": [
"string",
Expand Down
74 changes: 74 additions & 0 deletions src/features/fileOpenCloseProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { IDisposable } from "../Disposable";
import { OmniSharpServer } from "../omnisharp/server";
import * as vscode from 'vscode';
import CompositeDisposable from "../CompositeDisposable";
import * as serverUtils from '../omnisharp/utils';
import { isVirtualCSharpDocument } from "./virtualDocumentTracker";

export default function fileOpenClose(server: OmniSharpServer): IDisposable {
return new FileOpenCloseProvider(server);
}

class FileOpenCloseProvider implements IDisposable {
private _server: OmniSharpServer;
private _diagnostics: vscode.DiagnosticCollection;
private _disposable: CompositeDisposable;

constructor(server: OmniSharpServer) {
this._server = server;
this._diagnostics = vscode.languages.createDiagnosticCollection('csharp');

setTimeout(async () => {
for (let editor of vscode.window.visibleTextEditors) {
let document = editor.document;

await this._onDocumentOpen(document);
}
}, 0);

this._disposable = new CompositeDisposable(this._diagnostics,
vscode.workspace.onDidOpenTextDocument(this._onDocumentOpen, this),
vscode.workspace.onDidCloseTextDocument(this._onDocumentClose, this),
vscode.window.onDidChangeActiveTextEditor(this._onActiveTextEditorChange, this)
);
}

private async _onDocumentOpen(e: vscode.TextDocument) {
if (shouldIgnoreDocument(e)) {
return;
}

await serverUtils.fileOpen(this._server, { FileName: e.fileName });
}

private async _onDocumentClose(e: vscode.TextDocument) {
if (shouldIgnoreDocument(e)) {
return;
}

await serverUtils.fileClose(this._server, { FileName: e.fileName });
}

private async _onActiveTextEditorChange(e: vscode.TextEditor) {
if (shouldIgnoreDocument(e.document)) {
return;
}

await serverUtils.filesChanged(this._server, [{ FileName: e.document.fileName }]);
}

dispose = () => this._disposable.dispose();
}

function shouldIgnoreDocument(document: vscode.TextDocument) {
if (document.languageId !== 'csharp') {
return true;
}

if (document.uri.scheme !== 'file' &&
!isVirtualCSharpDocument(document)) {
333fred marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

return false;
}
2 changes: 2 additions & 0 deletions src/observers/OptionChangeObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const omniSharpOptions: ReadonlyArray<OptionsKey> = [
"organizeImportsOnFormat",
"enableAsyncCompletion",
"useModernNet",
"analyzeOpenDocumentsOnly",
"enableRoslynAnalyzers"
];

function OmniSharpOptionChangeObservable(optionObservable: Observable<Options>): Observable<Options> {
Expand Down
2 changes: 2 additions & 0 deletions src/omnisharp/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import SemanticTokensProvider from '../features/semanticTokensProvider';
import SourceGeneratedDocumentProvider from '../features/sourceGeneratedDocumentProvider';
import { getDecompilationAuthorization } from './decompilationPrompt';
import { OmniSharpDotnetResolver } from './OmniSharpDotnetResolver';
import fileOpenClose from '../features/fileOpenCloseProvider';

export interface ActivationResult {
readonly server: OmniSharpServer;
Expand Down Expand Up @@ -111,6 +112,7 @@ export async function activate(context: vscode.ExtensionContext, packageJSON: an
localDisposables.add(forwardChanges(server));
localDisposables.add(trackVirtualDocuments(server, eventStream));
localDisposables.add(vscode.languages.registerFoldingRangeProvider(documentSelector, new StructureProvider(server, languageMiddlewareFeature)));
localDisposables.add(fileOpenClose(server));

const semanticTokensProvider = new SemanticTokensProvider(server, optionProvider, languageMiddlewareFeature);
localDisposables.add(vscode.languages.registerDocumentSemanticTokensProvider(documentSelector, semanticTokensProvider, semanticTokensProvider.getLegend()));
Expand Down
3 changes: 3 additions & 0 deletions src/omnisharp/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class Options {
public enableDecompilationSupport: boolean,
public enableImportCompletion: boolean,
public enableAsyncCompletion: boolean,
public analyzeOpenDocumentsOnly: boolean,
public useSemanticHighlighting: boolean,
public razorPluginPath?: string,
public defaultLaunchSolution?: string,
Expand Down Expand Up @@ -82,6 +83,7 @@ export class Options {
const enableDecompilationSupport = omnisharpConfig.get<boolean>('enableDecompilationSupport', false);
const enableImportCompletion = omnisharpConfig.get<boolean>('enableImportCompletion', false);
const enableAsyncCompletion = omnisharpConfig.get<boolean>('enableAsyncCompletion', false);
const analyzeOpenDocumentsOnly = omnisharpConfig.get<boolean>('analyzeOpenDocumentsOnly', false);

const useFormatting = csharpConfig.get<boolean>('format.enable', true);
const organizeImportsOnFormat = omnisharpConfig.get<boolean>('organizeImportsOnFormat', false);
Expand Down Expand Up @@ -141,6 +143,7 @@ export class Options {
enableDecompilationSupport,
enableImportCompletion,
enableAsyncCompletion,
analyzeOpenDocumentsOnly,
useSemanticHighlighting,
razorPluginPath,
defaultLaunchSolution,
Expand Down
2 changes: 2 additions & 0 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export module Requests {
export const SourceGeneratedFile = '/sourcegeneratedfile';
export const UpdateSourceGeneratedFile = '/updatesourcegeneratedfile';
export const SourceGeneratedFileClosed = '/sourcegeneratedfileclosed';
export const FileOpen = '/open';
export const FileClose = '/close';
}

export namespace WireProtocol {
Expand Down
4 changes: 4 additions & 0 deletions src/omnisharp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ export class OmniSharpServer {
args.push('RoslynExtensionsOptions:EnableAsyncCompletion=true');
}

if (options.analyzeOpenDocumentsOnly === true) {
args.push('RoslynExtensionsOptions:AnalyzeOpenDocumentsOnly=true');
}

let launchInfo: LaunchInfo;
try {
launchInfo = await this._omnisharpManager.GetOmniSharpLaunchInfo(this.packageJSON.defaults.omniSharp, options.path, /* useFramework */ !options.useModernNet, serverUrl, latestVersionFileServerPath, installPath, this.extensionPath);
Expand Down
8 changes: 8 additions & 0 deletions src/omnisharp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ export async function getCompletionAfterInsert(server: OmniSharpServer, request:
return server.makeRequest<protocol.CompletionAfterInsertResponse>(protocol.Requests.CompletionAfterInsert, request);
}

export async function fileOpen(server: OmniSharpServer, request: protocol.Request) {
return server.makeRequest<void>(protocol.Requests.FileOpen, request);
}

export async function fileClose(server: OmniSharpServer, request: protocol.Request) {
return server.makeRequest<void>(protocol.Requests.FileClose, request);
}

export async function isNetCoreProject(project: protocol.MSBuildProject) {
return project.TargetFrameworks.find(tf => tf.ShortName.startsWith('netcoreapp') || tf.ShortName.startsWith('netstandard')) !== undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion test/unitTests/Fakes/FakeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
import { Options } from "../../../src/omnisharp/options";

export function getEmptyOptions(): Options {
return new Options("", false, "", false, "", false, 0, 0, false, false, false, false, false, [], false, false, false, 0, 0, false, false, false, false, false, false, false, false, undefined, "", "", "");
return new Options("", false, "", false, "", false, 0, 0, false, false, false, false, false, [], false, false, false, 0, 0, false, false, false, false, false, false, false, false, false, undefined, "", "", "");
}
1 change: 1 addition & 0 deletions test/unitTests/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ suite("Options tests", () => {
options.enableEditorConfigSupport.should.equal(false);
options.enableDecompilationSupport.should.equal(false);
options.enableImportCompletion.should.equal(false);
options.analyzeOpenDocumentsOnly.should.equal(false);
expect(options.testRunSettings).to.be.undefined;
expect(options.defaultLaunchSolution).to.be.undefined;
});
Expand Down