Documentation
¶
Index ¶
- func ChunkHead(text string, textPos Position, pos Position) string
- func FindPair(text string, lines []int, textPos Position, tokens []Token, lchar rune, ...) (int, int)
- func FindSingle(text string, lines []int, textPos Position, tokens []Token, sep string, ...) int
- func GetDistance(text string, start Position, pos Position) int
- func PositionOffset(file_uri string, text string, pos Position) int
- func RegisterProvider(lang uniast.Language, provider LanguageServiceProvider)
- func RelativePostionWithLines(lines []int, basePos Position, pos Position) int
- func SetLocationMarshalJSONInline(inline bool)
- type ClientOptions
- type DidOpenTextDocumentParams
- type DocumentRange
- type DocumentSymbol
- type DocumentURI
- type Hover
- type LSPClient
- func (cli *LSPClient) Call(ctx context.Context, method string, params, result interface{}, ...) error
- func (c *LSPClient) Close() error
- func (cli *LSPClient) Definition(ctx context.Context, uri DocumentURI, pos Position) ([]Location, error)
- func (cli *LSPClient) DidOpen(ctx context.Context, file DocumentURI) (*TextDocumentItem, error)
- func (cli *LSPClient) DocumentSymbols(ctx context.Context, file DocumentURI) (map[Range]*DocumentSymbol, error)
- func (cli *LSPClient) FileStructure(ctx context.Context, file DocumentURI) ([]*DocumentSymbol, error)
- func (cli *LSPClient) GetFile(uri DocumentURI) *TextDocumentItem
- func (cli *LSPClient) GetParent(sym *DocumentSymbol) (ret *DocumentSymbol)
- func (h LSPClient) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request)
- func (cli *LSPClient) Hover(ctx context.Context, uri DocumentURI, line, character int) (*Hover, error)
- func (cli *LSPClient) Implementation(ctx context.Context, uri DocumentURI, pos Position) ([]Location, error)
- func (c *LSPClient) InitFiles()
- func (cli *LSPClient) Line(uri DocumentURI, pos int) string
- func (cli *LSPClient) LineCounts(uri DocumentURI) []int
- func (cli *LSPClient) Locate(id Location) (string, error)
- func (cli *LSPClient) PrepareTypeHierarchy(ctx context.Context, uri DocumentURI, pos Position) ([]TypeHierarchyItem, error)
- func (cli *LSPClient) References(ctx context.Context, id Location) ([]Location, error)
- func (cli *LSPClient) SemanticTokens(ctx context.Context, id Location) ([]Token, error)
- func (cli *LSPClient) TypeDefinition(ctx context.Context, uri DocumentURI, pos Position) ([]Location, error)
- func (cli *LSPClient) TypeHierarchySubtypes(ctx context.Context, item TypeHierarchyItem) ([]TypeHierarchyItem, error)
- func (cli *LSPClient) TypeHierarchySupertypes(ctx context.Context, item TypeHierarchyItem) ([]TypeHierarchyItem, error)
- func (h LSPClient) WaitFirstNotify(method string) *jsonrpc2.Request
- func (cli *LSPClient) WorkspaceSearchSymbols(ctx context.Context, query string) ([]SymbolInformation, error)
- func (cli *LSPClient) WorkspaceSymbols(ctx context.Context, query string) ([]DocumentSymbol, error)
- type LanguageServiceProvider
- type LanguageSpec
- type Location
- type MarkedString
- type Position
- type Range
- type SemanticTokens
- type SemanticTokensFullParams
- type SymbolInformation
- type SymbolKind
- type SymbolRole
- type TextDocumentIdentifier
- type TextDocumentItem
- type TextDocumentPositionParams
- type Token
- type TypeHierarchyItem
- type WorkspaceSymbolParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindPair ¶
func FindPair(text string, lines []int, textPos Position, tokens []Token, lchar rune, rchar rune, start int, end int, notAllow rune) (int, int)
FindPair finds the right token index of lchar and left token index of rchar in a text start and end is the limit range of tokens notAllow is the character that not allow in the range
func FindSingle ¶
func FindSingle(text string, lines []int, textPos Position, tokens []Token, sep string, start int, end int) int
FindSingle finds the single char's left token index in a text start and end is the limit range of tokens
func RegisterProvider ¶ added in v0.2.0
func RegisterProvider(lang uniast.Language, provider LanguageServiceProvider)
RegisterProvider makes a LanguageServiceProvider available for a given language. This function should be called from the init() function of a language-specific package.
func RelativePostionWithLines ¶
calculate the relative index of a position to a text
func SetLocationMarshalJSONInline ¶
func SetLocationMarshalJSONInline(inline bool)
Types ¶
type ClientOptions ¶
type DidOpenTextDocumentParams ¶
type DidOpenTextDocumentParams struct {
TextDocument TextDocumentItem `json:"textDocument"`
}
type DocumentRange ¶
type DocumentRange struct { TextDocument lsp.TextDocumentIdentifier `json:"textDocument"` Range Range `json:"range"` }
type DocumentSymbol ¶
type DocumentSymbol struct { Name string `json:"name"` Kind SymbolKind `json:"kind"` Tags []json.RawMessage `json:"tags"` Location Location `json:"location"` Children []*DocumentSymbol `json:"children"` Text string `json:"text"` Tokens []Token `json:"tokens"` Node *sitter.Node `json:"-"` Role SymbolRole `json:"-"` }
func (*DocumentSymbol) MarshalJSON ¶
func (s *DocumentSymbol) MarshalJSON() ([]byte, error)
func (*DocumentSymbol) MarshalText ¶
func (s *DocumentSymbol) MarshalText() ([]byte, error)
func (*DocumentSymbol) String ¶
func (s *DocumentSymbol) String() string
type DocumentURI ¶
type DocumentURI lsp.DocumentURI
func NewURI ¶
func NewURI(file string) DocumentURI
func (DocumentURI) File ¶
func (l DocumentURI) File() string
type Hover ¶ added in v0.2.0
type Hover struct { Contents []MarkedString `json:"contents"` Range *Range `json:"range,omitempty"` }
type LSPClient ¶
type LSPClient struct { *jsonrpc2.Conn ClientOptions // contains filtered or unexported fields }
func InitLSPForFirstTest ¶ added in v0.2.0
func NewLSPClient ¶
func (*LSPClient) Call ¶ added in v0.2.0
func (cli *LSPClient) Call(ctx context.Context, method string, params, result interface{}, opts ...jsonrpc2.CallOption) error
Extra wrapper around json rpc to 1. implement a transparent, generic cache
func (*LSPClient) Definition ¶
func (*LSPClient) DidOpen ¶
func (cli *LSPClient) DidOpen(ctx context.Context, file DocumentURI) (*TextDocumentItem, error)
func (*LSPClient) DocumentSymbols ¶
func (cli *LSPClient) DocumentSymbols(ctx context.Context, file DocumentURI) (map[Range]*DocumentSymbol, error)
func (*LSPClient) FileStructure ¶
func (cli *LSPClient) FileStructure(ctx context.Context, file DocumentURI) ([]*DocumentSymbol, error)
func (*LSPClient) GetFile ¶
func (cli *LSPClient) GetFile(uri DocumentURI) *TextDocumentItem
func (*LSPClient) GetParent ¶
func (cli *LSPClient) GetParent(sym *DocumentSymbol) (ret *DocumentSymbol)
func (*LSPClient) Implementation ¶ added in v0.2.0
func (*LSPClient) Line ¶
func (cli *LSPClient) Line(uri DocumentURI, pos int) string
get line text of pos
func (*LSPClient) LineCounts ¶
func (cli *LSPClient) LineCounts(uri DocumentURI) []int
func (*LSPClient) PrepareTypeHierarchy ¶ added in v0.2.0
func (cli *LSPClient) PrepareTypeHierarchy(ctx context.Context, uri DocumentURI, pos Position) ([]TypeHierarchyItem, error)
func (*LSPClient) References ¶
func (*LSPClient) SemanticTokens ¶
func (*LSPClient) TypeDefinition ¶
func (*LSPClient) TypeHierarchySubtypes ¶ added in v0.2.0
func (cli *LSPClient) TypeHierarchySubtypes(ctx context.Context, item TypeHierarchyItem) ([]TypeHierarchyItem, error)
func (*LSPClient) TypeHierarchySupertypes ¶ added in v0.2.0
func (cli *LSPClient) TypeHierarchySupertypes(ctx context.Context, item TypeHierarchyItem) ([]TypeHierarchyItem, error)
func (LSPClient) WaitFirstNotify ¶
func (*LSPClient) WorkspaceSearchSymbols ¶ added in v0.2.0
func (*LSPClient) WorkspaceSymbols ¶
type LanguageServiceProvider ¶ added in v0.2.0
type LanguageServiceProvider interface { // Hover provides hover information for a given position. // Implementations may have custom logic to parse results from different language servers. Hover(ctx context.Context, cli *LSPClient, uri DocumentURI, line, character int) (*Hover, error) // Implementation finds implementations of a symbol. Implementation(ctx context.Context, cli *LSPClient, uri DocumentURI, pos Position) ([]Location, error) // WorkspaceSymbols searches for symbols in the workspace. WorkspaceSearchSymbols(ctx context.Context, cli *LSPClient, query string) ([]SymbolInformation, error) // PrepareTypeHierarchy prepares a type hierarchy for a given position. PrepareTypeHierarchy(ctx context.Context, cli *LSPClient, uri DocumentURI, pos Position) ([]TypeHierarchyItem, error) // TypeHierarchySupertypes gets the supertypes of a type hierarchy item. TypeHierarchySupertypes(ctx context.Context, cli *LSPClient, item TypeHierarchyItem) ([]TypeHierarchyItem, error) // TypeHierarchySubtypes gets the subtypes of a type hierarchy item. TypeHierarchySubtypes(ctx context.Context, cli *LSPClient, item TypeHierarchyItem) ([]TypeHierarchyItem, error) }
LanguageServiceProvider defines methods for language-specific LSP features. It allows for extending the base LSPClient with language-specific capabilities without creating circular dependencies.
func GetProvider ¶ added in v0.2.0
func GetProvider(lang uniast.Language) LanguageServiceProvider
GetProvider returns the registered LanguageServiceProvider for a given language. It returns nil if no provider is registered for the language.
type LanguageSpec ¶
type LanguageSpec interface { // initialize a root workspace, and return all modules [modulename=>abs-path] inside WorkSpace(root string) (map[string]string, error) // give an absolute file path and returns its module name and package path // external path should alse be supported // FIXEM: some language (like rust) may have sub-mods inside a file, but we still consider it as a unity mod here NameSpace(path string, file *uniast.File) (string, string, error) // tells if a file belang to language AST ShouldSkip(path string) bool // FileImports parse file codes to get its imports FileImports(content []byte) ([]uniast.Import, error) // return the first declaration token of a symbol, as Type-Name DeclareTokenOfSymbol(sym DocumentSymbol) int // tells if a token is an AST entity IsEntityToken(tok Token) bool // tells if a token is a std token IsStdToken(tok Token) bool // return the SymbolKind of a token TokenKind(tok Token) SymbolKind // tells if a symbol is a main function IsMainFunction(sym DocumentSymbol) bool // tells if a symbol is a language symbol (func, type, variable, etc) in workspace IsEntitySymbol(sym DocumentSymbol) bool // tells if a symbol is public in workspace IsPublicSymbol(sym DocumentSymbol) bool // declare if the language has impl symbol // if it return true, the ImplSymbol() will be called HasImplSymbol() bool // if a symbol is an impl symbol, return the token index of interface type, receiver type and first-method start (-1 means not found) // ortherwise the collector will use FunctionSymbol() as receiver type token index (-1 means not found) ImplSymbol(sym DocumentSymbol) (int, int, int) // if a symbol is a Function or Method symbol, return the token index of Receiver (-1 means not found),TypeParameters, InputParameters and Outputs FunctionSymbol(sym DocumentSymbol) (int, []int, []int, []int) // Handle a unloaded internal symbol, like `lazy_static!` in rust GetUnloadedSymbol(from Token, define Location) (string, error) // some language may allow local symbols inside another symbol ProtectedSymbolKinds() []SymbolKind }
Detailed implementation used for collect LSP symbols and transform them to UniAST
type Location ¶
type Location struct { URI DocumentURI `json:"uri"` Range Range `json:"range"` }
func (Location) MarshalJSON ¶
func (Location) MarshalText ¶
type MarkedString ¶ added in v0.2.0
type MarkedString markedString
type SemanticTokens ¶
type SemanticTokensFullParams ¶ added in v0.2.0
type SemanticTokensFullParams struct {
TextDocument lsp.TextDocumentIdentifier `json:"textDocument"`
}
type SymbolInformation ¶ added in v0.2.0
type SymbolInformation struct { Name string `json:"name"` Kind SymbolKind `json:"kind"` Location Location `json:"location"` ContainerName string `json:"containerName,omitempty"` }
type SymbolKind ¶
type SymbolKind = lsp.SymbolKind
const ( SKUnknown SymbolKind = 1 SKFile SymbolKind = 1 SKModule SymbolKind = 2 SKNamespace SymbolKind = 3 SKPackage SymbolKind = 4 SKClass SymbolKind = 5 SKMethod SymbolKind = 6 SKProperty SymbolKind = 7 SKField SymbolKind = 8 SKConstructor SymbolKind = 9 SKEnum SymbolKind = 10 SKInterface SymbolKind = 11 SKFunction SymbolKind = 12 SKVariable SymbolKind = 13 SKConstant SymbolKind = 14 SKString SymbolKind = 15 SKNumber SymbolKind = 16 SKBoolean SymbolKind = 17 SKArray SymbolKind = 18 SKObject SymbolKind = 19 SKKey SymbolKind = 20 SKNull SymbolKind = 21 SKEnumMember SymbolKind = 22 SKStruct SymbolKind = 23 SKEvent SymbolKind = 24 SKOperator SymbolKind = 25 SKTypeParameter SymbolKind = 26 )
The SymbolKind values are defined at https://microsoft.github.io/language-server-protocol/specification.
type SymbolRole ¶ added in v0.2.0
type SymbolRole int
const ( DEFINITION SymbolRole = 1 REFERENCE SymbolRole = 2 )
type TextDocumentIdentifier ¶ added in v0.2.0
type TextDocumentIdentifier struct { /** * The text document's URI. */ URI DocumentURI `json:"uri"` }
type TextDocumentItem ¶
type TextDocumentItem struct { URI DocumentURI `json:"uri"` LanguageID string `json:"languageId"` Version int `json:"version"` Text string `json:"text"` LineCounts []int `json:"-"` Symbols map[Range]*DocumentSymbol `json:"-"` Definitions map[Position][]Location `json:"-"` }
type TextDocumentPositionParams ¶ added in v0.2.0
type TextDocumentPositionParams struct { /** * The text document. */ TextDocument TextDocumentIdentifier `json:"textDocument"` /** * The position inside the text document. */ Position Position `json:"position"` }
type Token ¶
type TypeHierarchyItem ¶ added in v0.2.0
type TypeHierarchyItem struct { Name string `json:"name"` Kind SymbolKind `json:"kind"` Detail string `json:"detail,omitempty"` URI DocumentURI `json:"uri"` Range Range `json:"range"` SelectionRange Range `json:"selectionRange"` Data interface{} `json:"data,omitempty"` }
TypeHierarchyItem represents a node in the type hierarchy tree.
@since 3.17.0