MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / GetWordAtPosition

Method GetWordAtPosition

pkg/lsp/documents.go:355–386  ·  view source on GitHub ↗

GetWordAtPosition returns the word at the given position. This method extracts the identifier or keyword at a specific cursor position, which is used for hover documentation and completion filtering. The method uses rune-based indexing to properly handle UTF-8 encoded SQL identifiers that may cont

(pos Position)

Source from the content-addressed store, hash-verified

353// This method is safe for concurrent use as it operates on document fields
354// without modifying state.
355func (doc *Document) GetWordAtPosition(pos Position) string {
356 if pos.Line >= len(doc.Lines) {
357 return ""
358 }
359
360 line := doc.Lines[pos.Line]
361 runes := []rune(line)
362
363 if pos.Character >= len(runes) {
364 return ""
365 }
366
367 // Find word boundaries using rune indexing for UTF-8 safety
368 start := pos.Character
369 end := pos.Character
370
371 // Move start backwards to find word start
372 for start > 0 && isWordChar(runes[start-1]) {
373 start--
374 }
375
376 // Move end forwards to find word end
377 for end < len(runes) && isWordChar(runes[end]) {
378 end++
379 }
380
381 if start == end {
382 return ""
383 }
384
385 return string(runes[start:end])
386}
387
388// isWordChar returns true if c is a valid word character
389func isWordChar(c rune) bool {

Callers 4

handleHoverMethod · 0.80
handleCompletionMethod · 0.80

Calls 1

isWordCharFunction · 0.70

Tested by 2