Skip to content

Commit f8c4b60

Browse files
Kapil Borledaviwil
Kapil Borle
authored andcommitted
Get end of line character from the document
1 parent 2fdbd66 commit f8c4b60

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/features/HelpCompletion.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
* Copyright (C) Microsoft Corporation. All rights reserved.
33
*--------------------------------------------------------*/
44

5-
import vscode = require("vscode");
65
import { IFeature } from "../feature";
7-
import { TextDocumentChangeEvent, workspace, Disposable, Position } from "vscode";
6+
import { TextDocumentChangeEvent, workspace, Disposable, Position, window, Range, EndOfLine } from "vscode";
87
import { LanguageClient, RequestType } from "vscode-languageclient";
98

109
export namespace CommentHelpRequest {
@@ -53,6 +52,7 @@ export class HelpCompletionFeature implements IFeature {
5352
}
5453

5554
onEvent(changeEvent: TextDocumentChangeEvent): void {
55+
// todo split this method into logical components
5656
let text = changeEvent.contentChanges[0].text;
5757
switch (this.searchState) {
5858
case SearchState.Searching:
@@ -103,16 +103,24 @@ export class HelpCompletionFeature implements IFeature {
103103
return;
104104
}
105105

106-
// todo get the eol character programmatically or let the server return one whole string
107106
// todo add indentation level to the help content
108-
let editor = vscode.window.activeTextEditor;
109-
let replaceRange = new vscode.Range(triggerStartPos.translate(0, -1), triggerStartPos.translate(0, 1));
107+
let editor = window.activeTextEditor;
108+
let replaceRange = new Range(triggerStartPos.translate(0, -1), triggerStartPos.translate(0, 1));
110109

111110
// Trim the last empty line and join the strings.
112-
let text = content.slice(0, -1).join("\r\n");
111+
let text = content.slice(0, -1).join(this.getEOL(doc.eol));
113112
editor.edit(editBuilder => editBuilder.replace(replaceRange, text));
114113
});
115114
}
116115
}
117116
}
117+
118+
private getEOL(eol: EndOfLine): string {
119+
// there are only two type of EndOfLine types.
120+
if (eol === EndOfLine.CRLF) {
121+
return "\r\n";
122+
}
123+
124+
return "\n";
125+
}
118126
}

0 commit comments

Comments
 (0)