Merge pull request #19359 from Microsoft/port-master-10-19-2

Port master into release-2.6 10/19
This commit is contained in:
Mohamed Hegazy 2017-10-19 16:04:43 -07:00 committed by GitHub
commit 46b866c126
7 changed files with 151 additions and 19 deletions

View File

@ -351,7 +351,7 @@ namespace ts {
/**
* We assume the first line starts at position 0 and 'position' is non-negative.
*/
export function computeLineAndCharacterOfPosition(lineStarts: ReadonlyArray<number>, position: number) {
export function computeLineAndCharacterOfPosition(lineStarts: ReadonlyArray<number>, position: number): LineAndCharacter {
let lineNumber = binarySearch(lineStarts, position);
if (lineNumber < 0) {
// If the actual position was not found,

View File

@ -3811,9 +3811,10 @@ namespace ts {
}
export interface LineAndCharacter {
/** 0-based. */
line: number;
/*
* This value denotes the character position in line and is different from the 'column' because of tab characters.
* 0-based. This value denotes the character position in line and is different from the 'column' because of tab characters.
*/
character: number;
}

View File

@ -661,4 +661,28 @@ namespace ts.server {
session.consumeQueue();
});
});
describe("helpers", () => {
it(getLocationInNewDocument.name, () => {
const text = `// blank line\nconst x = 0;`;
const renameLocationInOldText = text.indexOf("0");
const fileName = "/a.ts";
const edits: ts.FileTextChanges = {
fileName,
textChanges: [
{
span: { start: 0, length: 0 },
newText: "const newLocal = 0;\n\n",
},
{
span: { start: renameLocationInOldText, length: 1 },
newText: "newLocal",
},
],
};
const renameLocationInNewText = renameLocationInOldText + edits.textChanges[0].newText.length;
const res = getLocationInNewDocument(text, fileName, renameLocationInNewText, [edits]);
assert.deepEqual(res, { line: 4, offset: 11 });
});
});
}

View File

@ -785,6 +785,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor_2715" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Abstract property '{0}' in class '{1}' cannot be accessed in the constructor.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['{1}' sınıfındaki '{0}' soyut özelliğine oluşturucuda erişilemiyor.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Accessibility_modifier_already_seen_1028" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Accessibility modifier already seen.]]></Val>
@ -1322,6 +1331,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Annotate_with_type_from_JSDoc_95009" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Annotate with type from JSDoc]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[JSDoc türü ile not ekle]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Annotate_with_types_from_JSDoc_95010" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Annotate with types from JSDoc]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[JSDoc türleri ile not ekle]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Argument_expression_expected_1135" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Argument expression expected.]]></Val>
@ -1469,6 +1496,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Call_decorator_expression_90028" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Call decorator expression.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Dekoratör ifadesini çağırın.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type_7020" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Call signature, which lacks return-type annotation, implicitly has an 'any' return type.]]></Val>
@ -1876,12 +1912,12 @@
</Item>
<Item ItemId=";Change_0_to_1_90014" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Change {0} to {1}.]]></Val>
<Val><![CDATA[Change '{0}' to '{1}'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[{0} öğesini {1} olarak değiştirin.]]></Val>
<Val><![CDATA['{0}' değerini '{1}' olarak değiştirin.]]></Val>
</Tgt>
<Prev Cat="Text">
<Val><![CDATA[Change {0} to {1}]]></Val>
<Val><![CDATA[Change {0} to {1}.]]></Val>
</Prev>
</Str>
<Disp Icon="Str" />
@ -1997,6 +2033,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Class_declarations_cannot_have_more_than_one_augments_or_extends_tag_8025" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Class declarations cannot have more than one `@augments` or `@extends` tag.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Sınıf bildirimlerinde birden fazla `@augments` veya `@extends` etiketi olamaz.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Class_name_cannot_be_0_2414" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Class name cannot be '{0}'.]]></Val>
@ -3779,6 +3824,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Infer_parameter_types_from_usage_95012" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Infer parameter types from usage.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Parametre türlerini kullanımdan çıkarsayın.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Infer_type_of_0_from_usage_95011" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Infer type of '{0}' from usage.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['{0}' türünü kullanımdan çıkarsayın.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Initialize_property_0_in_the_constructor_90020" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Initialize property '{0}' in the constructor.]]></Val>
@ -3971,20 +4034,20 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";JSDoc_augments_0_does_not_match_the_extends_1_clause_8023" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";JSDoc_0_1_does_not_match_the_extends_2_clause_8023" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[JSDoc '@augments {0}' does not match the 'extends {1}' clause.]]></Val>
<Val><![CDATA[JSDoc '@{0} {1}' does not match the 'extends {2}' clause.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[JSDoc '@augments {0}', 'extends {1}' yan tümcesiyle eşleşmiyor.]]></Val>
<Val><![CDATA[JSDoc '@{0} {1}', 'extends {2}' yan tümcesiyle eşleşmiyor.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";JSDoc_augments_is_not_attached_to_a_class_declaration_8022" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";JSDoc_0_is_not_attached_to_a_class_8022" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[JSDoc '@augments' is not attached to a class declaration.]]></Val>
<Val><![CDATA[JSDoc '@{0}' is not attached to a class.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[JSDoc '@augments', bir sınıf bildirimine eklenmemiş.]]></Val>
<Val><![CDATA[JSDoc '@{0}' bir sınıfa eklenmemiş.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
@ -7247,6 +7310,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Type_parameter_0_has_a_circular_default_2716" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Type parameter '{0}' has a circular default.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['{0}' tür parametresi döngüsel bir varsayılana sahip.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1_4008" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'.]]></Val>
@ -7727,6 +7799,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_accepts_too_few_arguments_to_be_used_as_a_decorator_here_Did_you_mean_to_call_it_first_and_write__1329" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@{0}()'?]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['{0}' burada dekoratör olarak kullanılmak için çok az bağımsız değişken kabul ediyor. Önce çağırıp '@{0}()' yazmak mı istediniz?]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_are_specified_twice_The_attribute_named_0_will_be_overwritten_2710" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' are specified twice. The attribute named '{0}' will be overwritten.]]></Val>

View File

@ -1514,16 +1514,18 @@ namespace ts.server {
}
if (simplifiedResult) {
const file = result.renameFilename;
let location: protocol.Location | undefined;
if (file !== undefined && result.renameLocation !== undefined) {
const renameScriptInfo = project.getScriptInfoForNormalizedPath(toNormalizedPath(file));
location = renameScriptInfo.positionToLineOffset(result.renameLocation);
const { renameFilename, renameLocation, edits } = result;
let mappedRenameLocation: protocol.Location | undefined;
if (renameFilename !== undefined && renameLocation !== undefined) {
const renameScriptInfo = project.getScriptInfoForNormalizedPath(toNormalizedPath(renameFilename));
const snapshot = renameScriptInfo.getSnapshot();
const oldText = snapshot.getText(0, snapshot.getLength());
mappedRenameLocation = getLocationInNewDocument(oldText, renameFilename, renameLocation, edits);
}
return {
renameLocation: location,
renameFilename: file,
edits: result.edits.map(change => this.mapTextChangesToCodeEdits(project, change))
renameLocation: mappedRenameLocation,
renameFilename,
edits: edits.map(change => this.mapTextChangesToCodeEdits(project, change))
};
}
else {
@ -2040,4 +2042,26 @@ namespace ts.server {
response?: {};
responseRequired?: boolean;
}
/* @internal */ // Exported only for tests
export function getLocationInNewDocument(oldText: string, renameFilename: string, renameLocation: number, edits: ReadonlyArray<FileTextChanges>): protocol.Location {
const newText = applyEdits(oldText, renameFilename, edits);
const { line, character } = computeLineAndCharacterOfPosition(computeLineStarts(newText), renameLocation);
return { line: line + 1, offset: character + 1 };
}
function applyEdits(text: string, textFilename: string, edits: ReadonlyArray<FileTextChanges>): string {
for (const { fileName, textChanges } of edits) {
if (fileName !== textFilename) {
continue;
}
for (let i = textChanges.length - 1; i >= 0; i--) {
const { newText, span: { start, length } } = textChanges[i];
text = text.slice(0, start) + newText + text.slice(start + length);
}
}
return text;
}
}

View File

@ -2307,6 +2307,7 @@ declare namespace ts {
LineFeed = 1,
}
interface LineAndCharacter {
/** 0-based. */
line: number;
character: number;
}

View File

@ -2307,6 +2307,7 @@ declare namespace ts {
LineFeed = 1,
}
interface LineAndCharacter {
/** 0-based. */
line: number;
character: number;
}