Skip to content

Commit 18c0e2e

Browse files
committed
Two edge cases covered
1 parent b76392b commit 18c0e2e

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

server/src/comment.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,34 @@ export namespace Comment {
99
for (let i = 0; i < line.length; i++) {
1010
if (state === State.No && line[i] === '/' && line[i + 1] === '*') {
1111
state = State.Multi
12-
} else if (state === State.No && line[i] === '/' && line[i + 1] === '/') {
12+
line = empty(i, line, true)
13+
i++
14+
} else if (state === State.No && line[i] === '/' && line[i + 1] === '/' && line[i - 1] !== '*') {
15+
// TODO early out here
1316
state = State.Single
14-
} else if (state === State.Multi && line[i] === '*' && line[i + 1] === '/' && line[i - 1] !== '/') {
17+
line = empty(i, line, true)
18+
i++
19+
} else if (state === State.Multi && line[i] === '*' && line[i + 1] === '/') {
1520
state = State.No
1621
// inefficient, try to aggregate it
17-
line = empty(i, line)
22+
line = empty(i, line, true)
1823
i++
19-
line = empty(i, line)
2024
}
21-
// inefficient, try to aggregate it
22-
if (state === State.Single || state === State.Multi) {
23-
line = empty(i, line)
24-
i++
25-
line = empty(i, line)
25+
26+
if (state === State.Multi || state === State.Single) {
27+
line = empty(i, line, false)
2628
}
2729
}
2830
if (state === State.Single) state = State.No
2931
return [state, line]
3032
}
3133

32-
function empty(i: number, line: string): string {
33-
return line.substr(0, i) + ' ' + line.substr(i + 1)
34+
function empty(i: number, line: string, twice: boolean): string {
35+
line = line.substr(0, i) + ' ' + line.substr(i + 1)
36+
if (twice) {
37+
i++
38+
line = line.substr(0, i) + ' ' + line.substr(i + 1)
39+
}
40+
return line
3441
}
3542
}

server/src/linter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ function calcRange(lineNum: number, uri: string): Range {
264264
const lines = getDocumentContents(uri).split('\n')
265265
const line = lines[lineNum]
266266
const startOfLine = line.length - line.trimLeft().length
267-
const endOfLine = line.slice(0, line.indexOf('//')).trimRight().length + 1
267+
const endOfLine = line.trimRight().length + 1
268+
//const endOfLine = line.slice(0, line.indexOf('//')).trimRight().length + 2
268269
return Range.create(lineNum, startOfLine, lineNum, endOfLine)
269270
}
270271

0 commit comments

Comments
 (0)