summaryrefslogtreecommitdiff
path: root/internal/lsp/handlers_ignore.go
blob: 716ea49468d4c62799b5b8fff4225e41a899eff2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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
}