Adjust carat after insertion

This commit is contained in:
Arthur Ozga
2015-07-20 18:31:17 -07:00
parent 784fc89adc
commit 6d174a0f18
3 changed files with 23 additions and 13 deletions

View File

@@ -381,7 +381,7 @@ module Harness.LanguageService {
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: ts.FormatCodeOptions): ts.TextChange[] {
return unwrapJSONCallResult(this.shim.getFormattingEditsAfterKeystroke(fileName, position, key, JSON.stringify(options)));
}
getDocCommentScaffoldingAtPosition(fileName: string, position: number): string {
getDocCommentScaffoldingAtPosition(fileName: string, position: number): ts.TextInsertion {
return unwrapJSONCallResult(this.shim.getDocCommentScaffoldingAtPosition(fileName, position));
}
getEmitOutput(fileName: string): ts.EmitOutput {

View File

@@ -1035,7 +1035,7 @@ namespace ts {
getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[];
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[];
getDocCommentScaffoldingAtPosition(fileName: string, position: number): string;
getDocCommentScaffoldingAtPosition(fileName: string, position: number): TextInsertion;
getEmitOutput(fileName: string): EmitOutput;
@@ -1083,6 +1083,11 @@ namespace ts {
newText: string;
}
export interface TextInsertion {
newText: string;
cursorOffset: number;
}
export interface RenameLocation {
textSpan: TextSpan;
fileName: string;
@@ -6755,9 +6760,9 @@ namespace ts {
* @param position The (character-indexed) position in the file where the check should
* be performed.
*/
function getDocCommentScaffoldingAtPosition(fileName: string, position: number): string {
const nullResult = "/**";
const emptyCompletion = "/** */";
function getDocCommentScaffoldingAtPosition(fileName: string, position: number): TextInsertion {
const nullResult = { newText: "/**", cursorOffset: 3 };
const emptyCompletion = { newText: "/** */", cursorOffset: 3 };
let start = new Date().getTime();
let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
log("getDocCommentScaffoldingAtPosition: getCurrentSourceFile: " + (new Date().getTime() - start));
@@ -6783,9 +6788,15 @@ namespace ts {
let docParams = parameters.map((p, index) =>
indentationStr + " * @param " + (p.name.kind === SyntaxKind.Identifier ? (<Identifier>p.name).text : "param" + index.toString()) + "\n");
let result = "/**\n" + docParams.reduce((prev, cur) => prev + cur, "") + indentationStr + " */";
let result =
/* opening comment */ "/**\n" +
/* first line for function info */ indentationStr + " * \n" +
/* paramters */ docParams.reduce((prev, cur) => prev + cur, "") +
/* closing comment */ indentationStr + " */";
let cursorOffset = /* "/**\n" */ 4 + indentationStr.length + /* " * " */ 3;
return result;
return {newText: result, cursorOffset: cursorOffset };
}
function getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[] {

View File

@@ -205,6 +205,9 @@ namespace ts {
getFormattingEditsForDocument(fileName: string, options: string/*Services.FormatCodeOptions*/): string;
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: string/*Services.FormatCodeOptions*/): string;
/**
* Returns JSON-encoded value of the type TextInsertion.
*/
getDocCommentScaffoldingAtPosition(fileName: string, position: number): string;
getEmitOutput(fileName: string): string;
@@ -816,12 +819,8 @@ namespace ts {
public getDocCommentScaffoldingAtPosition(fileName: string, position: number): string {
return this.forwardJSONCall(
"getDocCommentScaffoldingAtPosition('" + fileName + "', " + position + ")",
() => {
var commentText = this.languageService.getDocCommentScaffoldingAtPosition(fileName, position);
return commentText;
}
)
() => this.languageService.getDocCommentScaffoldingAtPosition(fileName, position)
);
}
/// NAVIGATE TO