mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-19 17:26:13 +00:00
Two edge cases covered
This commit is contained in:
parent
b76392b4e8
commit
18c0e2ef5c
2 changed files with 20 additions and 12 deletions
|
@ -9,27 +9,34 @@ export namespace Comment {
|
|||
for (let i = 0; i < line.length; i++) {
|
||||
if (state === State.No && line[i] === '/' && line[i + 1] === '*') {
|
||||
state = State.Multi
|
||||
} else if (state === State.No && line[i] === '/' && line[i + 1] === '/') {
|
||||
line = empty(i, line, true)
|
||||
i++
|
||||
} else if (state === State.No && line[i] === '/' && line[i + 1] === '/' && line[i - 1] !== '*') {
|
||||
// TODO early out here
|
||||
state = State.Single
|
||||
} else if (state === State.Multi && line[i] === '*' && line[i + 1] === '/' && line[i - 1] !== '/') {
|
||||
line = empty(i, line, true)
|
||||
i++
|
||||
} else if (state === State.Multi && line[i] === '*' && line[i + 1] === '/') {
|
||||
state = State.No
|
||||
// inefficient, try to aggregate it
|
||||
line = empty(i, line)
|
||||
line = empty(i, line, true)
|
||||
i++
|
||||
line = empty(i, line)
|
||||
}
|
||||
// inefficient, try to aggregate it
|
||||
if (state === State.Single || state === State.Multi) {
|
||||
line = empty(i, line)
|
||||
i++
|
||||
line = empty(i, line)
|
||||
|
||||
if (state === State.Multi || state === State.Single) {
|
||||
line = empty(i, line, false)
|
||||
}
|
||||
}
|
||||
if (state === State.Single) state = State.No
|
||||
return [state, line]
|
||||
}
|
||||
|
||||
function empty(i: number, line: string): string {
|
||||
return line.substr(0, i) + ' ' + line.substr(i + 1)
|
||||
function empty(i: number, line: string, twice: boolean): string {
|
||||
line = line.substr(0, i) + ' ' + line.substr(i + 1)
|
||||
if (twice) {
|
||||
i++
|
||||
line = line.substr(0, i) + ' ' + line.substr(i + 1)
|
||||
}
|
||||
return line
|
||||
}
|
||||
}
|
|
@ -264,7 +264,8 @@ function calcRange(lineNum: number, uri: string): Range {
|
|||
const lines = getDocumentContents(uri).split('\n')
|
||||
const line = lines[lineNum]
|
||||
const startOfLine = line.length - line.trimLeft().length
|
||||
const endOfLine = line.slice(0, line.indexOf('//')).trimRight().length + 1
|
||||
const endOfLine = line.trimRight().length + 1
|
||||
//const endOfLine = line.slice(0, line.indexOf('//')).trimRight().length + 2
|
||||
return Range.create(lineNum, startOfLine, lineNum, endOfLine)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue