Skip to main content
Glama

MCP Language Server

gitignore.go1.47 kB
package watcher import ( "os" "path/filepath" gitignore "github.com/sabhiram/go-gitignore" ) // GitignoreMatcher provides a simple wrapper around the go-gitignore package type GitignoreMatcher struct { gitignore *gitignore.GitIgnore basePath string } // NewGitignoreMatcher creates a new gitignore matcher for a workspace func NewGitignoreMatcher(workspacePath string) (*GitignoreMatcher, error) { gitignorePath := filepath.Join(workspacePath, ".gitignore") // Check if .gitignore exists _, err := os.Stat(gitignorePath) if os.IsNotExist(err) { // No .gitignore file, return a matcher with no patterns emptyIgnore := gitignore.CompileIgnoreLines([]string{}...) return &GitignoreMatcher{ gitignore: emptyIgnore, basePath: workspacePath, }, nil } else if err != nil { return nil, err } // Parse .gitignore file using the go-gitignore library ignore, err := gitignore.CompileIgnoreFile(gitignorePath) if err != nil { return nil, err } return &GitignoreMatcher{ gitignore: ignore, basePath: workspacePath, }, nil } // ShouldIgnore checks if a file or directory should be ignored based on gitignore patterns func (g *GitignoreMatcher) ShouldIgnore(path string, isDir bool) bool { // Make path relative to workspace root relPath, err := filepath.Rel(g.basePath, path) if err != nil { return false } // Use the go-gitignore Match function to check if the path should be ignored return g.gitignore.MatchesPath(relPath) }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/isaacphi/mcp-language-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server