Documentation
¶
Index ¶
- func ChunkHead(text string, textPos Position, pos Position) string
- func GetDistance(text string, start Position, pos Position) int
- func PositionOffset(text string, pos Position) int
- func RelativePostionWithLines(lines []int, textPos Position, pos Position) int
- func SetLocationMarshalJSONInline(inline bool)
- type ClientOptions
- type DidOpenTextDocumentParams
- type DocumentRange
- type DocumentSymbol
- type DocumentURI
- type LSPClient
- 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) Line(uri DocumentURI, pos int) string
- func (cli *LSPClient) LineCounts(uri DocumentURI) []int
- func (cli *LSPClient) Locate(id Location) (string, 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 (h LSPClient) WaitFirstNotify(method string) *jsonrpc2.Request
- func (cli *LSPClient) WorkspaceSymbols(ctx context.Context, query string) ([]DocumentSymbol, error)
- type LanguageSpec
- type Location
- type ModulePatcher
- type Position
- type Range
- type SemanticTokens
- type SymbolKind
- type TextDocumentItem
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PositionOffset ¶
func RelativePostionWithLines ¶
calculate the relative index of a position to a text
func SetLocationMarshalJSONInline ¶
func SetLocationMarshalJSONInline(inline bool)
Types ¶
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"` }
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 LSPClient ¶
type LSPClient struct { *jsonrpc2.Conn ClientOptions // contains filtered or unexported fields }
func NewLSPClient ¶
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) 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) References ¶
func (*LSPClient) SemanticTokens ¶
func (*LSPClient) TypeDefinition ¶
func (LSPClient) WaitFirstNotify ¶
func (*LSPClient) WorkspaceSymbols ¶
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) (string, string, error) // tells if a file belang to language AST ShouldSkip(path string) bool // 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) }
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 ModulePatcher ¶
type ModulePatcher interface { // Patch is called after collect all symbol Patch(ast *uniast.Module) }
ModulePatcher supplements some information for module
type SemanticTokens ¶
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 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:"-"` }
Click to show internal directories.
Click to hide internal directories.