summaryrefslogtreecommitdiff
path: root/internal/lsp/document.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-17 00:06:00 +0300
committerPaul Buetow <paul@buetow.org>2025-08-17 00:06:00 +0300
commitdc383b4faef881f3bb22816f42c53a79236a4152 (patch)
tree7c6a48487fc1d51fed72ea5d15618d133132cdaa /internal/lsp/document.go
parent6a1d48036105e92193aef11a15a77a569eeb1562 (diff)
lsp/config: make completion trigger characters configurable
- Add trigger_characters to JSON config and ServerOptions - Store on server and advertise in initialize - Update README and example config - Preserve previous defaults when unset
Diffstat (limited to 'internal/lsp/document.go')
-rw-r--r--internal/lsp/document.go86
1 files changed, 43 insertions, 43 deletions
diff --git a/internal/lsp/document.go b/internal/lsp/document.go
index e5eaf06..05f024f 100644
--- a/internal/lsp/document.go
+++ b/internal/lsp/document.go
@@ -1,8 +1,8 @@
package lsp
import (
- "strings"
- "time"
+ "strings"
+ "time"
)
// --- Document store and helpers ---
@@ -76,47 +76,47 @@ func (s *Server) lineContext(uri string, pos Position) (above, current, below, f
// Heuristic: find nearest preceding line containing "func "; ensure no '{'
// appears before the cursor across those lines.
func (s *Server) isDefiningNewFunction(uri string, pos Position) bool {
- d := s.getDocument(uri)
- if d == nil || len(d.lines) == 0 {
- return false
- }
- idx := pos.Line
- if idx < 0 {
- idx = 0
- }
- if idx >= len(d.lines) {
- idx = len(d.lines) - 1
- }
- // Find signature start
- sigStart := -1
- for i := idx; i >= 0; i-- {
- if strings.Contains(d.lines[i], "func ") {
- sigStart = i
- break
- }
- // stop if we hit a closing brace which likely ends a previous block
- if strings.Contains(d.lines[i], "}") {
- break
- }
- }
- if sigStart == -1 {
- return false
- }
- // Scan for '{' from sigStart up to cursor position; if found before or at cursor, we're in body
- for i := sigStart; i <= idx; i++ {
- line := d.lines[i]
- brace := strings.Index(line, "{")
- if brace >= 0 {
- if i < idx {
- return false // body started on a previous line
- }
- // same line as cursor: if brace position < cursor character, then already in body
- if pos.Character > brace {
- return false
- }
- }
- }
- return true
+ d := s.getDocument(uri)
+ if d == nil || len(d.lines) == 0 {
+ return false
+ }
+ idx := pos.Line
+ if idx < 0 {
+ idx = 0
+ }
+ if idx >= len(d.lines) {
+ idx = len(d.lines) - 1
+ }
+ // Find signature start
+ sigStart := -1
+ for i := idx; i >= 0; i-- {
+ if strings.Contains(d.lines[i], "func ") {
+ sigStart = i
+ break
+ }
+ // stop if we hit a closing brace which likely ends a previous block
+ if strings.Contains(d.lines[i], "}") {
+ break
+ }
+ }
+ if sigStart == -1 {
+ return false
+ }
+ // Scan for '{' from sigStart up to cursor position; if found before or at cursor, we're in body
+ for i := sigStart; i <= idx; i++ {
+ line := d.lines[i]
+ brace := strings.Index(line, "{")
+ if brace >= 0 {
+ if i < idx {
+ return false // body started on a previous line
+ }
+ // same line as cursor: if brace position < cursor character, then already in body
+ if pos.Character > brace {
+ return false
+ }
+ }
+ }
+ return true
}
func hasAny(s string, needles []string) bool {