sun::lsp
namespace · Source (opens in a new tab)
Provides compiler-backed editor features through the language server protocol.
Shared document state and interfaces between server implementation files.
Initializes the language server and dispatches framed editor messages.
Language server protocol implementation.
Language server documents implementation.
Implements the Sun language server.
Classes
- sun::lsp::NodeFinder (public)
- sun::lsp::DiagnosticsCache (public)
- sun::lsp::EntrypointManager (public)
Structs
- sun::lsp::Target (public)
- sun::lsp::Declaration (public)
- sun::lsp::Hover (public)
- sun::lsp::DeclarationKey (public)
- sun::lsp::MemberGroup (public)
- sun::lsp::Occurrences (public)
- sun::lsp::Rename (public)
- sun::lsp::SymbolLocation (public)
- sun::lsp::TestItem (public)
- sun::lsp::TestSpan (public)
- sun::lsp::LspPosition (public)
- sun::lsp::OpenDocument (public)
- sun::lsp::AnalyzedDocument (public)
- sun::lsp::EntrypointConfig (public)
- sun::lsp::TestFreshness (public)
- sun::lsp::TestBuildCandidate (public)
- sun::lsp::TestBuildInspection (public)
Functions
- analyzeDiagnostics
- annotationIn
- appendDiagnostic
- applyPathVariables
- byteOffsetFromLspPosition
- checkNewName
- checkTestFreshness
- clearAnalysisCaches
- collectTestConfigPaths
- collectTestSpans
- collectTests
- computeDefinition
- computeHover
- computeReferences
- computeRename
- computeSemanticTokens
- declarationKey
- declarationName
- declarationOf
- declarationQualifiedName
- declarationUnder
- declaresParameter
- findAnnotatedType
- findDeclaration
- findDeclarationAt
- findDeclarationOf
- findInnermostNodeAt
- findLocalDeclaration
- findMember
- findMemberDeclaration
- findOccurrences
- findParameter
- findTypeDefinition
- findWord
- firstSpecialization
- forEachAnnotation
- getAnalyzedDocument
- handleDocuments
- handleFormatting
- handleNavigation
- handleTestRequests
- inspectTestBuild
- isDefinition
- lineStart
- locate
- lspPositionFromByteOffset
- makePosition
- makeRange
- makeSymbolLocation
- memberGroupOf
- nameRange
- nameRangeOf
- normalizePath
- ownDeclaration
- parameterRange
- pathToUri
- percentDecode
- prototypeOf
- publishDiagnostics
- rangeAt
- readEntrypoints
- readMessageBody
- readSunConfigs
- refreshEntrypoints
- resolveSymbol
- runServer
- sendErrorResponse
- sendResponse
- siteAt
- sliceSpan
- sourceFor
- spanContains
- startsGenericCall
- startsWith
- stripReference
- testBinaryIdentity
- testSuites
- textHas
- textOf
- toJsonPayload
- tokenKindToLSPType
- trimCR
- uriToPath
- utf16Units
- utf8Length
- writeLSPMessage
analyzeDiagnostics
public · function · Source (opens in a new tab)
llvm::json::Array sun::lsp::analyzeDiagnostics(const OpenDocument &document)Analyzes the current document text and collects compiler diagnostics.
Analyzes a document in its manifest context and returns diagnostics.
Related: OpenDocument
annotationIn
public · function · Source (opens in a new tab)
const sun::ast::TypeAnnotation * sun::lsp::annotationIn(const ExprAST &node, int offset)The annotation under the cursor among those written on a node, or null.
Finds the type annotation covering the requested byte offset.
Related: sun::ast::TypeAnnotation, ExprAST
appendDiagnostic
public · function · static · Source (opens in a new tab)
static void sun::lsp::appendDiagnostic(llvm::json::Array &diagnostics, const OpenDocument &document, const std::string &message, const std::optional< sun::support::Position > &location, int severity, const std::string &knownSourceLine="")Add one diagnostic for a message and the place it points at.
A location in this document is marked where it happened; one in another file (a manifest sibling, or a library body instantiated from a bundle) is shown at the top of this document, naming where it came from.
Related: OpenDocument, sun::support::Position
applyPathVariables
public · function · Source (opens in a new tab)
bool sun::lsp::applyPathVariables(const llvm::json::Object &config)Install manifest path variables ($NAME) from a configuration object's "pathVariables" member ({NAME: dir, ...}).
Applies editor-configured compiler path variables.
Replaces the previous set so removed variables disappear. Returns true if the member was present.
byteOffsetFromLspPosition
public · function · Source (opens in a new tab)
int sun::lsp::byteOffsetFromLspPosition(const std::string &text, int line, int character)Byte offset for a protocol position.
A column past the end of the line stops at the line break; a line past the end of the text stops at the end. A column inside a surrogate pair snaps to the start of that character.
checkNewName
public · function · Source (opens in a new tab)
std::string sun::lsp::checkNewName(const std::string &newName)Why newName cannot be a symbol name, or empty when it can: it must lex as a single identifier, so keywords and punctuation are refused.
Validates a proposed identifier before applying a rename.
checkTestFreshness
public · function · static · Source (opens in a new tab)
static TestFreshness sun::lsp::checkTestFreshness(const std::string &binary, const std::set< std::string > &inputs, std::string problem)Checks the same resolved inputs for test and production artifacts.
Related: TestFreshness
clearAnalysisCaches
public · function · Source (opens in a new tab)
void sun::lsp::clearAnalysisCaches()Invalidates results whose source text or configuration changed.
Clears diagnostics and analyzed trees after document or context changes.
collectTestConfigPaths
public · function · static · Source (opens in a new tab)
static void sun::lsp::collectTestConfigPaths(const std::string &file, std::set< std::string > &files, std::set< std::string > &patterns)Retains missing included configs and glob patterns so their creation can refresh discovery.
collectTestSpans
public · function · Source (opens in a new tab)
std::vector< TestSpan > sun::lsp::collectTestSpans(const sun::ast::BlockExprAST &ast)Every test_function in the program, whichever file declares it.
Collects the source ranges occupied by test declarations.
Related: TestSpan, sun::ast::BlockExprAST
collectTests
public · function · Source (opens in a new tab)
std::vector< TestItem > sun::lsp::collectTests(const sun::ast::BlockExprAST &ast, const std::string &documentPath, const std::string &source)Every test_function declared in the document at documentPath, walking module bodies the way the test runner does so ids match the runner's dotted names.
Collects runnable test declarations and their editor locations.
source is the document's text, used to narrow each declaration span to the name token.
Related: TestItem, sun::ast::BlockExprAST
computeDefinition
public · function · Source (opens in a new tab)
std::optional< SymbolLocation > sun::lsp::computeDefinition(const sun::ast::BlockExprAST &program, const std::string &filePath, const std::string &source, int byteOffset)Where the symbol at byteOffset was declared: a local, a parameter, a loop variable, a match or catch binding, a module-level function, class, interface, enum, variable or alias, a member behind obj.member, the class behind this, or the type a written annotation names.
Returns the definition location for the symbol at a document offset.
On a declaration's own header the declaration itself is returned. The range covers the declared name. Declarations from a .moon bundle resolve to the library's source file when the bundle recorded it and the file can be read. Returns nothing for literals, operators, statements and whitespace.
Related: SymbolLocation, sun::ast::BlockExprAST
computeHover
public · function · Source (opens in a new tab)
std::optional< Hover > sun::lsp::computeHover(const sun::ast::BlockExprAST &program, const std::string &filePath, const std::string &source, int byteOffset)Hover text for the construct at byteOffset in an analyzed program: name: T for variables and members, full signatures for functions, class Name for definitions, module Name for module name tokens, and the type alone for literals and operators.
Returns documentation and type details for the symbol under the cursor.
Inside a generic class or function body, types come from the first specialization and are printed in terms of the type parameters. source is the document text; declarations whose types were never resolved (analysis stopped at an earlier error, or a generic that is never used) fall back to the type annotation written there. The comment directly above the symbol's declaration is returned as documentation. Returns nothing for statements and untyped nodes.
Related: Hover, sun::ast::BlockExprAST
computeReferences
public · function · Source (opens in a new tab)
std::vector< SymbolLocation > sun::lsp::computeReferences(const BlockExprAST &program, const std::string &filePath, const std::string &source, int byteOffset, bool includeDeclaration)Every place the symbol at byteOffset is named, across all files of the analyzed program, sorted by file then offset: uses of a local, parameter, loop variable, match or catch binding, function, class, interface, enum, variant, field or method, including type names written in annotations and implements lists.
Returns references to the symbol selected at a document offset.
With includeDeclaration the declared name is listed too; a declaration from a .moon bundle resolves to the library's source file when the bundle recorded it. Uses inside library code are not listed, since bundles carry no function bodies. An interface member and the class members implementing it are listed together, as one group. Empty for literals, operators, statements and whitespace.
Related: SymbolLocation, BlockExprAST
computeRename
public · function · Source (opens in a new tab)
std::optional< Rename > sun::lsp::computeRename(const sun::ast::BlockExprAST &program, const std::string &filePath, const std::string &source, int byteOffset)The symbol at byteOffset with every place its name is written, found as computeReferences finds them.
Collects the declaration and use sites needed to rename a symbol.
An interface member and the class members implementing it are renamed together, since renaming one side alone would break the program. A symbol declared in a library (loaded from a .moon bundle) is refused, since its uses inside the library cannot be edited. Nothing when the cursor is not on a symbol.
Related: Rename, sun::ast::BlockExprAST
computeSemanticTokens
public · function · Source (opens in a new tab)
std::vector< int > sun::lsp::computeSemanticTokens(const std::string &source)Compute semantic tokens for a document Returns encoded token data as per LSP spec: [deltaLine, deltaStartChar, length, tokenType, tokenModifiers]...
Computes semantic tokens for document text.
declarationKey
public · function · Source (opens in a new tab)
DeclarationKey sun::lsp::declarationKey(const Declaration &declaration, const std::string &file)A location without a file belongs to file.
Builds the key used to group references to the same declaration.
Related: DeclarationKey, Declaration
declarationName
public · function · Source (opens in a new tab)
std::string sun::lsp::declarationName(const ExprAST &node)Name a module-level declaration is known by, or empty for other nodes.
Returns the unqualified name introduced by a declaration node.
Related: ExprAST
declarationOf
public · function · Source (opens in a new tab)
Declaration sun::lsp::declarationOf(const ExprAST &node)Extracts declaration information from a syntax node.
Related: Declaration, ExprAST
declarationQualifiedName
public · function · Source (opens in a new tab)
QualifiedName sun::lsp::declarationQualifiedName(const ExprAST &node)Qualified name the analyzer gave a declaration, or empty.
Returns the declaration name together with its enclosing scopes.
Related: QualifiedName, ExprAST
declarationUnder
public · function · Source (opens in a new tab)
std::optional< Declaration > sun::lsp::declarationUnder(const BlockExprAST &program, const Target &target, int offset, const std::string &source)The declaration behind the node under the cursor.
Resolves the declaration under a selected source position.
Related: Declaration, BlockExprAST, Target
declaresParameter
public · function · Source (opens in a new tab)
bool sun::lsp::declaresParameter(const sun::ast::PrototypeAST &proto, const std::string &name)Reports whether a function signature declares the requested parameter.
Related: sun::ast::PrototypeAST
findAnnotatedType
public · function · Source (opens in a new tab)
const ExprAST * sun::lsp::findAnnotatedType(const BlockExprAST &program, const sun::ast::TypeAnnotation &annotation)The user-defined type an annotation names, looking through ref, pointer and array wrappers when their element has no span of its own.
Resolves the type named by a source annotation.
Related: ExprAST, BlockExprAST, sun::ast::TypeAnnotation
findDeclaration
public · function · Source (opens in a new tab)
const ExprAST * sun::lsp::findDeclaration(const BlockExprAST &program, const std::string &name, const QualifiedName &qualified)Module-level declaration with this name; a qualified-name match wins over a plain name match when the reference was resolved by the analyzer.
Finds a declaration by its local and qualified names.
Related: ExprAST, BlockExprAST, QualifiedName
findDeclarationAt
public · function · Source (opens in a new tab)
std::optional< Declaration > sun::lsp::findDeclarationAt(const BlockExprAST &program, const std::string &documentPath, const std::string &source, int byteOffset)Where the symbol at byteOffset was declared: the type a written annotation names, else the declaration behind the node under the cursor.
Finds the declaration associated with a document byte offset.
Related: Declaration, BlockExprAST
findDeclarationOf
public · function · Source (opens in a new tab)
std::optional< Declaration > sun::lsp::findDeclarationOf(const BlockExprAST &program, const std::vector< const ExprAST * > &chain, const ExprAST &node, const DeclarationIndex *declarations=nullptr)Where the symbol under node was declared, or nothing.
Resolves the declaration referenced by a node in its enclosing scopes.
An optional index must cover the same program and is used for repeated reference lookups.
Related: Declaration, BlockExprAST, ExprAST, DeclarationIndex
findInnermostNodeAt
public · function · Source (opens in a new tab)
const ExprAST * sun::lsp::findInnermostNodeAt(const sun::ast::BlockExprAST &program, const std::string &filePath, int byteOffset)Innermost node from filePath whose span contains byteOffset, or null.
Finds the most deeply nested syntax node covering a document offset.
Nodes without a span (module wrappers from merged compilation) are looked through; moon import stubs and nodes from other files are skipped.
Related: sun::ast::ExprAST, sun::ast::BlockExprAST
findLocalDeclaration
public · function · Source (opens in a new tab)
std::optional< Declaration > sun::lsp::findLocalDeclaration(const std::vector< const ExprAST * > &chain, const ExprAST &node, const std::string &name)Declaration of a local name visible at node: the closest earlier var/const/ref in an enclosing block, or an enclosing loop variable.
Searches enclosing lexical scopes for a local declaration.
Parameters have no declaration of their own and yield nothing.
Related: Declaration, ExprAST
findMember
public · function · Source (opens in a new tab)
std::optional< Declaration > sun::lsp::findMember(const ExprAST &definition, const std::string &member)A member (method, field or variant) inside a definition.
Finds a named member in a type definition.
Related: Declaration, ExprAST
findMemberDeclaration
public · function · Source (opens in a new tab)
std::optional< Declaration > sun::lsp::findMemberDeclaration(const BlockExprAST &program, const ExprAST &object, const std::string &member, const QualifiedName &qualifiedName)The member behind object.member: a module's item (the analyzer records which module's in qualifiedName), or a field, method or variant of the object's type.
Resolves the named member on the receiver's type.
A match pattern's object carries no type, so a bare name there is looked up as a type.
Related: Declaration, BlockExprAST, ExprAST, QualifiedName
findOccurrences
public · function · Source (opens in a new tab)
Occurrences sun::lsp::findOccurrences(const BlockExprAST &program, const std::string &documentPath, const std::string &source, const std::vector< Declaration > &targets, bool includeDeclaration)Where each of targets is named, as computeReferences lists them, merged into one sorted list.
Collects source occurrences of the selected declarations.
Declarations outside the tree are not added.
Related: Occurrences, BlockExprAST, Declaration
findParameter
public · function · Source (opens in a new tab)
std::optional< Declaration > sun::lsp::findParameter(const std::vector< const ExprAST * > &chain, const std::string &name)The nearest enclosing function or lambda declaring name as a parameter.
Finds a named parameter in the enclosing function signatures.
Related: Declaration, ExprAST
findTypeDefinition
public · function · Source (opens in a new tab)
const ExprAST * sun::lsp::findTypeDefinition(const BlockExprAST &program, const sun::types::Type &type)Definition node (class, interface or enum) behind a type.
Finds the syntax declaration corresponding to a semantic type.
Related: ExprAST, BlockExprAST, sun::types::Type
findWord
public · function · Source (opens in a new tab)
int sun::lsp::findWord(const std::string &text, const std::string &name, size_t from, size_t to)Offset of the first whole word name in text[from, to), or -1.
Finds a complete identifier within a bounded source range.
firstSpecialization
public · function · Source (opens in a new tab)
const ExprAST * sun::lsp::firstSpecialization(const ExprAST &node, Bindings &bindings)First specialization of a generic class or function, with its bindings; null when the node is not a generic template or was never used.
Finds a concrete generic instance and its type bindings for editor lookup.
forEachAnnotation
public · function · Source (opens in a new tab)
void sun::lsp::forEachAnnotation(const ExprAST &node, const AnnotationFn &fn)Visits type annotations directly associated with a syntax node.
Related: ExprAST, AnnotationFn
getAnalyzedDocument
public · function · Source (opens in a new tab)
const AnalyzedDocument * sun::lsp::getAnalyzedDocument(const OpenDocument &document)Analyzed tree for the document's current text, or null when it cannot be parsed.
Returns a cached analyzed tree, retaining partial trees after errors.
Analysis errors keep the partial tree: everything typed before the error still answers hover requests.
Related: AnalyzedDocument, OpenDocument
handleDocuments
public · function · Source (opens in a new tab)
bool sun::lsp::handleDocuments(const std::string &methodName, const llvm::json::Value *id, llvm::json::Object *params, std::unordered_map< std::string, OpenDocument > &openDocuments)Dispatches documents messages using the current document state.
Handles documents messages; returns whether the method was recognized.
Related: OpenDocument
handleFormatting
public · function · Source (opens in a new tab)
bool sun::lsp::handleFormatting(const std::string &methodName, const llvm::json::Value *id, llvm::json::Object *params, std::unordered_map< std::string, OpenDocument > &openDocuments)Dispatches formatting messages using the current document state.
Handles formatting messages; returns whether the method was recognized.
Related: OpenDocument
handleNavigation
public · function · Source (opens in a new tab)
bool sun::lsp::handleNavigation(const std::string &methodName, const llvm::json::Value *id, llvm::json::Object *params, std::unordered_map< std::string, OpenDocument > &openDocuments)Dispatches navigation messages using the current document state.
Handles navigation messages; returns whether the method was recognized.
Related: OpenDocument
handleTestRequests
public · function · Source (opens in a new tab)
bool sun::lsp::handleTestRequests(const std::string &methodName, const llvm::json::Value *id, llvm::json::Object *params, std::unordered_map< std::string, OpenDocument > &openDocuments)Handles test requests messages; returns whether the method was recognized.
Dispatches test requests messages using the current document state.
Related: OpenDocument
inspectTestBuild
public · function · static · Source (opens in a new tab)
static TestBuildInspection sun::lsp::inspectTestBuild(const TestBuildCandidate &candidate, const std::string &configurationError, std::set< std::string > &watched, std::set< std::string > &binaries)Resolve inputs in this build's graph and inspect artifacts without executing them.
Related: TestBuildInspection, TestBuildCandidate
isDefinition
public · function · Source (opens in a new tab)
bool sun::lsp::isDefinition(sun::ast::ASTNodeType kind)Reports whether the syntax-node kind introduces a declaration.
Related: sun::ast::ASTNodeType
lineStart
public · function · Source (opens in a new tab)
size_t sun::lsp::lineStart(const std::string &text, int line)Byte offset of the first character on a zero-based line (text.size() if the line does not exist).
locate
public · function · Source (opens in a new tab)
std::optional< Target > sun::lsp::locate(const BlockExprAST &program, const std::string &documentPath, int offset)Node chain at the offset.
Finds the syntax node and ancestor chain at a document offset.
Generic templates are analyzed only through their specializations, so the chain is redirected into the first specialization of any generic class or function it passes through; the clones keep the template's source spans.
Related: Target, BlockExprAST
lspPositionFromByteOffset
public · function · Source (opens in a new tab)
LspPosition sun::lsp::lspPositionFromByteOffset(const std::string &text, int offset)Protocol position for a byte offset (clamped to the text).
Related: LspPosition
makePosition
public · function · static · Source (opens in a new tab)
static llvm::json::Object sun::lsp::makePosition(int line, int character)Builds a JSON source position for the language server protocol.
makeRange
public · function · Source (opens in a new tab)
llvm::json::Object sun::lsp::makeRange(int startLine, int startCharacter, int endLine, int endCharacter)Builds a JSON source range for the language server protocol.
Creates a zero-based protocol source range.
makeSymbolLocation
public · function · Source (opens in a new tab)
SymbolLocation sun::lsp::makeSymbolLocation(const std::string &filePath, const sun::support::Position &range, const std::string &text)Protocol form of a byte range inside text.
Converts a source span to an editor navigation location.
Related: SymbolLocation, sun::support::Position
memberGroupOf
public · function · Source (opens in a new tab)
MemberGroup sun::lsp::memberGroupOf(const BlockExprAST &program, const Declaration &declaration, const std::string &documentPath)Finds related member declarations that share a rename operation.
Related: MemberGroup, BlockExprAST, Declaration
nameRange
public · function · Source (opens in a new tab)
Position sun::lsp::nameRange(const sun::support::Position &span, const std::string &name, const std::string &text)The name token of a declaration: the span itself when it already is the name, otherwise the first whole word name inside it, or the name just before it (a signature span starts at its parenthesis).
Finds the identifier's exact range within its declaration span.
Falls back to an empty range at the start of the span.
Related: sun::support::Position
nameRangeOf
public · function · Source (opens in a new tab)
Position sun::lsp::nameRangeOf(const Declaration &declaration, const std::string &text)The declared name's range, in the declaration's own file.
Finds the exact name range of a resolved declaration.
Related: sun::support::Position, Declaration
normalizePath
public · function · Source (opens in a new tab)
std::string sun::lsp::normalizePath(const std::string &path)Canonical form of a path that exists on disk; other paths are unchanged.
Converts a path to the normalized form used for document comparisons.
ownDeclaration
public · function · Source (opens in a new tab)
std::optional< Declaration > sun::lsp::ownDeclaration(const ExprAST &node, int offset, const std::string &source)The declaration for a cursor on a definition's own header: the definition, or the field, variant, parameter or binding written there.
Finds a declaration introduced at the selected position within a node.
Related: Declaration, ExprAST
parameterRange
public · function · Source (opens in a new tab)
std::optional< Position > sun::lsp::parameterRange(const sun::ast::ExprAST &owner, const std::string &name, const std::string &text)Where name is declared in a signature: name: or name... after the opening parenthesis.
Finds the source range of a named function parameter.
Related: sun::support::Position, sun::ast::ExprAST
pathToUri
public · function · Source (opens in a new tab)
std::string sun::lsp::pathToUri(const std::string &path)file:// URI for an absolute path; bytes outside the unreserved set are percent-encoded (the inverse of uriToPath)
Converts a filesystem path to an editor file URI.
percentDecode
public · function · static · Source (opens in a new tab)
static std::string sun::lsp::percentDecode(std::string_view encoded)Decodes percent-escaped bytes in a URI component.
prototypeOf
public · function · Source (opens in a new tab)
const PrototypeAST * sun::lsp::prototypeOf(const sun::ast::ExprAST &node)Signature of a function or lambda; null for other nodes.
Returns the signature belonging to a function-like syntax node.
Related: sun::ast::PrototypeAST, sun::ast::ExprAST
publishDiagnostics
public · function · Source (opens in a new tab)
void sun::lsp::publishDiagnostics(const std::string &uri, llvm::json::Array diagnostics, int version)Notifies the editor of diagnostics for a specific document version.
Publishes diagnostics for the supplied document version.
rangeAt
public · function · Source (opens in a new tab)
Position sun::lsp::rangeAt(const sun::support::Position &base, int offset, int length)length bytes at offset in the file of base
Creates a source span from an offset and length within a base position.
Related: sun::support::Position
readEntrypoints
public · function · Source (opens in a new tab)
std::optional< std::vector< std::string > > sun::lsp::readEntrypoints(const llvm::json::Object &config)Read a configuration object's "entrypoints" member.
Reads explicit entrypoints from editor configuration.
Entries may be strings or {path: string} objects. Returns nullopt if the member is absent.
readMessageBody
public · function · Source (opens in a new tab)
std::optional< std::string > sun::lsp::readMessageBody()Reads the next framed language server message from standard input.
Reads the next framed JSON-RPC message from standard input.
readSunConfigs
public · function · Source (opens in a new tab)
std::optional< std::vector< std::string > > sun::lsp::readSunConfigs(const llvm::json::Object &config)The sun_configs setting: sun-config.json files whose entrypoints the server should know about.
Reads project configuration paths from editor configuration.
Paths arrive absolute from the client.
refreshEntrypoints
public · function · Source (opens in a new tab)
void sun::lsp::refreshEntrypoints()Re-read the configured sun-config files and hand the manager the union of their entrypoints, explicitly configured ones, and open manifest files (configs first, so a file covered by both maps to the config's entrypoint).
Reloads configured and open manifest entrypoints.
A config that fails to parse is skipped: a bad editor setting must not kill the server.
resolveSymbol
public · function · Source (opens in a new tab)
std::optional< Declaration > sun::lsp::resolveSymbol(const BlockExprAST &program, const std::vector< const ExprAST * > &chain, const ExprAST &node, const DeclarationIndex *declarations=nullptr)The declaration a name-bearing node refers to: a local, a parameter, or what findDeclarationOf finds.
Resolves a syntax node to the declaration it denotes.
Used for the cursor and for every candidate reference alike, so both land on the same declaration. The optional index must cover the same program.
Related: Declaration, BlockExprAST, ExprAST, DeclarationIndex
runServer
public · function · Source (opens in a new tab)
int sun::lsp::runServer()Reads editor requests and runs the Sun language server message loop.
Runs the standard-input language server message loop.
sendErrorResponse
public · function · Source (opens in a new tab)
void sun::lsp::sendErrorResponse(const llvm::json::Value &id, int code, const std::string &message)Sends a JSON-RPC error response with its code and message.
Sends a JSON-RPC error to the editor.
sendResponse
public · function · Source (opens in a new tab)
void sun::lsp::sendResponse(const llvm::json::Value &id, llvm::json::Value result)Sends a successful JSON-RPC response for the supplied request identifier.
Sends a JSON-RPC result to the editor.
siteAt
public · function · Source (opens in a new tab)
std::optional< SymbolLocation > sun::lsp::siteAt(const Rename &rename, const std::string &filePath, int byteOffset)The site in filePath holding byteOffset, cursor at the end included; nothing when the cursor is outside every site.
Finds the rename occurrence covering the selected document offset.
Related: SymbolLocation, Rename
sliceSpan
public · function · Source (opens in a new tab)
std::string sun::lsp::sliceSpan(const std::string &source, const sun::support::Position &loc)Text covered by a span, or empty when the span is missing or out of range.
Returns the source text covered by a recorded span.
Related: sun::support::Position
sourceFor
public · function · Source (opens in a new tab)
std::string sun::lsp::sourceFor(const sun::support::Position &declaration, const std::string &documentPath, const std::string &documentSource)Text of the file a declaration lives in: the document itself, or a file registered during compilation (another file of the same manifest); empty when neither.
Loads declaration source, reusing the open document text when possible.
Related: sun::support::Position
spanContains
public · function · Source (opens in a new tab)
bool sun::lsp::spanContains(const sun::support::Position &loc, int offset)Reports whether a source span contains the requested byte offset.
Related: sun::support::Position
startsGenericCall
public · function · static · Source (opens in a new tab)
static bool sun::lsp::startsGenericCall(sun::parsing::Lexer &lexer)Distinguish generic calls from comparisons after an opening angle bracket.
Related: sun::parsing::Lexer
startsWith
public · function · static · Source (opens in a new tab)
static bool sun::lsp::startsWith(const std::string &text, const std::string &prefix)Reports whether text begins with the supplied prefix.
stripReference
public · function · Source (opens in a new tab)
const sun::types::Type * sun::lsp::stripReference(const sun::types::Type *type)Unwraps reference types to inspect the underlying value type.
Related: sun::types::Type
testBinaryIdentity
public · function · static · Source (opens in a new tab)
static std::optional< std::string > sun::lsp::testBinaryIdentity(const std::string &path)Matches Node's bigint stat identity before launching a capability-checked binary.
testSuites
public · function · Source (opens in a new tab)
llvm::json::Object sun::lsp::testSuites()Inventories expected test binaries and their freshness without analysis.
Lists expected test artifacts and checks their inputs without semantic analysis.
textHas
public · function · Source (opens in a new tab)
bool sun::lsp::textHas(const std::string &text, int offset, const std::string &word)True when word is written at offset.
Reports whether the expected spelling occurs at a source offset.
textOf
public · function · Source (opens in a new tab)
std::optional< std::string > sun::lsp::textOf(const sun::support::Position &location, const std::string &documentPath, const std::string &source)Text of the file holding a location: the document, a file of the same manifest, or a library source read from disk.
Retrieves source text for a location, reusing the open document when possible.
Related: sun::support::Position
toJsonPayload
public · function · static · Source (opens in a new tab)
static std::string sun::lsp::toJsonPayload(llvm::json::Value value)Serializes a JSON value for a language server message.
tokenKindToLSPType
public · function · static · Source (opens in a new tab)
static int sun::lsp::tokenKindToLSPType(TokenKind kind)Map TokenKind to LSP semantic token type index (-1 = skip).
Related: TokenKind
trimCR
public · function · static · Source (opens in a new tab)
static std::string sun::lsp::trimCR(std::string line)Removes the carriage return from a protocol header line.
uriToPath
public · function · Source (opens in a new tab)
std::string sun::lsp::uriToPath(const std::string &uri)Converts a file URI to a filesystem path.
Converts an editor file URI to a filesystem path.
utf16Units
public · function · Source (opens in a new tab)
int sun::lsp::utf16Units(size_t utf8Length)UTF-16 code units for a sequence of this byte length.
utf8Length
public · function · Source (opens in a new tab)
size_t sun::lsp::utf8Length(unsigned char lead)Number of bytes in the UTF-8 sequence that starts with this byte.
writeLSPMessage
public · function · static · Source (opens in a new tab)
static void sun::lsp::writeLSPMessage(llvm::json::Value value)Writes a JSON message with language server framing headers.
Variables
- Class
- Comment
- Enum
- EnumMember
- Event
- Function
- Interface
- Keyword
- Lifecycle
- Macro
- Method
- Modifier
- Module
- Number
- Operator
- Parameter
- Property
- Regexp
- String
- Struct
- Type
- TypeParameter
- Variable
- analyzedDocuments
- configEntrypointInfo
- configuredSunConfigs
- diagnosticsCache
- entrypointManager
- explicitEntrypoints
- openSourceOverrides
Class
public · variable · Source (opens in a new tab)
int sun::lsp::Class = 2No documentation comment.
Comment
public · variable · Source (opens in a new tab)
int sun::lsp::Comment = 17No documentation comment.
Enum
public · variable · Source (opens in a new tab)
int sun::lsp::Enum = 3No documentation comment.
EnumMember
public · variable · Source (opens in a new tab)
int sun::lsp::EnumMember = 10No documentation comment.
Event
public · variable · Source (opens in a new tab)
int sun::lsp::Event = 11No documentation comment.
Function
public · variable · Source (opens in a new tab)
int sun::lsp::Function = 12No documentation comment.
Interface
public · variable · Source (opens in a new tab)
int sun::lsp::Interface = 4No documentation comment.
Keyword
public · variable · Source (opens in a new tab)
int sun::lsp::Keyword = 15No documentation comment.
Lifecycle
public · variable · Source (opens in a new tab)
int sun::lsp::Lifecycle = 22No documentation comment.
Macro
public · variable · Source (opens in a new tab)
int sun::lsp::Macro = 14No documentation comment.
Method
public · variable · Source (opens in a new tab)
int sun::lsp::Method = 13No documentation comment.
Modifier
public · variable · Source (opens in a new tab)
int sun::lsp::Modifier = 16No documentation comment.
Module
public · variable · Source (opens in a new tab)
int sun::lsp::Module = 0No documentation comment.
Number
public · variable · Source (opens in a new tab)
int sun::lsp::Number = 19No documentation comment.
Operator
public · variable · Source (opens in a new tab)
int sun::lsp::Operator = 21No documentation comment.
Parameter
public · variable · Source (opens in a new tab)
int sun::lsp::Parameter = 7No documentation comment.
Property
public · variable · Source (opens in a new tab)
int sun::lsp::Property = 9No documentation comment.
Regexp
public · variable · Source (opens in a new tab)
int sun::lsp::Regexp = 20No documentation comment.
String
public · variable · Source (opens in a new tab)
int sun::lsp::String = 18No documentation comment.
Struct
public · variable · Source (opens in a new tab)
int sun::lsp::Struct = 5No documentation comment.
Type
public · variable · Source (opens in a new tab)
int sun::lsp::Type = 1No documentation comment.
TypeParameter
public · variable · Source (opens in a new tab)
int sun::lsp::TypeParameter = 6No documentation comment.
Variable
public · variable · Source (opens in a new tab)
int sun::lsp::Variable = 8No documentation comment.
analyzedDocuments
public · variable · static · Source (opens in a new tab)
std::unordered_map<std::string, AnalyzedDocument> sun::lsp::analyzedDocumentsNo documentation comment.
Related: AnalyzedDocument
configEntrypointInfo
public · variable · Source (opens in a new tab)
std::map< std::string, sun::driver::ConfigEntrypoint > sun::lsp::configEntrypointInfoNo documentation comment.
Related: sun::driver::ConfigEntrypoint
configuredSunConfigs
public · variable · Source (opens in a new tab)
std::vector< std::string > sun::lsp::configuredSunConfigsNo documentation comment.
diagnosticsCache
public · variable · static · Source (opens in a new tab)
DiagnosticsCache sun::lsp::diagnosticsCacheNo documentation comment.
Related: DiagnosticsCache
entrypointManager
public · variable · Source (opens in a new tab)
EntrypointManager sun::lsp::entrypointManagerNo documentation comment.
Related: EntrypointManager
explicitEntrypoints
public · variable · Source (opens in a new tab)
std::vector< std::string > sun::lsp::explicitEntrypointsNo documentation comment.
openSourceOverrides
public · variable · Source (opens in a new tab)
std::map< std::string, std::string > sun::lsp::openSourceOverridesCurrent editor buffers, used to resolve manifests and analyze unsaved edits.
Enums
TestBuildPreference
public · enum · Source (opens in a new tab)
enum class sun::lsp::TestBuildPreferenceOrder build candidates without depending on their timestamps across roots.
Missing
Missing
No documentation comment.
Unknown
Unknown
No documentation comment.
Stale
Stale
No documentation comment.
Fresh
Fresh
No documentation comment.
Type Aliases
AnnotationFn
public · typedef · Source (opens in a new tab)
using sun::lsp::AnnotationFn = std::function<void(const sun::ast::TypeAnnotation&)>Every annotation written on a node: parameter and return types, a variable's or loop variable's type, field and payload types, type arguments, catch binding types.
Related: sun::ast::TypeAnnotation
Bindings
public · typedef · Source (opens in a new tab)
using sun::lsp::Bindings = std::vector<std::pair<std::string, sun::types::TypePtr>>Type parameter name -> the type it stands for in one specialization.
Related: sun::types::TypePtr
DeclarationIndex
public · typedef · Source (opens in a new tab)
using sun::lsp::DeclarationIndex =
std::unordered_map<sun::semantic_analysis::DeclarationId, const ExprAST*>Maps declaration identities to their first syntax node in a live program.
Related: sun::semantic_analysis::DeclarationId, ExprAST