Skip to content

Commit

Permalink
Fixed lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
armanio123 committed May 22, 2020
1 parent ee37d8e commit 35a3d85
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/harness/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,4 +832,4 @@ namespace ts.server {
throw new Error("dispose is not available through the server layer.");
}
}
}
}
16 changes: 8 additions & 8 deletions src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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));
}

Expand All @@ -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));
}

Expand All @@ -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));
}

Expand Down
16 changes: 8 additions & 8 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
},
});

Expand Down
35 changes: 20 additions & 15 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand All @@ -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.
Expand All @@ -2021,15 +2021,17 @@ 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: {
length: 0,
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: {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
});
}
Expand All @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions src/services/shims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 35a3d85

Please sign in to comment.