Skip to content

Commit

Permalink
Merge pull request #1789 from DustinCampbell/tweak-mono-launch
Browse files Browse the repository at this point in the history
Revisit launch on Mono
  • Loading branch information
DustinCampbell authored Oct 16, 2017
2 parents 64b4921 + 771dc9e commit f993d74
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
45 changes: 28 additions & 17 deletions src/omnisharp/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ export function launchOmniSharp(cwd: string, args: string[]): Promise<LaunchResu
setTimeout(function () {
resolve(result);
}, 0);
});
})
.catch(reason => reject(reason));
});
}

Expand All @@ -215,18 +216,36 @@ function launch(cwd: string, args: string[]): Promise<LaunchResult> {
args.push(`formattingOptions:indentationSize=${getConfigurationValue(globalConfig, csharpConfig, 'editor.tabSize', 4)}`);
}

if (options.path && options.useMono) {
return launchNixMono(options.path, cwd, args);
// If the user has provide a path to OmniSharp, we'll use that.
if (options.path) {
if (platformInfo.isWindows()) {
return launchWindows(options.path, cwd, args);
}

// If we're launching on macOS/Linux, we have two possibilities:
// 1. Launch using Mono
// 2. Launch process directly (e.g. a 'run' script)
return options.useMono
? launchNixMono(options.path, cwd, args)
: launchNix(options.path, cwd, args);
}

const launchPath = options.path || getLaunchPath(platformInfo);
// If the user has not provided a path, we'll use the locally-installed OmniSharp
const basePath = path.resolve(util.getExtensionPath(), '.omnisharp');

if (platformInfo.isWindows()) {
return launchWindows(launchPath, cwd, args);
}
else {
return launchNix(launchPath, cwd, args);
return launchWindows(path.join(basePath, 'OmniSharp.exe'), cwd, args);
}

// If it's possible to launch on a global Mono, we'll do that. Otherwise, run with our
// locally installed Mono runtime.
return canLaunchMono()
.then(() => {
return launchNixMono(path.join(basePath, 'omnisharp', 'OmniSharp.exe'), cwd, args);
})
.catch(_ => {
return launchNix(path.join(basePath, 'run'), cwd, args);
});
});
}

Expand All @@ -240,14 +259,6 @@ function getConfigurationValue(globalConfig: vscode.WorkspaceConfiguration, csha
return globalConfig.get(configurationPath, defaultValue);
}

function getLaunchPath(platformInfo: PlatformInformation): string {
const binPath = path.resolve(util.getExtensionPath(), '.omnisharp');

return platformInfo.isWindows()
? path.join(binPath, 'OmniSharp.exe')
: path.join(binPath, 'run');
}

function launchWindows(launchPath: string, cwd: string, args: string[]): LaunchResult {
function escapeIfNeeded(arg: string) {
const hasSpaceWithoutQuotes = /^[^"].* .*[^"]/;
Expand Down Expand Up @@ -294,8 +305,8 @@ function launchNixMono(launchPath: string, cwd: string, args: string[]): Promise
return canLaunchMono()
.then(() => {
let argsCopy = args.slice(0); // create copy of details args
argsCopy.unshift("--assembly-loader=strict");
argsCopy.unshift(launchPath);
argsCopy.unshift("--assembly-loader=strict");

let process = spawn('mono', argsCopy, {
detached: false,
Expand Down
2 changes: 2 additions & 0 deletions src/omnisharp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ export class OmniSharpServer {
}

private _onLineReceived(line: string) {
line = line.trim();

if (line[0] !== '{') {
this._logger.appendLine(line);
return;
Expand Down

0 comments on commit f993d74

Please sign in to comment.