summaryrefslogtreecommitdiff
path: root/internal/lsp/handlers_ignore.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-08 10:39:51 +0200
committerPaul Buetow <paul@buetow.org>2026-02-08 10:39:51 +0200
commit023ed82e612451caa38ec46106ed9d148ab9a595 (patch)
treed482cc965a65be22604800fe6772279c52961b99 /internal/lsp/handlers_ignore.go
parent80808d42c257823feb873f80d06b325430c9350e (diff)
add gitignore-aware file filtering for LSP completions and code actions
Files matching .gitignore patterns or user-configured extra patterns are now skipped for completions and code actions. Configurable via [ignore] section in config.toml with gitignore, extra_patterns, and lsp_notify_ignored options. Includes hot-reload support and env var overrides (HEXAI_IGNORE_*). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/lsp/handlers_ignore.go')
-rw-r--r--internal/lsp/handlers_ignore.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/lsp/handlers_ignore.go b/internal/lsp/handlers_ignore.go
new file mode 100644
index 0000000..bbd2dfa
--- /dev/null
+++ b/internal/lsp/handlers_ignore.go
@@ -0,0 +1,41 @@
+// Summary: Helpers for gitignore-aware file filtering in LSP handlers.
+package lsp
+
+import (
+ "net/url"
+ "strings"
+)
+
+// isFileIgnored checks whether the file at the given LSP URI should be ignored.
+// Returns false when no ignore checker is configured.
+func (s *Server) isFileIgnored(uri string) (bool, string) {
+ if s.ignoreChecker == nil {
+ return false, ""
+ }
+ absPath := uriToPath(uri)
+ if absPath == "" {
+ return false, ""
+ }
+ return s.ignoreChecker.IsIgnored(absPath)
+}
+
+// ignoreLSPNotifyEnabled returns whether to show "file ignored" completion items
+// when a file is ignored. Reads from the IgnoreLSPNotify config field.
+func (s *Server) ignoreLSPNotifyEnabled() bool {
+ s.mu.RLock()
+ defer s.mu.RUnlock()
+ return s.cfg.IgnoreLSPNotify == nil || *s.cfg.IgnoreLSPNotify
+}
+
+// uriToPath converts a file:// URI to an absolute file path.
+// Returns empty string for non-file URIs.
+func uriToPath(uri string) string {
+ if !strings.HasPrefix(uri, "file://") {
+ return ""
+ }
+ parsed, err := url.Parse(uri)
+ if err != nil {
+ return ""
+ }
+ return parsed.Path
+}