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

Allow multiple simultaneous requests to be sent to OmniSharp server #902

Merged
merged 6 commits into from
Nov 11, 2016
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
6 changes: 3 additions & 3 deletions src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as fs from 'fs-extra-promise';
import * as path from 'path';
import * as vscode from 'vscode';
import * as tasks from 'vscode-tasks';
import {OmnisharpServer} from './omnisharp/server';
import {OmniSharpServer} from './omnisharp/server';
import * as serverUtils from './omnisharp/utils';
import * as protocol from './omnisharp/protocol';

Expand Down Expand Up @@ -393,7 +393,7 @@ export enum AddAssetResult {
Cancelled
}

export function addAssetsIfNecessary(server: OmnisharpServer): Promise<AddAssetResult> {
export function addAssetsIfNecessary(server: OmniSharpServer): Promise<AddAssetResult> {
return new Promise<AddAssetResult>((resolve, reject) => {
if (!vscode.workspace.rootPath) {
return resolve(AddAssetResult.NotApplicable);
Expand Down Expand Up @@ -492,7 +492,7 @@ function shouldGenerateAssets(paths: Paths) {
});
}

export function generateAssets(server: OmnisharpServer) {
export function generateAssets(server: OmniSharpServer) {
serverUtils.requestWorkspaceInformation(server).then(info => {
if (info.DotNet && info.DotNet.Projects.length > 0) {
getOperations().then(operations => {
Expand Down
6 changes: 3 additions & 3 deletions src/features/abstractProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

'use strict';

import {OmnisharpServer} from '../omnisharp/server';
import {OmniSharpServer} from '../omnisharp/server';
import {Disposable} from 'vscode';

export default class AbstractProvider {

protected _server: OmnisharpServer;
protected _server: OmniSharpServer;
protected _disposables: Disposable[];

constructor(server: OmnisharpServer) {
constructor(server: OmniSharpServer) {
this._server = server;
this._disposables = [];
}
Expand Down
8 changes: 4 additions & 4 deletions src/features/changeForwarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
'use strict';

import {Disposable, Uri, workspace} from 'vscode';
import {OmnisharpServer} from '../omnisharp/server';
import {OmniSharpServer} from '../omnisharp/server';
import * as serverUtils from '../omnisharp/utils';

function forwardDocumentChanges(server: OmnisharpServer): Disposable {
function forwardDocumentChanges(server: OmniSharpServer): Disposable {

return workspace.onDidChangeTextDocument(event => {

Expand All @@ -29,7 +29,7 @@ function forwardDocumentChanges(server: OmnisharpServer): Disposable {
});
}

function forwardFileChanges(server: OmnisharpServer): Disposable {
function forwardFileChanges(server: OmniSharpServer): Disposable {

function onFileSystemEvent(uri: Uri): void {
if (!server.isRunning()) {
Expand All @@ -52,7 +52,7 @@ function forwardFileChanges(server: OmnisharpServer): Disposable {
return Disposable.from(watcher, d1, d2, d3);
}

export default function forwardChanges(server: OmnisharpServer): Disposable {
export default function forwardChanges(server: OmniSharpServer): Disposable {

// combine file watching and text document watching
return Disposable.from(
Expand Down
4 changes: 2 additions & 2 deletions src/features/codeActionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import {CodeActionProvider, CodeActionContext, Command, CancellationToken, TextDocument, WorkspaceEdit, TextEdit, Range, Uri, workspace, commands} from 'vscode';
import {OmnisharpServer} from '../omnisharp/server';
import {OmniSharpServer} from '../omnisharp/server';
import AbstractProvider from './abstractProvider';
import * as protocol from '../omnisharp/protocol';
import {toRange2} from '../omnisharp/typeConvertion';
Expand All @@ -17,7 +17,7 @@ export default class OmnisharpCodeActionProvider extends AbstractProvider implem
private _disabled: boolean;
private _commandId: string;

constructor(server: OmnisharpServer) {
constructor(server: OmniSharpServer) {
super(server);
this._commandId = 'omnisharp.runCodeAction';

Expand Down
12 changes: 6 additions & 6 deletions src/features/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

'use strict';

import {OmnisharpServer} from '../omnisharp/server';
import {OmniSharpServer} from '../omnisharp/server';
import * as serverUtils from '../omnisharp/utils';
import {findLaunchTargets} from '../omnisharp/launcher';
import * as cp from 'child_process';
Expand All @@ -19,7 +19,7 @@ import {generateAssets} from '../assets';

let channel = vscode.window.createOutputChannel('.NET');

export default function registerCommands(server: OmnisharpServer, extensionPath: string) {
export default function registerCommands(server: OmniSharpServer, extensionPath: string) {
let d1 = vscode.commands.registerCommand('o.restart', () => restartOmniSharp(server));
let d2 = vscode.commands.registerCommand('o.pickProjectAndStart', () => pickProjectAndStart(server));
let d3 = vscode.commands.registerCommand('o.showOutput', () => server.getChannel().show(vscode.ViewColumn.Three));
Expand All @@ -44,7 +44,7 @@ export default function registerCommands(server: OmnisharpServer, extensionPath:
return vscode.Disposable.from(d1, d2, d3, d4, d5, d6, d7, d8, d9);
}

function restartOmniSharp(server: OmnisharpServer) {
function restartOmniSharp(server: OmniSharpServer) {
if (server.isRunning()) {
server.restart();
}
Expand All @@ -53,7 +53,7 @@ function restartOmniSharp(server: OmnisharpServer) {
}
}

function pickProjectAndStart(server: OmnisharpServer) {
function pickProjectAndStart(server: OmniSharpServer) {

return findLaunchTargets().then(targets => {

Expand Down Expand Up @@ -103,7 +103,7 @@ function projectsToCommands(projects: protocol.DotNetProject[]): Promise<Command
});
}

export function dotnetRestoreAllProjects(server: OmnisharpServer) {
export function dotnetRestoreAllProjects(server: OmniSharpServer) {

if (!server.isRunning()) {
return Promise.reject('OmniSharp server is not running.');
Expand All @@ -127,7 +127,7 @@ export function dotnetRestoreAllProjects(server: OmnisharpServer) {
});
}

export function dotnetRestoreForProject(server: OmnisharpServer, fileName: string) {
export function dotnetRestoreForProject(server: OmniSharpServer, fileName: string) {

if (!server.isRunning()) {
return Promise.reject('OmniSharp server is not running.');
Expand Down
10 changes: 5 additions & 5 deletions src/features/diagnosticsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

'use strict';

import {OmnisharpServer} from '../omnisharp/server';
import {OmniSharpServer} from '../omnisharp/server';
import AbstractSupport from './abstractProvider';
import * as protocol from '../omnisharp/protocol';
import * as serverUtils from '../omnisharp/utils';
Expand All @@ -15,11 +15,11 @@ import {Disposable, Uri, CancellationTokenSource, TextDocument, Diagnostic, Diag
export class Advisor {

private _disposable: Disposable;
private _server: OmnisharpServer;
private _server: OmniSharpServer;
private _packageRestoreCounter: number = 0;
private _projectSourceFileCounts: { [path: string]: number } = Object.create(null);

constructor(server: OmnisharpServer) {
constructor(server: OmniSharpServer) {
this._server = server;

let d1 = server.onProjectChange(this._onProjectChange, this);
Expand Down Expand Up @@ -112,7 +112,7 @@ export class Advisor {
}
}

export default function reportDiagnostics(server: OmnisharpServer, advisor: Advisor): Disposable {
export default function reportDiagnostics(server: OmniSharpServer, advisor: Advisor): Disposable {
return new DiagnosticsProvider(server, advisor);
}

Expand All @@ -124,7 +124,7 @@ class DiagnosticsProvider extends AbstractSupport {
private _projectValidation: CancellationTokenSource;
private _diagnostics: DiagnosticCollection;

constructor(server: OmnisharpServer, validationAdvisor: Advisor) {
constructor(server: OmniSharpServer, validationAdvisor: Advisor) {
super(server);
this._validationAdvisor = validationAdvisor;
this._diagnostics = languages.createDiagnosticCollection('csharp');
Expand Down
10 changes: 5 additions & 5 deletions src/features/dotnetTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

'use strict';

import {OmnisharpServer} from '../omnisharp/server';
import {OmniSharpServer} from '../omnisharp/server';
import {toRange} from '../omnisharp/typeConvertion';
import * as vscode from 'vscode';
import * as serverUtils from "../omnisharp/utils";
Expand All @@ -21,20 +21,20 @@ function getTestOutputChannel(): vscode.OutputChannel {
return _testOutputChannel;
}

export function registerDotNetTestRunCommand(server: OmnisharpServer): vscode.Disposable {
export function registerDotNetTestRunCommand(server: OmniSharpServer): vscode.Disposable {
return vscode.commands.registerCommand(
'dotnet.test.run',
(testMethod, fileName) => runDotnetTest(testMethod, fileName, server));
}

export function registerDotNetTestDebugCommand(server: OmnisharpServer): vscode.Disposable {
export function registerDotNetTestDebugCommand(server: OmniSharpServer): vscode.Disposable {
return vscode.commands.registerCommand(
'dotnet.test.debug',
(testMethod, fileName) => debugDotnetTest(testMethod, fileName, server));
}

// Run test through dotnet-test command. This function can be moved to a separate structure
export function runDotnetTest(testMethod: string, fileName: string, server: OmnisharpServer) {
export function runDotnetTest(testMethod: string, fileName: string, server: OmniSharpServer) {
getTestOutputChannel().show();
getTestOutputChannel().appendLine('Running test ' + testMethod + '...');
serverUtils
Expand All @@ -54,7 +54,7 @@ export function runDotnetTest(testMethod: string, fileName: string, server: Omni
}

// Run test through dotnet-test command with debugger attached
export function debugDotnetTest(testMethod: string, fileName: string, server: OmnisharpServer) {
export function debugDotnetTest(testMethod: string, fileName: string, server: OmniSharpServer) {
serverUtils.getTestStartInfo(server, { FileName: fileName, MethodName: testMethod }).then(response => {
vscode.commands.executeCommand(
'vscode.startDebug', {
Expand Down
20 changes: 7 additions & 13 deletions src/features/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
'use strict';

import * as vscode from 'vscode';
import {OmnisharpServer} from '../omnisharp/server';
import {OmniSharpServer} from '../omnisharp/server';
import {dotnetRestoreForProject} from './commands';
import {basename} from 'path';
import * as protocol from '../omnisharp/protocol';
import * as serverUtils from '../omnisharp/utils';

const debounce = require('lodash.debounce');

export default function reportStatus(server: OmnisharpServer) {
export default function reportStatus(server: OmniSharpServer) {
return vscode.Disposable.from(
reportServerStatus(server),
forwardOutput(server),
Expand Down Expand Up @@ -41,7 +41,7 @@ class Status {
}
}

export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable {
export function reportDocumentStatus(server: OmniSharpServer): vscode.Disposable {

let disposables: vscode.Disposable[] = [];
let localDisposables: vscode.Disposable[];
Expand Down Expand Up @@ -202,7 +202,7 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable

// ---- server status

export function reportServerStatus(server: OmnisharpServer): vscode.Disposable{
export function reportServerStatus(server: OmniSharpServer): vscode.Disposable{

function appendLine(value: string = '') {
server.getChannel().appendLine(value);
Expand Down Expand Up @@ -275,20 +275,14 @@ function showMessageSoon() {

// --- mirror output in channel

function forwardOutput(server: OmnisharpServer) {
function forwardOutput(server: OmniSharpServer) {

const logChannel = server.getChannel();
const timing200Pattern = /^\[INFORMATION:OmniSharp.Middleware.LoggingMiddleware\] \/\w+: 200 \d+ms/;

function forward(message: string) {
// strip stuff like: /codecheck: 200 339ms
if(!timing200Pattern.test(message)) {
logChannel.append(message);
}
logChannel.append(message);
}

return vscode.Disposable.from(
server.onStdout(forward),
server.onStderr(forward));
}

}
4 changes: 2 additions & 2 deletions src/omnisharp/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import SignatureHelpProvider from '../features/signatureHelpProvider';
import registerCommands from '../features/commands';
import forwardChanges from '../features/changeForwarding';
import reportStatus from '../features/status';
import {StdioOmnisharpServer} from './server';
import {OmniSharpServer} from './server';
import {Options} from './options';
import {addAssetsIfNecessary, AddAssetResult} from '../assets';

Expand All @@ -33,7 +33,7 @@ export function activate(context: vscode.ExtensionContext, reporter: TelemetryRe
scheme: 'file' // only files from disk
};

const server = new StdioOmnisharpServer(reporter);
const server = new OmniSharpServer(reporter);
const advisor = new Advisor(server); // create before server is started
const disposables: vscode.Disposable[] = [];
const localDisposables: vscode.Disposable[] = [];
Expand Down
60 changes: 60 additions & 0 deletions src/omnisharp/prioritization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as protocol from './protocol';

const priorityCommands = [
protocol.Requests.ChangeBuffer,
protocol.Requests.FormatAfterKeystroke,
protocol.Requests.FormatRange,
protocol.Requests.UpdateBuffer
];

const normalCommands = [
protocol.Requests.AutoComplete,
protocol.Requests.FilesChanged,
protocol.Requests.FindSymbols,
protocol.Requests.FindUsages,
protocol.Requests.GetCodeActions,
protocol.Requests.GoToDefinition,
protocol.Requests.RunCodeAction,
protocol.Requests.SignatureHelp,
protocol.Requests.TypeLookup
];

const prioritySet = new Set<string>(priorityCommands);
Copy link
Contributor

Choose a reason for hiding this comment

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

This code looks awfully familiar. :D

Copy link
Member Author

Choose a reason for hiding this comment

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

const normalSet = new Set<string>(normalCommands);
const deferredSet = new Set<string>();

const nonDeferredSet = new Set<string>();

for (let command of priorityCommands) {
nonDeferredSet.add(command);
}

for (let command of normalCommands) {
nonDeferredSet.add(command);
}

export function isPriorityCommand(command: string) {
return prioritySet.has(command);
}

export function isNormalCommand(command: string) {
return normalSet.has(command);
}

export function isDeferredCommand(command: string) {
if (deferredSet.has(command)) {
return true;
}

if (nonDeferredSet.has(command)) {
return false;
}

deferredSet.add(command);
return true;
}
Loading