summaryrefslogtreecommitdiffhomepage
path: root/internal/lsp/protocol/pattern_interfaces.go
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-03 15:20:15 +0200
committerKujtim Hoxha <[email protected]>2025-04-03 17:23:41 +0200
commitcfdd687216799cb5b47f099f1e7cd5dd16b3bdd0 (patch)
treea822bfde1463a7080c0ea06dd17796d7a1617d3d /internal/lsp/protocol/pattern_interfaces.go
parentafd9ad0560d76c2a6d161dad52553b10ff428905 (diff)
downloadopencode-cfdd687216799cb5b47f099f1e7cd5dd16b3bdd0.tar.gz
opencode-cfdd687216799cb5b47f099f1e7cd5dd16b3bdd0.zip
add initial lsp support
Diffstat (limited to 'internal/lsp/protocol/pattern_interfaces.go')
-rw-r--r--internal/lsp/protocol/pattern_interfaces.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/lsp/protocol/pattern_interfaces.go b/internal/lsp/protocol/pattern_interfaces.go
new file mode 100644
index 000000000..ebc7053dc
--- /dev/null
+++ b/internal/lsp/protocol/pattern_interfaces.go
@@ -0,0 +1,58 @@
+package protocol
+
+import (
+ "fmt"
+ "strings"
+)
+
+// PatternInfo is an interface for types that represent glob patterns
+type PatternInfo interface {
+ GetPattern() string
+ GetBasePath() string
+ isPattern() // marker method
+}
+
+// StringPattern implements PatternInfo for string patterns
+type StringPattern struct {
+ Pattern string
+}
+
+func (p StringPattern) GetPattern() string { return p.Pattern }
+func (p StringPattern) GetBasePath() string { return "" }
+func (p StringPattern) isPattern() {}
+
+// RelativePatternInfo implements PatternInfo for RelativePattern
+type RelativePatternInfo struct {
+ RP RelativePattern
+ BasePath string
+}
+
+func (p RelativePatternInfo) GetPattern() string { return string(p.RP.Pattern) }
+func (p RelativePatternInfo) GetBasePath() string { return p.BasePath }
+func (p RelativePatternInfo) isPattern() {}
+
+// AsPattern converts GlobPattern to a PatternInfo object
+func (g *GlobPattern) AsPattern() (PatternInfo, error) {
+ if g.Value == nil {
+ return nil, fmt.Errorf("nil pattern")
+ }
+
+ switch v := g.Value.(type) {
+ case string:
+ return StringPattern{Pattern: v}, nil
+ case RelativePattern:
+ // Handle BaseURI which could be string or DocumentUri
+ basePath := ""
+ switch baseURI := v.BaseURI.Value.(type) {
+ case string:
+ basePath = strings.TrimPrefix(baseURI, "file://")
+ case DocumentUri:
+ basePath = strings.TrimPrefix(string(baseURI), "file://")
+ default:
+ return nil, fmt.Errorf("unknown BaseURI type: %T", v.BaseURI.Value)
+ }
+ return RelativePatternInfo{RP: v, BasePath: basePath}, nil
+ default:
+ return nil, fmt.Errorf("unknown pattern type: %T", g.Value)
+ }
+}