mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 17:27:54 -05:00
PR Feedback
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/// <reference path="types.ts"/>
|
||||
/// <reference path="types.ts"/>
|
||||
/// <reference path="performance.ts" />
|
||||
|
||||
|
||||
@@ -115,15 +115,6 @@ namespace ts {
|
||||
return -1;
|
||||
}
|
||||
|
||||
export function firstOrUndefined<T>(array: T[], predicate: (x: T) => boolean): T {
|
||||
for (let i = 0, len = array.length; i < len; i++) {
|
||||
if (predicate(array[i])) {
|
||||
return array[i];
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function indexOfAnyCharCode(text: string, charCodes: number[], start?: number): number {
|
||||
for (let i = start || 0, len = text.length; i < len; i++) {
|
||||
if (contains(charCodes, text.charCodeAt(i))) {
|
||||
@@ -229,6 +220,19 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element that matches the predicate, or undefined if none
|
||||
* could be found.
|
||||
*/
|
||||
export function find<T>(array: T[], predicate: (item: T) => boolean): T {
|
||||
for (let i = 0, len = array.length; i < len; i++) {
|
||||
if (predicate(array[i])) {
|
||||
return array[i];
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last element of an array if non-empty, undefined otherwise.
|
||||
*/
|
||||
|
||||
@@ -3033,31 +3033,31 @@
|
||||
"code": 17010
|
||||
},
|
||||
"Add missing 'super()' call.": {
|
||||
"category": "CodeFix",
|
||||
"category": "Message",
|
||||
"code": 90001
|
||||
},
|
||||
"Make 'super()' call the first statement in the constructor.": {
|
||||
"category": "CodeFix",
|
||||
"category": "Message",
|
||||
"code": 90002
|
||||
},
|
||||
"Change 'extends' to 'implements'": {
|
||||
"category": "CodeFix",
|
||||
"category": "Message",
|
||||
"code": 90003
|
||||
},
|
||||
"Remove unused identifiers": {
|
||||
"category": "CodeFix",
|
||||
"category": "Message",
|
||||
"code": 90004
|
||||
},
|
||||
"Implement interface on reference": {
|
||||
"category": "CodeFix",
|
||||
"category": "Message",
|
||||
"code": 90005
|
||||
},
|
||||
"Implement interface on class": {
|
||||
"category": "CodeFix",
|
||||
"category": "Message",
|
||||
"code": 90006
|
||||
},
|
||||
"Implement inherited abstract class": {
|
||||
"category": "CodeFix",
|
||||
"category": "Message",
|
||||
"code": 90007
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2547,7 +2547,6 @@ namespace ts {
|
||||
Warning,
|
||||
Error,
|
||||
Message,
|
||||
CodeFix,
|
||||
}
|
||||
|
||||
export enum ModuleResolutionKind {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -1879,11 +1879,11 @@ namespace FourSlash {
|
||||
this.raiseError("Errors expected.");
|
||||
}
|
||||
|
||||
if (diagnostics.length > 1 && !errorCode) {
|
||||
if (diagnostics.length > 1 && errorCode !== undefined) {
|
||||
this.raiseError("When there's more than one error, you must specify the errror to fix.");
|
||||
}
|
||||
|
||||
const diagnostic = !errorCode ? diagnostics[0] : ts.firstOrUndefined(diagnostics, d => d.code == errorCode);
|
||||
const diagnostic = !errorCode ? diagnostics[0] : ts.find(diagnostics, d => d.code == errorCode);
|
||||
|
||||
const actual = this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.length, [`TS${diagnostic.code}`]);
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/* @internal */
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
export interface CodeFix {
|
||||
name: string;
|
||||
errorCodes: string[];
|
||||
getCodeActions(context: CodeFixContext): CodeAction[];
|
||||
}
|
||||
@@ -14,7 +13,7 @@ namespace ts {
|
||||
newLineCharacter: string;
|
||||
}
|
||||
|
||||
export namespace codeFix {
|
||||
export namespace codefix {
|
||||
const codeFixes: Map<CodeFix[]> = {};
|
||||
|
||||
export function registerCodeFix(action: CodeFix) {
|
||||
@@ -37,8 +36,6 @@ namespace ts {
|
||||
const fixes = codeFixes[context.errorCode];
|
||||
let allActions: CodeAction[] = [];
|
||||
|
||||
Debug.assert(fixes && fixes.length > 0, "No fixes found for error: '${errorCode}'.");
|
||||
|
||||
forEach(fixes, f => {
|
||||
const actions = f.getCodeActions(context);
|
||||
if (actions && actions.length > 0) {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
///<reference path='..\services.ts' />
|
||||
///<reference path='codeFixProvider.ts' />
|
||||
///<reference path='superFixes.ts' />
|
||||
///<reference path='unusedIdentifierFixes.ts' />
|
||||
///<reference path='changeExtendsToImplementsFix.ts' />
|
||||
///<reference path='interfaceFixes.ts' />
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
/* @internal */
|
||||
namespace ts.codeFix {
|
||||
namespace ts.codefix {
|
||||
function getOpenBraceEnd(constructor: ConstructorDeclaration, sourceFile: SourceFile) {
|
||||
// First token is the open curly, this is where we want to put the 'super' call.
|
||||
return constructor.body.getFirstToken(sourceFile).getEnd();
|
||||
}
|
||||
|
||||
registerCodeFix({
|
||||
name: "AddMissingSuperCallFix",
|
||||
errorCodes: ["TS2377"],
|
||||
errorCodes: [`TS${Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call.code}`],
|
||||
getCodeActions: (context: CodeFixContext) => {
|
||||
const sourceFile = context.sourceFile;
|
||||
const token = getTokenAtPosition(sourceFile, context.span.start);
|
||||
@@ -22,8 +21,7 @@ namespace ts.codeFix {
|
||||
});
|
||||
|
||||
registerCodeFix({
|
||||
name: "MakeSuperCallTheFirstStatementInTheConstructor",
|
||||
errorCodes: ["TS17009"],
|
||||
errorCodes: [`TS${Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class.code}`],
|
||||
getCodeActions: (context: CodeFixContext) => {
|
||||
const sourceFile = context.sourceFile;
|
||||
|
||||
|
||||
@@ -1902,7 +1902,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function getSupportedCodeFixes() {
|
||||
return codeFix.CodeFixProvider.getSupportedErrorCodes();
|
||||
return codefix.CodeFixProvider.getSupportedErrorCodes();
|
||||
}
|
||||
|
||||
// Cache host information about script Should be refreshed
|
||||
@@ -3041,7 +3041,7 @@ namespace ts {
|
||||
documentRegistry: DocumentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory())): LanguageService {
|
||||
|
||||
const syntaxTreeCache: SyntaxTreeCache = new SyntaxTreeCache(host);
|
||||
const codeFixProvider: codeFix.CodeFixProvider = new codeFix.CodeFixProvider();
|
||||
const codeFixProvider: codefix.CodeFixProvider = new codefix.CodeFixProvider();
|
||||
let ruleProvider: formatting.RulesProvider;
|
||||
let program: Program;
|
||||
let lastProjectVersion: string;
|
||||
|
||||
Reference in New Issue
Block a user