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

Eliminate Thennable<any> #2163

Merged
merged 3 commits into from
Apr 9, 2018
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
8 changes: 8 additions & 0 deletions src/CSharpExtensionExports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

export default interface CSharpExtensionExports {
initializationFinished: Promise<void>;
}
3 changes: 2 additions & 1 deletion src/coreclr-debug/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { CoreClrDebugUtil, DotnetInfo, } from './util';
import { PlatformInformation } from './../platform';
import { DebuggerPrerequisiteWarning, DebuggerPrerequisiteFailure, DebuggerNotInstalledFailure } from '../omnisharp/loggingEvents';
import { EventStream } from '../EventStream';
import CSharpExtensionExports from '../CSharpExtensionExports';

let _debugUtil: CoreClrDebugUtil = null;

export async function activate(thisExtension: vscode.Extension<any>, context: vscode.ExtensionContext, platformInformation: PlatformInformation, eventStream: EventStream) {
export async function activate(thisExtension: vscode.Extension<CSharpExtensionExports>, context: vscode.ExtensionContext, platformInformation: PlatformInformation, eventStream: EventStream) {
_debugUtil = new CoreClrDebugUtil(context.extensionPath);

if (!CoreClrDebugUtil.existsSync(_debugUtil.debugAdapterDir())) {
Expand Down
2 changes: 1 addition & 1 deletion src/features/codeActionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default class CodeActionProvider extends AbstractProvider implements vsco
});
}

private async _runCodeAction(req: protocol.V2.RunCodeActionRequest): Promise<any> {
private async _runCodeAction(req: protocol.V2.RunCodeActionRequest): Promise<boolean | string | {}> {

return serverUtils.runCodeAction(this._server, req).then(response => {

Expand Down
2 changes: 1 addition & 1 deletion src/features/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function pickProjectAndStart(server: OmniSharpServer) {
interface Command {
label: string;
description: string;
execute(): Thenable<any>;
execute(): Thenable<void>;
}

function projectsToCommands(projects: protocol.ProjectDescriptor[], eventStream: EventStream): Promise<Command>[] {
Expand Down
63 changes: 46 additions & 17 deletions src/features/dotnetTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { DebuggerEventsProtocol } from '../coreclr-debug/debuggerEventsProtocol'
import { OmniSharpServer } from '../omnisharp/server';
import { TestExecutionCountReport } from '../omnisharp/loggingEvents';
import { EventStream } from '../EventStream';
import LaunchConfiguration from './launchConfiguration';

const TelemetryReportingDelay = 2 * 60 * 1000; // two minutes

Expand Down Expand Up @@ -241,22 +242,29 @@ export default class TestManager extends AbstractProvider {
result = {};
}

if (!result.type) {
result.type = "coreclr";
}
let launchConfiguration: LaunchConfiguration = {
...result,
type: result.type || "coreclr",
name: ".NET Test Launch",
request: "launch",
debuggerEventsPipeName: debuggerEventsPipeName,
program: program,
args: args,
cwd: cwd
};


// Now fill in the rest of the options
result.name = ".NET Test Launch";
result.request = "launch";
result.debuggerEventsPipeName = debuggerEventsPipeName;
result.program = program;
result.args = args;
result.cwd = cwd;

return result;

return launchConfiguration;
}

private async _getLaunchConfigurationForVSTest(fileName: string, testMethod: string, testFrameworkName: string, targetFrameworkVersion: string, debugEventListener: DebugEventListener): Promise<any> {
private async _getLaunchConfigurationForVSTest(
fileName: string,
testMethod: string,
testFrameworkName: string,
targetFrameworkVersion: string,
debugEventListener: DebugEventListener): Promise<LaunchConfiguration> {
const output = this._getOutputChannel();

// Listen for test messages while getting start info.
Expand All @@ -274,11 +282,15 @@ export default class TestManager extends AbstractProvider {
return serverUtils.debugTestGetStartInfo(this._server, request)
.then(response => {
listener.dispose();
return this._createLaunchConfiguration(response.FileName, response.Arguments, response.WorkingDirectory, debugEventListener.pipePath());
return this._createLaunchConfiguration(
response.FileName,
response.Arguments,
response.WorkingDirectory,
debugEventListener.pipePath());
});
}

private async _getLaunchConfigurationForLegacy(fileName: string, testMethod: string, testFrameworkName: string, targetFrameworkVersion: string): Promise<any> {
private async _getLaunchConfigurationForLegacy(fileName: string, testMethod: string, testFrameworkName: string, targetFrameworkVersion: string): Promise<LaunchConfiguration> {
const output = this._getOutputChannel();

// Listen for test messages while getting start info.
Expand All @@ -300,7 +312,13 @@ export default class TestManager extends AbstractProvider {
});
}

private async _getLaunchConfiguration(debugType: string, fileName: string, testMethod: string, testFrameworkName: string, targetFrameworkVersion: string, debugEventListener: DebugEventListener): Promise<any> {
private async _getLaunchConfiguration(
debugType: string,
fileName: string,
testMethod: string,
testFrameworkName: string,
targetFrameworkVersion: string,
debugEventListener: DebugEventListener): Promise<LaunchConfiguration> {
switch (debugType) {
case 'legacy':
return this._getLaunchConfigurationForLegacy(fileName, testMethod, testFrameworkName, targetFrameworkVersion);
Expand Down Expand Up @@ -382,14 +400,25 @@ export default class TestManager extends AbstractProvider {
});
}

private async _getLaunchConfigurationForClass(debugType: string, fileName: string, methodsToRun: string[], testFrameworkName: string, targetFrameworkVersion: string, debugEventListener: DebugEventListener): Promise<any> {
private async _getLaunchConfigurationForClass(
debugType: string,
fileName: string,
methodsToRun: string[],
testFrameworkName: string,
targetFrameworkVersion: string,
debugEventListener: DebugEventListener): Promise<LaunchConfiguration> {
if (debugType == 'vstest') {
return this._getLaunchConfigurationForVSTestClass(fileName, methodsToRun, testFrameworkName, targetFrameworkVersion, debugEventListener);
}
throw new Error(`Unexpected debug type: ${debugType}`);
}

private async _getLaunchConfigurationForVSTestClass(fileName: string, methodsToRun: string[], testFrameworkName: string, targetFrameworkVersion: string, debugEventListener: DebugEventListener): Promise<any> {
private async _getLaunchConfigurationForVSTestClass(
fileName: string,
methodsToRun: string[],
testFrameworkName: string,
targetFrameworkVersion: string,
debugEventListener: DebugEventListener): Promise<LaunchConfiguration> {
const output = this._getOutputChannel();

const listener = this._server.onTestMessage(e => {
Expand Down
10 changes: 10 additions & 0 deletions src/features/json/NuGetFlatContainerPackageResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// Sample Request: https://api.nuget.org/v3-flatcontainer/FluentAssertions/index.json

export default interface NuGetFlatContainerPackageResponse {
versions: string[];
}
14 changes: 14 additions & 0 deletions src/features/json/NuGetIndexResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// Sample Request: https://api.nuget.org/v3/index.json
export default interface NuGetIndexResponse {
resources: NuGetResource[];
}

interface NuGetResource {
'@type': string;
'@id': string;
}
10 changes: 10 additions & 0 deletions src/features/json/NuGetSearchAutocompleteServiceResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// Sample Query: https://api-v2v3search-0.nuget.org/autocomplete

export default interface NuGetSearchAutocompleteServiceResponse {
data: string[];
}
16 changes: 16 additions & 0 deletions src/features/json/NuGetSearchQueryServiceResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// Sample Request: https://api-v2v3search-0.nuget.org/query?q=newtonsoft.json&take=5

export default interface NuGetSearchQueryServiceResponse {
data: NuGetSearchQueryServiceDataElement[];
}

interface NuGetSearchQueryServiceDataElement {
id: string;
description: string;
version: string;
}
8 changes: 4 additions & 4 deletions src/features/json/jsonContributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export interface ISuggestionsCollector {
export interface IJSONContribution {
getDocumentSelector(): DocumentSelector;
getInfoContribution(fileName: string, location: Location): Thenable<MarkedString[]>;
collectPropertySuggestions(fileName: string, location: Location, currentWord: string, addValue: boolean, isLast: boolean, result: ISuggestionsCollector): Thenable<any>;
collectValueSuggestions(fileName: string, location: Location, result: ISuggestionsCollector): Thenable<any>;
collectDefaultSuggestions(fileName: string, result: ISuggestionsCollector): Thenable<any>;
collectPropertySuggestions(fileName: string, location: Location, currentWord: string, addValue: boolean, isLast: boolean, result: ISuggestionsCollector): Thenable<void>;
collectValueSuggestions(fileName: string, location: Location, result: ISuggestionsCollector): Thenable<void>;
collectDefaultSuggestions(fileName: string, result: ISuggestionsCollector): Thenable<void>;
resolveSuggestion?(item: CompletionItem): Thenable<CompletionItem>;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
log: (message: string) => console.log(message)
};

let collectPromise: Thenable<any> = null;
let collectPromise: Thenable<void> = null;

if (location.isAtPropertyKey) {
let addValue = !location.previousNode || !location.previousNode.columnOffset && (offset == (location.previousNode.offset + location.previousNode.length));
Expand Down
32 changes: 21 additions & 11 deletions src/features/json/projectJSONContribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { IJSONContribution, ISuggestionsCollector } from './jsonContributions';
import { XHRRequest, XHRResponse, getErrorStatusDescription } from 'request-light';

import { Location } from 'jsonc-parser';
import NuGetIndexResponse from './NuGetIndexResponse';
import NuGetSearchAutocompleteServiceResponse from './NuGetSearchAutocompleteServiceResponse';
import NuGetFlatContainerPackageResponse from './NuGetFlatContainerPackageResponse';
import NuGetSearchQueryServiceResponse from './NuGetSearchQueryServiceResponse';

const localize = nls.loadMessageBundle();

Expand All @@ -36,10 +40,10 @@ export class ProjectJSONContribution implements IJSONContribution {

private getNugetIndex(): Thenable<NugetServices> {
if (!this.nugetIndexPromise) {
this.nugetIndexPromise = this.makeJSONRequest<any>(FEED_INDEX_URL).then(indexContent => {
this.nugetIndexPromise = this.makeJSONRequest<NuGetIndexResponse>(FEED_INDEX_URL).then(indexContent => {
let services: NugetServices = {};
if (indexContent && Array.isArray(indexContent.resources)) {
let resources = <any[]>indexContent.resources;
let resources = indexContent.resources;
for (let i = resources.length - 1; i >= 0; i--) {
let type = resources[i]['@type'];
let id = resources[i]['@id'];
Expand Down Expand Up @@ -81,7 +85,13 @@ export class ProjectJSONContribution implements IJSONContribution {
});
}

public collectPropertySuggestions(resource: string, location: Location, currentWord: string, addValue: boolean, isLast: boolean, result: ISuggestionsCollector): Thenable<any> {
public collectPropertySuggestions(
resource: string,
location: Location,
currentWord: string,
addValue: boolean,
isLast: boolean,
result: ISuggestionsCollector): Thenable<void> {
if ((location.matches(['dependencies']) || location.matches(['frameworks', '*', 'dependencies']) || location.matches(['frameworks', '*', 'frameworkAssemblies']))) {

return this.getNugetService('SearchAutocompleteService').then(service => {
Expand All @@ -91,9 +101,9 @@ export class ProjectJSONContribution implements IJSONContribution {
} else {
queryUrl = service + '?take=' + LIMIT;
}
return this.makeJSONRequest<any>(queryUrl).then(resultObj => {
return this.makeJSONRequest<NuGetSearchAutocompleteServiceResponse>(queryUrl).then(resultObj => {
if (Array.isArray(resultObj.data)) {
let results = <any[]>resultObj.data;
let results = resultObj.data;
for (let i = 0; i < results.length; i++) {
let name = results[i];
let insertText = JSON.stringify(name);
Expand Down Expand Up @@ -123,15 +133,15 @@ export class ProjectJSONContribution implements IJSONContribution {
return null;
}

public collectValueSuggestions(resource: string, location: Location, result: ISuggestionsCollector): Thenable<any> {
public collectValueSuggestions(resource: string, location: Location, result: ISuggestionsCollector): Thenable<void> {
if ((location.matches(['dependencies', '*']) || location.matches(['frameworks', '*', 'dependencies', '*']) || location.matches(['frameworks', '*', 'frameworkAssemblies', '*']))) {
return this.getNugetService('PackageBaseAddress/3.0.0').then(service => {
let currentKey = location.path[location.path.length - 1];
if (typeof currentKey === 'string') {
let queryUrl = service + currentKey + '/index.json';
return this.makeJSONRequest<any>(queryUrl).then(obj => {
return this.makeJSONRequest<NuGetFlatContainerPackageResponse>(queryUrl).then(obj => {
if (Array.isArray(obj.versions)) {
let results = <any[]>obj.versions;
let results = obj.versions;
for (let i = 0; i < results.length; i++) {
let curr = results[i];
let name = JSON.stringify(curr);
Expand All @@ -156,7 +166,7 @@ export class ProjectJSONContribution implements IJSONContribution {
return null;
}

public collectDefaultSuggestions(resource: string, result: ISuggestionsCollector): Thenable<any> {
public collectDefaultSuggestions(resource: string, result: ISuggestionsCollector): Thenable<null> {
let defaultValue = {
'version': '{{1.0.0-*}}',
'dependencies': {},
Expand Down Expand Up @@ -192,9 +202,9 @@ export class ProjectJSONContribution implements IJSONContribution {
private getInfo(pack: string): Thenable<{ description?: string; version?: string }> {
return this.getNugetService('SearchQueryService').then(service => {
let queryUrl = service + '?q=' + encodeURIComponent(pack) + '&take=' + 5;
return this.makeJSONRequest<any>(queryUrl).then(resultObj => {
return this.makeJSONRequest<NuGetSearchQueryServiceResponse>(queryUrl).then(resultObj => {
if (Array.isArray(resultObj.data)) {
let results = <any[]>resultObj.data;
let results = resultObj.data;
let info: { description?: string; version?: string } = {};
for (let i = 0; i < results.length; i++) {
let res = results[i];
Expand Down
13 changes: 13 additions & 0 deletions src/features/launchConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { DebugConfiguration } from "vscode";

export default interface LaunchConfiguration extends DebugConfiguration {
debuggerEventsPipeName?: string;
program?: string;
args?: string;
cwd?: string;
}
2 changes: 1 addition & 1 deletion src/features/processPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ async function execChildProcess(process: string, workingDirectory: string): Prom
// VSCode cannot find the path "c:\windows\system32\bash.exe" as bash.exe is only available on 64bit OS.
// It can be invoked from "c:\windows\sysnative\bash.exe", so adding "c:\windows\sysnative" to path if we identify
// VSCode is running in windows and doesn't have it in the path.
async function GetSysNativePathIfNeeded(): Promise<any> {
async function GetSysNativePathIfNeeded(): Promise<NodeJS.ProcessEnv> {
return PlatformInformation.GetCurrent().then(platformInfo => {
let env = process.env;
if (platformInfo.isWindows() && platformInfo.architecture === "x86_64") {
Expand Down
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import { TelemetryObserver } from './observers/TelemetryObserver';
import TelemetryReporter from 'vscode-extension-telemetry';
import { addJSONProviders } from './features/json/jsonContributions';
import { ProjectStatusBarObserver } from './observers/ProjectStatusBarObserver';
import CSharpExtensionExports from './CSharpExtensionExports';

export async function activate(context: vscode.ExtensionContext): Promise<{ initializationFinished: Promise<void> }> {
export async function activate(context: vscode.ExtensionContext): Promise<CSharpExtensionExports> {

const extensionId = 'ms-vscode.csharp';
const extension = vscode.extensions.getExtension(extensionId);
const extension = vscode.extensions.getExtension<CSharpExtensionExports>(extensionId);
const extensionVersion = extension.packageJSON.version;
const aiKey = extension.packageJSON.contributes.debuggers[0].aiKey;
const reporter = new TelemetryReporter(extensionId, extensionVersion, aiKey);
Expand Down Expand Up @@ -115,7 +116,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<{ init
};
}

async function ensureRuntimeDependencies(extension: vscode.Extension<any>, eventStream: EventStream, platformInfo: PlatformInformation): Promise<boolean> {
async function ensureRuntimeDependencies(extension: vscode.Extension<CSharpExtensionExports>, eventStream: EventStream, platformInfo: PlatformInformation): Promise<boolean> {
return util.installFileExists(util.InstallFileType.Lock)
.then(exists => {
if (!exists) {
Expand Down
2 changes: 1 addition & 1 deletion src/omnisharp/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function launchWindows(launchPath: string, cwd: string, args: string[]): LaunchR
'"' + argsCopy.map(escapeIfNeeded).join(' ') + '"'
].join(' ')];

let process = spawn('cmd', argsCopy, <any>{
let process = spawn('cmd', argsCopy, {
windowsVerbatimArguments: true,
detached: false,
cwd: cwd
Expand Down
Loading