Documentation
¶
Overview ¶
Copyright © 2025 Benny Powers <web@bennypowers.com>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Copyright © 2025 Benny Powers <web@bennypowers.com>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Copyright © 2025 Benny Powers <web@bennypowers.com>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Copyright © 2025 Benny Powers <web@bennypowers.com>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Copyright © 2025 Benny Powers <web@bennypowers.com>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Index ¶
- type ElementDefinition
- func (ed *ElementDefinition) Element() *M.CustomElement
- func (ed *ElementDefinition) GetClassName() string
- func (ed *ElementDefinition) GetModulePath() string
- func (ed *ElementDefinition) GetTagName() string
- func (ed *ElementDefinition) ModulePath() string
- func (ed *ElementDefinition) PackageName() string
- func (ed *ElementDefinition) SourceHref() string
- type InProcessGenerateWatcher
- type ManifestUpdateCallback
- type Registry
- func (r *Registry) AddManifest(pkg *M.Package)
- func (r *Registry) AddManifestPath(path string)
- func (r *Registry) AddWatchPath(path string)
- func (r *Registry) AllTagNames() []string
- func (r *Registry) Attributes(tagName string) (map[string]*M.Attribute, bool)
- func (r *Registry) Element(tagName string) (*M.CustomElement, bool)
- func (r *Registry) ElementDefinition(tagName string) (*ElementDefinition, bool)
- func (r *Registry) Events(tagName string) (map[string]*M.Event, bool)
- func (r *Registry) Fields(tagName string) (map[string]*M.ClassField, bool)
- func (r *Registry) FindCustomElementDeclaration(tagName string) *M.CustomElementDeclaration
- func (r *Registry) GetFileWatcher() platform.FileWatcher
- func (r *Registry) GetModuleGraph() *modulegraph.ModuleGraph
- func (r *Registry) LoadAdditionalPackages(packages []string) error
- func (r *Registry) LoadFromWorkspace(workspace types.WorkspaceContext) error
- func (r *Registry) ReloadManifestsDirectly() error
- func (r *Registry) SetGenerateWatcher(watcher platform.GenerateWatcher)
- func (r *Registry) Slots(tagName string) ([]M.Slot, bool)
- func (r *Registry) StartFileWatching(onReload func()) error
- func (r *Registry) StartGenerateWatcher() error
- func (r *Registry) StopFileWatching() error
- func (r *Registry) StopGenerateWatcher() error
- type RegistryManifestResolver
- type Server
- func (s *Server) AddManifest(manifest *M.Package)
- func (s *Server) AllDocuments() []types.Document
- func (s *Server) AllTagNames() []string
- func (s *Server) Attributes(tagName string) (map[string]*M.Attribute, bool)
- func (s *Server) Client() protocol.Client
- func (s *Server) Close() error
- func (s *Server) CodeAction(_ context.Context, params *protocol.CodeActionParams) (_ []protocol.CommandOrCodeAction, err error)
- func (s *Server) Completion(_ context.Context, params *protocol.CompletionParams) (_ protocol.CompletionResult, err error)
- func (s *Server) CompletionResolve(_ context.Context, params *protocol.CompletionItem) (_ *protocol.CompletionItem, err error)
- func (s *Server) Config() types.ServerConfig
- func (s *Server) DebugLog(format string, args ...any)
- func (s *Server) Definition(_ context.Context, params *protocol.DefinitionParams) (_ protocol.DefinitionResult, err error)
- func (s *Server) Diagnostic(_ context.Context, params *protocol.DocumentDiagnosticParams) (_ protocol.DocumentDiagnosticReport, err error)
- func (s *Server) DiagnosticWorkspace(_ context.Context, params *protocol.WorkspaceDiagnosticParams) (_ *protocol.WorkspaceDiagnosticReport, err error)
- func (s *Server) DidChange(_ context.Context, params *protocol.DidChangeTextDocumentParams) (err error)
- func (s *Server) DidChangeConfiguration(_ context.Context, params *protocol.DidChangeConfigurationParams) (err error)
- func (s *Server) DidClose(_ context.Context, params *protocol.DidCloseTextDocumentParams) (err error)
- func (s *Server) DidOpen(_ context.Context, params *protocol.DidOpenTextDocumentParams) (err error)
- func (s *Server) Document(uri string) types.Document
- func (s *Server) DocumentManager() (types.DocumentManager, error)
- func (s *Server) Element(tagName string) (*M.CustomElement, bool)
- func (s *Server) ElementCount() int
- func (s *Server) ElementDefinition(tagName string) (types.ElementDefinition, bool)
- func (s *Server) ElementDescription(tagName string) (string, bool)
- func (s *Server) ElementSource(tagName string) (string, bool)
- func (s *Server) Events(tagName string) (map[string]*M.Event, bool)
- func (s *Server) Fields(tagName string) (map[string]*M.ClassField, bool)
- func (s *Server) FileSystem() platform.FileSystem
- func (s *Server) FindCustomElementDeclaration(tagName string) *M.CustomElementDeclaration
- func (s *Server) Hover(_ context.Context, params *protocol.HoverParams) (_ *protocol.Hover, err error)
- func (s *Server) Initialize(_ context.Context, params *protocol.InitializeParams) (_ *protocol.InitializeResult, err error)
- func (s *Server) InitializeForTesting() error
- func (s *Server) InitializeManifests() error
- func (s *Server) Initialized(_ context.Context, params *protocol.InitializedParams) (err error)
- func (s *Server) InlayHint(_ context.Context, params *protocol.InlayHintParams) (_ []protocol.InlayHint, err error)
- func (s *Server) InlayHintsEnabled() bool
- func (s *Server) ManifestCount() int
- func (s *Server) ModuleGraph() *modulegraph.ModuleGraph
- func (s *Server) QueryManager() (*treesitter.QueryManager, error)
- func (s *Server) References(_ context.Context, params *protocol.ReferenceParams) (_ []protocol.Location, err error)
- func (s *Server) Registry() *Registry
- func (s *Server) Run() error
- func (s *Server) SetAdditionalPackages(packages []string)
- func (s *Server) SetClient(client protocol.Client)
- func (s *Server) SetConfig(config types.ServerConfig)
- func (s *Server) SetTrace(_ context.Context, params *protocol.SetTraceParams) (err error)
- func (s *Server) SetUsePullDiagnostics(enabled bool)
- func (s *Server) Shutdown(_ context.Context) (err error)
- func (s *Server) Slots(tagName string) ([]M.Slot, bool)
- func (s *Server) Symbols(_ context.Context, params *protocol.WorkspaceSymbolParams) (_ protocol.WorkspaceSymbolResult, err error)
- func (s *Server) SynthesizeEphemeralElements(uri string)
- func (s *Server) UpdateWorkspaceFromLSP(rootURI *string, workspaceFolders []protocol.WorkspaceFolder) error
- func (s *Server) UsePullDiagnostics() bool
- func (s *Server) Workspace() types.Workspace
- func (s *Server) WorkspaceRoot() string
- type TransportKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ElementDefinition ¶
type ElementDefinition struct {
CustomElement *M.CustomElement
Source *M.SourceReference // Source reference if available
// contains filtered or unexported fields
}
ElementDefinition stores a custom element with its source information
func (*ElementDefinition) Element ¶
func (ed *ElementDefinition) Element() *M.CustomElement
Element returns the custom element for this definition
func (*ElementDefinition) GetClassName ¶ added in v0.4.5
func (ed *ElementDefinition) GetClassName() string
GetClassName returns the class name
func (*ElementDefinition) GetModulePath ¶ added in v0.4.5
func (ed *ElementDefinition) GetModulePath() string
GetModulePath returns the module path (for module graph interface compatibility)
func (*ElementDefinition) GetTagName ¶ added in v0.4.5
func (ed *ElementDefinition) GetTagName() string
GetTagName returns the tag name
func (*ElementDefinition) ModulePath ¶
func (ed *ElementDefinition) ModulePath() string
ModulePath returns the module path for this element definition
func (*ElementDefinition) PackageName ¶
func (ed *ElementDefinition) PackageName() string
PackageName returns the package name for this element definition
func (*ElementDefinition) SourceHref ¶
func (ed *ElementDefinition) SourceHref() string
SourceHref returns the source href for this element definition
type InProcessGenerateWatcher ¶
type InProcessGenerateWatcher struct {
// contains filtered or unexported fields
}
InProcessGenerateWatcher manages in-process generate watching for the LSP server This replaces the subprocess-based approach to prevent hanging processes It generates manifests in-memory only, never writing to files
func NewInProcessGenerateWatcher ¶
func NewInProcessGenerateWatcher( workspace types.WorkspaceContext, globs []string, callback ManifestUpdateCallback, fsys platform.FileSystem, ) (*InProcessGenerateWatcher, error)
NewInProcessGenerateWatcher creates a new in-process generate watcher
func (*InProcessGenerateWatcher) IsRunning ¶
func (w *InProcessGenerateWatcher) IsRunning() bool
IsRunning returns true if the watcher is currently active
func (*InProcessGenerateWatcher) Start ¶
func (w *InProcessGenerateWatcher) Start() error
Start begins the file watching process in a goroutine This will watch for source file changes and regenerate the manifest automatically NOTE: This generates manifests in-memory only and calls the callback, never writes files Thread-safety: All operations in this function are protected by mu
func (*InProcessGenerateWatcher) Stop ¶
func (w *InProcessGenerateWatcher) Stop() error
Stop cleanly shuts down the file watcher Thread-safety: All operations in this function are protected by mu
type ManifestUpdateCallback ¶
ManifestUpdateCallback is called when a new manifest is generated
type Registry ¶
type Registry struct {
// Elements maps tag names to their definitions
Elements map[string]*M.CustomElement
// ElementDefinitions maps tag names to their definitions with source information
ElementDefinitions map[string]*ElementDefinition
// Manifests stores all loaded manifest packages
Manifests []*M.Package
// ManifestPaths tracks the file paths of loaded CEM manifests for reload
ManifestPaths []string
// WatchPaths tracks all file paths watched for changes (manifests + package.json)
WatchPaths []string
// ManifestPackageNames tracks the package name for each manifest path
ManifestPackageNames map[string]string
// contains filtered or unexported fields
}
Registry manages all loaded custom elements manifests and provides fast lookup capabilities for LSP features
func NewRegistry ¶
func NewRegistry(fileWatcher platform.FileWatcher, fsys platform.FileSystem) *Registry
NewRegistry creates a new empty registry with the given file watcher. If fsys is nil, it defaults to platform.NewOSFileSystem(). For production use, pass platform.NewFSNotifyFileWatcher(). For testing, pass platform.NewMockFileWatcher().
func NewRegistryWithDefaults ¶
NewRegistryWithDefaults creates a registry with production defaults. This is a convenience constructor for production use.
func (*Registry) AddManifest ¶
AddManifest adds a custom elements manifest to the registry This allows programmatic addition of manifests from various sources
func (*Registry) AddManifestPath ¶
AddManifestPath adds a manifest file path to the tracking list for file watching This is useful for testing scenarios where you need to watch specific manifest files
func (*Registry) AddWatchPath ¶ added in v0.11.0
AddWatchPath adds a file path to the watch list without treating it as a manifest.
func (*Registry) AllTagNames ¶
AllTagNames returns all registered custom element tag names
func (*Registry) Attributes ¶
Attributes returns the available attributes for a custom element tag
func (*Registry) Element ¶
func (r *Registry) Element(tagName string) (*M.CustomElement, bool)
Element returns the custom element definition for a tag name
func (*Registry) ElementDefinition ¶
func (r *Registry) ElementDefinition(tagName string) (*ElementDefinition, bool)
ElementDefinition returns the element definition with source information for a tag name
func (*Registry) Events ¶ added in v0.11.0
Events returns the available events for a custom element tag
func (*Registry) FindCustomElementDeclaration ¶ added in v0.8.0
func (r *Registry) FindCustomElementDeclaration(tagName string) *M.CustomElementDeclaration
FindCustomElementDeclaration finds the full CustomElementDeclaration for a given tag name. This provides access to the complete declaration including summary and description, which are not available on the CustomElement struct alone.
Returns nil if no matching element is found.
func (*Registry) GetFileWatcher ¶ added in v0.4.6
func (r *Registry) GetFileWatcher() platform.FileWatcher
GetFileWatcher returns the file watcher for testing purposes
func (*Registry) GetModuleGraph ¶ added in v0.4.5
func (r *Registry) GetModuleGraph() *modulegraph.ModuleGraph
GetModuleGraph returns the module graph for re-export analysis
func (*Registry) LoadAdditionalPackages ¶ added in v0.9.3
LoadAdditionalPackages loads manifests from additional package specifiers. Accepts URLs (https://...), npm specifiers (npm:@scope/pkg), and jsr specifiers (jsr:...). Packages that fail to load are logged as warnings; loading continues with remaining packages.
func (*Registry) LoadFromWorkspace ¶
func (r *Registry) LoadFromWorkspace(workspace types.WorkspaceContext) error
LoadFromWorkspace loads all available custom elements manifests from the workspace context
func (*Registry) ReloadManifestsDirectly ¶
ReloadManifestsDirectly bypasses workspace caching by directly reading manifest files from disk This is used when manifest files change and we need to force a fresh read
func (*Registry) SetGenerateWatcher ¶ added in v0.4.6
func (r *Registry) SetGenerateWatcher(watcher platform.GenerateWatcher)
SetGenerateWatcher sets a custom generate watcher for testing purposes
func (*Registry) StartFileWatching ¶
StartFileWatching initializes file watching for manifest changes Thread-safety: All operations in this function are protected by watcherMu.Lock()
func (*Registry) StartGenerateWatcher ¶
StartGenerateWatcher starts the generate watcher for the local project if one exists This auto-regenerates the manifest when source files change
func (*Registry) StopFileWatching ¶
StopFileWatching stops file watching Thread-safety: All operations in this function are protected by watcherMu.Lock()
func (*Registry) StopGenerateWatcher ¶
StopGenerateWatcher stops the generate watcher if it's running
type RegistryManifestResolver ¶ added in v0.4.5
type RegistryManifestResolver struct {
// contains filtered or unexported fields
}
RegistryManifestResolver implements ManifestResolver using the registry's manifest data
func NewRegistryManifestResolver ¶ added in v0.4.5
func NewRegistryManifestResolver(registry *Registry) *RegistryManifestResolver
NewRegistryManifestResolver creates a new manifest resolver using the registry
func (*RegistryManifestResolver) FindManifestModulesForImportPath ¶ added in v0.4.5
func (r *RegistryManifestResolver) FindManifestModulesForImportPath(importPath string) []string
FindManifestModulesForImportPath finds manifest modules that match an import path
func (*RegistryManifestResolver) GetElementsFromManifestModule ¶ added in v0.4.5
func (r *RegistryManifestResolver) GetElementsFromManifestModule(manifestModulePath string) []string
GetElementsFromManifestModule returns all custom element tag names available from a manifest module
func (*RegistryManifestResolver) GetManifestModulePath ¶ added in v0.4.5
func (r *RegistryManifestResolver) GetManifestModulePath(filePath string) string
GetManifestModulePath converts a file path to its corresponding manifest module path
type Server ¶
type Server struct {
protocol.UnimplementedServer
// contains filtered or unexported fields
}
Server represents the CEM LSP server
func NewServer ¶
func NewServer(workspace types.WorkspaceContext, transport TransportKind) (*Server, error)
NewServer creates a new CEM LSP server
func (*Server) AddManifest ¶
func (*Server) AllDocuments ¶
func (*Server) AllTagNames ¶
func (*Server) Attributes ¶
func (*Server) CodeAction ¶ added in v0.11.1
func (s *Server) CodeAction(_ context.Context, params *protocol.CodeActionParams) (_ []protocol.CommandOrCodeAction, err error)
func (*Server) Completion ¶ added in v0.11.1
func (s *Server) Completion(_ context.Context, params *protocol.CompletionParams) (_ protocol.CompletionResult, err error)
func (*Server) CompletionResolve ¶ added in v0.11.1
func (s *Server) CompletionResolve(_ context.Context, params *protocol.CompletionItem) (_ *protocol.CompletionItem, err error)
func (*Server) Config ¶ added in v0.10.0
func (s *Server) Config() types.ServerConfig
Config returns the current server configuration (thread-safe)
func (*Server) Definition ¶ added in v0.11.1
func (s *Server) Definition(_ context.Context, params *protocol.DefinitionParams) (_ protocol.DefinitionResult, err error)
func (*Server) Diagnostic ¶ added in v0.11.1
func (s *Server) Diagnostic(_ context.Context, params *protocol.DocumentDiagnosticParams) (_ protocol.DocumentDiagnosticReport, err error)
func (*Server) DiagnosticWorkspace ¶ added in v0.11.1
func (s *Server) DiagnosticWorkspace(_ context.Context, params *protocol.WorkspaceDiagnosticParams) (_ *protocol.WorkspaceDiagnosticReport, err error)
func (*Server) DidChangeConfiguration ¶ added in v0.11.1
func (*Server) DocumentManager ¶
func (s *Server) DocumentManager() (types.DocumentManager, error)
func (*Server) ElementCount ¶ added in v0.4.1
ElementCount returns the number of loaded elements
func (*Server) ElementDefinition ¶
func (s *Server) ElementDefinition(tagName string) (types.ElementDefinition, bool)
func (*Server) ElementDescription ¶
func (*Server) FileSystem ¶ added in v0.8.0
func (s *Server) FileSystem() platform.FileSystem
func (*Server) FindCustomElementDeclaration ¶ added in v0.8.0
func (s *Server) FindCustomElementDeclaration(tagName string) *M.CustomElementDeclaration
func (*Server) Initialize ¶ added in v0.11.1
func (s *Server) Initialize(_ context.Context, params *protocol.InitializeParams) (_ *protocol.InitializeResult, err error)
func (*Server) InitializeForTesting ¶
InitializeForTesting initializes the server without running stdio - for testing only
func (*Server) InitializeManifests ¶
func (*Server) Initialized ¶ added in v0.11.1
func (*Server) InlayHintsEnabled ¶ added in v0.10.0
InlayHintsEnabled returns whether inlay hints are enabled
func (*Server) ManifestCount ¶ added in v0.4.1
ManifestCount returns the number of loaded manifests
func (*Server) ModuleGraph ¶ added in v0.4.5
func (s *Server) ModuleGraph() *modulegraph.ModuleGraph
func (*Server) QueryManager ¶
func (s *Server) QueryManager() (*treesitter.QueryManager, error)
func (*Server) References ¶ added in v0.11.1
func (*Server) SetAdditionalPackages ¶ added in v0.9.3
SetAdditionalPackages sets the additional packages to load during manifest initialization
func (*Server) SetConfig ¶ added in v0.10.0
func (s *Server) SetConfig(config types.ServerConfig)
SetConfig updates the server configuration (thread-safe)
func (*Server) SetUsePullDiagnostics ¶ added in v0.10.0
SetUsePullDiagnostics sets whether pull diagnostics model is active
func (*Server) Symbols ¶ added in v0.11.1
func (s *Server) Symbols(_ context.Context, params *protocol.WorkspaceSymbolParams) (_ protocol.WorkspaceSymbolResult, err error)
func (*Server) SynthesizeEphemeralElements ¶ added in v0.9.5
SynthesizeEphemeralElements runs synthesis of element declarations from a TypeScript/JavaScript document that defines custom elements locally. The synthesized data is stored in the ephemeral registry and acts as a fallback for all LSP features.
Synthesis runs synchronously so that ephemeral data is available before diagnostics fire. The per-file cost is ~1-5ms, well within LSP budgets.
If the document is no longer open (e.g., after DidClose), ephemeral data for the URI is removed immediately.
func (*Server) UpdateWorkspaceFromLSP ¶
func (s *Server) UpdateWorkspaceFromLSP(rootURI *string, workspaceFolders []protocol.WorkspaceFolder) error
UpdateWorkspaceFromLSP updates the workspace context based on LSP initialize parameters
func (*Server) UsePullDiagnostics ¶ added in v0.10.0
UsePullDiagnostics returns whether pull diagnostics model is active
func (*Server) WorkspaceRoot ¶
type TransportKind ¶ added in v0.4.1
type TransportKind string
TransportKind represents different LSP transport methods
const ( TransportStdio TransportKind = "stdio" TransportTCP TransportKind = "tcp" TransportWebSocket TransportKind = "websocket" TransportNodeJS TransportKind = "nodejs" )