Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dandeandean committed Jan 19, 2025
1 parent cdddbeb commit ca01af9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions internal/adapter/lsp/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,23 @@ var currentCodeBlockStart = -1
// check whether the current line in document is within a fenced or indented
// code block
func isLineWithinCodeBlock(lines []string, lineIndex int, line string) bool {
if len(line) == 0 { // if 0 either it's in a fence or no
if len(line) == 0 {
return insideFenced
}
isEndOfFence := func(line string) bool {
if !insideFenced ||
currentCodeBlockStart < 0 ||
len(line) < 3 ||
len(lines) <= currentCodeBlockStart ||
len(lines[currentCodeBlockStart]) < 3 ||
fencedEndRegex.FindStringIndex(line) == nil {
return false
}
return lines[currentCodeBlockStart][:3] == line[:3]
}
// if line is already within code fences or indented code block
if insideFenced && currentCodeBlockStart > -1 {
if fencedEndRegex.FindStringIndex(line) != nil &&
currentCodeBlockStart < len(lines) &&
3 <= len(lines[currentCodeBlockStart]) &&
3 <= len(line) &&
lines[currentCodeBlockStart][:3] == line[:3] {
if isEndOfFence(line) {
// Fenced code block ends with this line
insideFenced = false
currentCodeBlockStart = -1
Expand Down

0 comments on commit ca01af9

Please sign in to comment.