Merge branch 'isInMultiLineComment' of https://github.com/aozgaa/TypeScript into isInMultiLineComment

This commit is contained in:
Arthur Ozga 2017-06-07 14:35:45 -07:00
commit 6b4cd0bd03
10 changed files with 77 additions and 0 deletions

View File

@ -2427,6 +2427,16 @@ namespace FourSlash {
}
}
public verifyIsInMultiLineComment(negative: boolean) {
const expected = !negative;
const position = this.currentCaretPosition;
const fileName = this.activeFile.fileName;
const actual = this.languageService.getIsInMultiLineComment(fileName, position);
if (expected !== actual) {
this.raiseError(`verifyIsInDocComment failed: at position '${position}' in '${fileName}', expected '${expected}'.`);
}
}
private clarifyNewlines(str: string) {
return str.replace(/\r?\n/g, lineEnding => {
const representation = lineEnding === "\r\n" ? "CRLF" : "LF";
@ -3577,6 +3587,10 @@ namespace FourSlashInterface {
this.state.verifyCodeFixAvailable(this.negative);
}
public isInMultiLineComment() {
this.state.verifyIsInMultiLineComment(this.negative);
}
public applicableRefactorAvailableAtMarker(markerName: string) {
this.state.verifyApplicableRefactorAvailableAtMarker(this.negative, markerName);
}

View File

@ -483,6 +483,9 @@ namespace Harness.LanguageService {
getDocCommentTemplateAtPosition(fileName: string, position: number): ts.TextInsertion {
return unwrapJSONCallResult(this.shim.getDocCommentTemplateAtPosition(fileName, position));
}
getIsInMultiLineComment(fileName: string, position: number): boolean {
return unwrapJSONCallResult(this.shim.getIsInMultiLineComment(fileName, position));
}
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean {
return unwrapJSONCallResult(this.shim.isValidBraceCompletionAtPosition(fileName, position, openingBrace));
}

View File

@ -672,6 +672,10 @@ namespace ts.server {
return notImplemented();
}
getIsInMultiLineComment(_fileName: string, _position: number): boolean {
return notImplemented();
}
isValidBraceCompletionAtPosition(_fileName: string, _position: number, _openingBrace: number): boolean {
return notImplemented();
}

View File

@ -85,6 +85,7 @@ namespace ts.server.protocol {
TodoComments = "todoComments",
Indentation = "indentation",
DocCommentTemplate = "docCommentTemplate",
IsInMultiLineComment = "isInMultiLineComment",
/* @internal */
CompilerOptionsDiagnosticsFull = "compilerOptionsDiagnostics-full",
/* @internal */
@ -238,6 +239,20 @@ namespace ts.server.protocol {
body?: TodoComment[];
}
/**
* A request to determine if the caret is inside a multi-line comment.
*/
export interface IsInMultiLineCommentRequest extends FileLocationRequest {
command: CommandTypes.IsInMultiLineComment;
}
/**
* Response for TodoCommentRequest request.
*/
export interface IsInMultiLineCommentResponse extends Response {
body?: { isInMultiLineComment: boolean };
}
/**
* Request to obtain outlining spans in file.
*/

View File

@ -961,6 +961,13 @@ namespace ts.server {
return project.getLanguageService(/*ensureSynchronized*/ false).getDocCommentTemplateAtPosition(file, position);
}
private getIsInMultiLineComment(args: protocol.FileLocationRequestArgs) {
const { file, project } = this.getFileAndProjectWithoutRefreshingInferredProjects(args);
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
const position = this.getPosition(args, scriptInfo);
return project.getLanguageService(/*ensureSynchronized*/ false).getIsInMultiLineComment(file, position);
}
private getIndentation(args: protocol.IndentationRequestArgs) {
const { file, project } = this.getFileAndProjectWithoutRefreshingInferredProjects(args);
const position = this.getPosition(args, project.getScriptInfoForNormalizedPath(file));
@ -1694,6 +1701,9 @@ namespace ts.server {
[CommandNames.DocCommentTemplate]: (request: protocol.DocCommentTemplateRequest) => {
return this.requiredResponse(this.getDocCommentTemplate(request.arguments));
},
[CommandNames.IsInMultiLineComment]: (request: protocol.IsInMultiLineCommentRequest) => {
return this.requiredResponse(this.getIsInMultiLineComment(request.arguments));
},
[CommandNames.Format]: (request: protocol.FormatRequest) => {
return this.requiredResponse(this.getFormattingEditsForRange(request.arguments));
},

View File

@ -1789,6 +1789,16 @@ namespace ts {
return JsDoc.getDocCommentTemplateAtPosition(getNewLineOrDefaultFromHost(host), syntaxTreeCache.getCurrentSourceFile(fileName), position);
}
function getIsInMultiLineComment(_fileName: string, position: number): boolean {
const sourceFile = syntaxTreeCache.getCurrentSourceFile(_fileName);
const token = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ true);
const _triviaWidth = token.getLeadingTriviaWidth(sourceFile); _triviaWidth;
const _text = token.getText(sourceFile); _text;
const _fullText = token.getFullText(sourceFile); _fullText;
// TODO: distinguish multi-line and single line comments...
return token.getFullStart() <= position && position < token.getStart(sourceFile, /*includeJsDocComment*/ false);
}
function isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean {
// '<' is currently not supported, figuring out if we're in a Generic Type vs. a comparison is too
// expensive to do during typing scenarios
@ -2039,6 +2049,7 @@ namespace ts {
getFormattingEditsForDocument,
getFormattingEditsAfterKeystroke,
getDocCommentTemplateAtPosition,
getIsInMultiLineComment,
isValidBraceCompletionAtPosition,
getCodeFixesAtPosition,
getEmitOutput,

View File

@ -247,6 +247,11 @@ namespace ts {
*/
getDocCommentTemplateAtPosition(fileName: string, position: number): string;
/**
* Returns JSON-encoded value of the type TextInsertion.
*/
getIsInMultiLineComment(fileName: string, position: number): string;
/**
* Returns JSON-encoded boolean to indicate whether we should support brace location
* at the current position.
@ -935,6 +940,13 @@ namespace ts {
);
}
public getIsInMultiLineComment(fileName: string, position: number): string {
return this.forwardJSONCall(
`getIsInMultiLineComment('${fileName}', ${position})`,
() => this.languageService.getIsInMultiLineComment(fileName, position)
);
}
/// NAVIGATE TO
/** Return a list of symbols that are interesting to navigate to */

View File

@ -257,6 +257,7 @@ namespace ts {
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[];
getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion;
getIsInMultiLineComment(fileName: string, position: number): boolean;
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;

View File

@ -150,6 +150,7 @@ declare namespace FourSlashInterface {
implementationListIsEmpty(): void;
isValidBraceCompletionAtPosition(openingBrace?: string): void;
codeFixAvailable(): void;
isInMultiLineComment(): void;
applicableRefactorAvailableAtMarker(markerName: string): void;
codeFixDiagnosticsAvailableAtMarkers(markerNames: string[], diagnosticCode?: number): void;
applicableRefactorAvailableForRange(): void;

View File

@ -0,0 +1,6 @@
/// <reference path="fourslash.ts" />
//// /* blach /*m0*/ */ let x = 10;
goTo.marker("m0");
verify.isInMultiLineComment();