mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Fixed lint issues
This commit is contained in:
parent
ee37d8e8d3
commit
35a3d8547b
@ -832,4 +832,4 @@ namespace ts.server {
|
||||
throw new Error("dispose is not available through the server layer.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3659,8 +3659,8 @@ namespace FourSlash {
|
||||
}
|
||||
|
||||
public toggleLineComment(newFileContent: string): void {
|
||||
let changes: ts.TextChange[] = [];
|
||||
for (let range of this.getRanges()) {
|
||||
const changes: ts.TextChange[] = [];
|
||||
for (const range of this.getRanges()) {
|
||||
changes.push.apply(changes, this.languageService.toggleLineComment(this.activeFile.fileName, range));
|
||||
}
|
||||
|
||||
@ -3670,8 +3670,8 @@ namespace FourSlash {
|
||||
}
|
||||
|
||||
public toggleMultilineComment(newFileContent: string): void {
|
||||
let changes: ts.TextChange[] = [];
|
||||
for (let range of this.getRanges()) {
|
||||
const changes: ts.TextChange[] = [];
|
||||
for (const range of this.getRanges()) {
|
||||
changes.push.apply(changes, this.languageService.toggleMultilineComment(this.activeFile.fileName, range));
|
||||
}
|
||||
|
||||
@ -3681,8 +3681,8 @@ namespace FourSlash {
|
||||
}
|
||||
|
||||
public commentSelection(newFileContent: string): void {
|
||||
let changes: ts.TextChange[] = [];
|
||||
for (let range of this.getRanges()) {
|
||||
const changes: ts.TextChange[] = [];
|
||||
for (const range of this.getRanges()) {
|
||||
changes.push.apply(changes, this.languageService.commentSelection(this.activeFile.fileName, range));
|
||||
}
|
||||
|
||||
@ -3692,8 +3692,8 @@ namespace FourSlash {
|
||||
}
|
||||
|
||||
public uncommentSelection(newFileContent: string): void {
|
||||
let changes: ts.TextChange[] = [];
|
||||
for (let range of this.getRanges()) {
|
||||
const changes: ts.TextChange[] = [];
|
||||
for (const range of this.getRanges()) {
|
||||
changes.push.apply(changes, this.languageService.uncommentSelection(this.activeFile.fileName, range));
|
||||
}
|
||||
|
||||
|
||||
@ -2711,28 +2711,28 @@ namespace ts.server {
|
||||
return this.requiredResponse(this.provideCallHierarchyOutgoingCalls(request.arguments));
|
||||
},
|
||||
[CommandNames.ToggleLineComment]: (request: protocol.ToggleLineCommentRequest) => {
|
||||
return this.requiredResponse(this.toggleLineComment(request.arguments, /*simplifiedResult*/true));
|
||||
return this.requiredResponse(this.toggleLineComment(request.arguments, /*simplifiedResult*/ true));
|
||||
},
|
||||
[CommandNames.ToggleLineCommentFull]: (request: protocol.ToggleLineCommentRequest) => {
|
||||
return this.requiredResponse(this.toggleLineComment(request.arguments, /*simplifiedResult*/false));
|
||||
return this.requiredResponse(this.toggleLineComment(request.arguments, /*simplifiedResult*/ false));
|
||||
},
|
||||
[CommandNames.ToggleMultilineComment]: (request: protocol.ToggleMultilineCommentRequest) => {
|
||||
return this.requiredResponse(this.toggleMultilineComment(request.arguments, /*simplifiedResult*/true));
|
||||
return this.requiredResponse(this.toggleMultilineComment(request.arguments, /*simplifiedResult*/ true));
|
||||
},
|
||||
[CommandNames.ToggleMultilineCommentFull]: (request: protocol.ToggleMultilineCommentRequest) => {
|
||||
return this.requiredResponse(this.toggleMultilineComment(request.arguments, /*simplifiedResult*/false));
|
||||
return this.requiredResponse(this.toggleMultilineComment(request.arguments, /*simplifiedResult*/ false));
|
||||
},
|
||||
[CommandNames.CommentSelection]: (request: protocol.CommentSelectionRequest) => {
|
||||
return this.requiredResponse(this.commentSelection(request.arguments, /*simplifiedResult*/true));
|
||||
return this.requiredResponse(this.commentSelection(request.arguments, /*simplifiedResult*/ true));
|
||||
},
|
||||
[CommandNames.CommentSelectionFull]: (request: protocol.CommentSelectionRequest) => {
|
||||
return this.requiredResponse(this.commentSelection(request.arguments, /*simplifiedResult*/false));
|
||||
return this.requiredResponse(this.commentSelection(request.arguments, /*simplifiedResult*/ false));
|
||||
},
|
||||
[CommandNames.UncommentSelection]: (request: protocol.UncommentSelectionRequest) => {
|
||||
return this.requiredResponse(this.uncommentSelection(request.arguments, /*simplifiedResult*/true));
|
||||
return this.requiredResponse(this.uncommentSelection(request.arguments, /*simplifiedResult*/ true));
|
||||
},
|
||||
[CommandNames.UncommentSelectionFull]: (request: protocol.UncommentSelectionRequest) => {
|
||||
return this.requiredResponse(this.uncommentSelection(request.arguments, /*simplifiedResult*/false));
|
||||
return this.requiredResponse(this.uncommentSelection(request.arguments, /*simplifiedResult*/ false));
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -1982,7 +1982,7 @@ namespace ts {
|
||||
lineStarts: sourceFile.getLineStarts(),
|
||||
firstLine: sourceFile.getLineAndCharacterOfPosition(textRange.pos).line,
|
||||
lastLine: sourceFile.getLineAndCharacterOfPosition(textRange.end).line
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function toggleLineComment(fileName: string, textRange: TextRange, insertComment?: boolean): TextChange[] {
|
||||
@ -1992,9 +1992,9 @@ namespace ts {
|
||||
|
||||
let isCommenting = insertComment || false;
|
||||
let leftMostPosition = Number.MAX_VALUE;
|
||||
let lineTextStarts = new Map<number>();
|
||||
const lineTextStarts = new Map<number>();
|
||||
const whiteSpaceRegex = new RegExp(/\S/);
|
||||
const isJsx = isInsideJsxElement(sourceFile, lineStarts[firstLine])
|
||||
const isJsx = isInsideJsxElement(sourceFile, lineStarts[firstLine]);
|
||||
const openComment = isJsx ? "{/*" : "//";
|
||||
|
||||
// Check each line before any text changes.
|
||||
@ -2021,7 +2021,8 @@ namespace ts {
|
||||
if (lineTextStart !== undefined) {
|
||||
if (isJsx) {
|
||||
textChanges.push.apply(textChanges, toggleMultilineComment(fileName, { pos: lineStarts[i] + leftMostPosition, end: sourceFile.getLineEndOfPosition(lineStarts[i]) }, isCommenting, isJsx));
|
||||
} else if (isCommenting) {
|
||||
}
|
||||
else if (isCommenting) {
|
||||
textChanges.push({
|
||||
newText: openComment,
|
||||
span: {
|
||||
@ -2029,7 +2030,8 @@ namespace ts {
|
||||
start: lineStarts[i] + leftMostPosition
|
||||
}
|
||||
});
|
||||
} else if (sourceFile.text.substr(lineStarts[i] + lineTextStart, openComment.length) === openComment) {
|
||||
}
|
||||
else if (sourceFile.text.substr(lineStarts[i] + lineTextStart, openComment.length) === openComment) {
|
||||
textChanges.push({
|
||||
newText: "",
|
||||
span: {
|
||||
@ -2080,8 +2082,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
pos = commentRange.end + 1;
|
||||
} else { // If it's not in a comment range, then we need to comment the uncommented portions.
|
||||
let newPos = text.substring(pos, textRange.end).search(`(${openMultilineRegex})|(${closeMultilineRegex})`);
|
||||
}
|
||||
else { // If it's not in a comment range, then we need to comment the uncommented portions.
|
||||
const newPos = text.substring(pos, textRange.end).search(`(${openMultilineRegex})|(${closeMultilineRegex})`);
|
||||
|
||||
isCommenting = insertComment !== undefined
|
||||
? insertComment
|
||||
@ -2141,16 +2144,17 @@ namespace ts {
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// If is not commenting then remove all comments found.
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
const from = positions[i] - closeMultiline.length > 0 ? positions[i] - closeMultiline.length : 0;
|
||||
for (const pos of positions) {
|
||||
const from = pos - closeMultiline.length > 0 ? pos - closeMultiline.length : 0;
|
||||
const offset = text.substr(from, closeMultiline.length) === closeMultiline ? closeMultiline.length : 0;
|
||||
textChanges.push({
|
||||
newText: "",
|
||||
span: {
|
||||
length: openMultiline.length,
|
||||
start: positions[i] - offset
|
||||
start: pos - offset
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -2160,21 +2164,22 @@ namespace ts {
|
||||
}
|
||||
|
||||
function commentSelection(fileName: string, textRange: TextRange): TextChange[] {
|
||||
return toggleLineComment(fileName, textRange, true);
|
||||
return toggleLineComment(fileName, textRange, /*insertComment*/ true);
|
||||
}
|
||||
|
||||
function uncommentSelection(fileName: string, textRange: TextRange): TextChange[] {
|
||||
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
|
||||
const textChanges: TextChange[] = [];
|
||||
|
||||
for (let i = textRange.pos; i <= textRange.end; i++) {
|
||||
let commentRange = isInComment(sourceFile, i);
|
||||
const commentRange = isInComment(sourceFile, i);
|
||||
if (commentRange) {
|
||||
switch (commentRange.kind) {
|
||||
case SyntaxKind.SingleLineCommentTrivia:
|
||||
textChanges.push.apply(textChanges, toggleLineComment(fileName, { end: commentRange.end, pos: commentRange.pos + 1 }, false));
|
||||
textChanges.push.apply(textChanges, toggleLineComment(fileName, { end: commentRange.end, pos: commentRange.pos + 1 }, /*insertComment*/ false));
|
||||
break;
|
||||
case SyntaxKind.MultiLineCommentTrivia:
|
||||
textChanges.push.apply(textChanges, toggleMultilineComment(fileName, { end: commentRange.end, pos: commentRange.pos + 1 }, false));
|
||||
textChanges.push.apply(textChanges, toggleMultilineComment(fileName, { end: commentRange.end, pos: commentRange.pos + 1 }, /*insertComment*/ false));
|
||||
}
|
||||
|
||||
i = commentRange.end + 1;
|
||||
|
||||
@ -278,10 +278,10 @@ namespace ts {
|
||||
getEmitOutput(fileName: string): string;
|
||||
getEmitOutputObject(fileName: string): EmitOutput;
|
||||
|
||||
toggleLineComment(fileName: string, textChange: ts.TextRange): string;
|
||||
toggleMultilineComment(fileName: string, textChange: ts.TextRange): string;
|
||||
commentSelection(fileName: string, textChange: ts.TextRange): string;
|
||||
uncommentSelection(fileName: string, textChange: ts.TextRange): string;
|
||||
toggleLineComment(fileName: string, textChange: TextRange): string;
|
||||
toggleMultilineComment(fileName: string, textChange:TextRange): string;
|
||||
commentSelection(fileName: string, textChange: TextRange): string;
|
||||
uncommentSelection(fileName: string, textChange: TextRange): string;
|
||||
}
|
||||
|
||||
export interface ClassifierShim extends Shim {
|
||||
@ -1072,28 +1072,28 @@ namespace ts {
|
||||
this.logPerformance) as EmitOutput;
|
||||
}
|
||||
|
||||
public toggleLineComment(fileName: string, textRange: ts.TextRange): string {
|
||||
public toggleLineComment(fileName: string, textRange: TextRange): string {
|
||||
return this.forwardJSONCall(
|
||||
`toggleLineComment('${fileName}', '${JSON.stringify(textRange)}')`,
|
||||
() => this.languageService.toggleLineComment(fileName, textRange)
|
||||
);
|
||||
}
|
||||
|
||||
public toggleMultilineComment(fileName: string, textRange: ts.TextRange): string {
|
||||
public toggleMultilineComment(fileName: string, textRange: TextRange): string {
|
||||
return this.forwardJSONCall(
|
||||
`toggleMultilineComment('${fileName}', '${JSON.stringify(textRange)}')`,
|
||||
() => this.languageService.toggleMultilineComment(fileName, textRange)
|
||||
);
|
||||
}
|
||||
|
||||
public commentSelection(fileName: string, textRange: ts.TextRange): string {
|
||||
public commentSelection(fileName: string, textRange: TextRange): string {
|
||||
return this.forwardJSONCall(
|
||||
`commentSelection('${fileName}', '${JSON.stringify(textRange)}')`,
|
||||
() => this.languageService.commentSelection(fileName, textRange)
|
||||
);
|
||||
}
|
||||
|
||||
public uncommentSelection(fileName: string, textRange: ts.TextRange): string {
|
||||
public uncommentSelection(fileName: string, textRange: TextRange): string {
|
||||
return this.forwardJSONCall(
|
||||
`uncommentSelection('${fileName}', '${JSON.stringify(textRange)}')`,
|
||||
() => this.languageService.uncommentSelection(fileName, textRange)
|
||||
|
||||
@ -1332,9 +1332,11 @@ namespace ts {
|
||||
|| node.kind === SyntaxKind.OpenBraceToken
|
||||
|| node.kind === SyntaxKind.SlashToken) {
|
||||
node = node.parent;
|
||||
} else if (node.kind === SyntaxKind.JsxElement) {
|
||||
}
|
||||
else if (node.kind === SyntaxKind.JsxElement) {
|
||||
return position > node.getStart(sourceFile) || isInsideJsxElementRecursion(node.parent);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user