glob

package
v0.8.0-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package glob implements an LSP-compliant glob pattern matcher for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Glob

type Glob struct {
	// contains filtered or unexported fields
}

A Glob is an LSP-compliant glob pattern, as defined by the spec: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#documentFilter

NOTE: this implementation is currently only intended for testing. In order to make it production ready, we'd need to:

  • verify it against the VS Code implementation
  • add more tests
  • microbenchmark, likely avoiding the element interface
  • resolve the question of what is meant by "character". If it's a UTF-16 code (as we suspect) it'll be a bit more work.

Quoting from the spec: Glob patterns can have the following syntax:

  • `*` to match one or more characters in a path segment
  • `?` to match on one character in a path segment
  • `**` to match any number of path segments, including none
  • `{}` to group sub patterns into an OR expression. (e.g. `**/*.{ts,js}` matches all TypeScript and JavaScript files)
  • `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …)
  • `[!...]` to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`)

Expanding on this:

  • '/' matches one or more literal slashes.
  • any other character matches itself literally.

func Parse

func Parse(pattern string) (*Glob, error)

Parse builds a Glob for the given pattern, returning an error if the pattern is invalid.

func (*Glob) Match

func (g *Glob) Match(input string) bool

Match reports whether the input string matches the glob pattern.

func (*Glob) String

func (g *Glob) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL