lsp

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: GPL-3.0 Imports: 47 Imported by: 0

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

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

type ManifestUpdateCallback func(pkg *M.Package) error

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

func NewRegistryWithDefaults() (*Registry, error)

NewRegistryWithDefaults creates a registry with production defaults. This is a convenience constructor for production use.

func (*Registry) AddManifest

func (r *Registry) AddManifest(pkg *M.Package)

AddManifest adds a custom elements manifest to the registry This allows programmatic addition of manifests from various sources

func (*Registry) AddManifestPath

func (r *Registry) AddManifestPath(path string)

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

func (r *Registry) AddWatchPath(path string)

AddWatchPath adds a file path to the watch list without treating it as a manifest.

func (*Registry) AllTagNames

func (r *Registry) AllTagNames() []string

AllTagNames returns all registered custom element tag names

func (*Registry) Attributes

func (r *Registry) Attributes(tagName string) (map[string]*M.Attribute, bool)

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

func (r *Registry) Events(tagName string) (map[string]*M.Event, bool)

Events returns the available events for a custom element tag

func (*Registry) Fields added in v0.11.0

func (r *Registry) Fields(tagName string) (map[string]*M.ClassField, bool)

Fields returns the class fields 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

func (r *Registry) LoadAdditionalPackages(packages []string) error

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

func (r *Registry) ReloadManifestsDirectly() error

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) Slots

func (r *Registry) Slots(tagName string) ([]M.Slot, bool)

Slots returns the available slots for a custom element tag

func (*Registry) StartFileWatching

func (r *Registry) StartFileWatching(onReload func()) error

StartFileWatching initializes file watching for manifest changes Thread-safety: All operations in this function are protected by watcherMu.Lock()

func (*Registry) StartGenerateWatcher

func (r *Registry) StartGenerateWatcher() error

StartGenerateWatcher starts the generate watcher for the local project if one exists This auto-regenerates the manifest when source files change

func (*Registry) StopFileWatching

func (r *Registry) StopFileWatching() error

StopFileWatching stops file watching Thread-safety: All operations in this function are protected by watcherMu.Lock()

func (*Registry) StopGenerateWatcher

func (r *Registry) StopGenerateWatcher() error

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 (s *Server) AddManifest(manifest *M.Package)

func (*Server) AllDocuments

func (s *Server) AllDocuments() []types.Document

func (*Server) AllTagNames

func (s *Server) AllTagNames() []string

func (*Server) Attributes

func (s *Server) Attributes(tagName string) (map[string]*M.Attribute, bool)

func (*Server) Client added in v0.11.1

func (s *Server) Client() protocol.Client

func (*Server) Close

func (s *Server) Close() error

Close cleans up server resources

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) DebugLog

func (s *Server) DebugLog(format string, args ...any)

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 (*Server) DiagnosticWorkspace added in v0.11.1

func (s *Server) DiagnosticWorkspace(_ context.Context, params *protocol.WorkspaceDiagnosticParams) (_ *protocol.WorkspaceDiagnosticReport, err error)

func (*Server) DidChange added in v0.11.1

func (s *Server) DidChange(_ context.Context, params *protocol.DidChangeTextDocumentParams) (err error)

func (*Server) DidChangeConfiguration added in v0.11.1

func (s *Server) DidChangeConfiguration(_ context.Context, params *protocol.DidChangeConfigurationParams) (err error)

func (*Server) DidClose added in v0.11.1

func (s *Server) DidClose(_ context.Context, params *protocol.DidCloseTextDocumentParams) (err error)

func (*Server) DidOpen added in v0.11.1

func (s *Server) DidOpen(_ context.Context, params *protocol.DidOpenTextDocumentParams) (err error)

func (*Server) Document

func (s *Server) Document(uri string) types.Document

func (*Server) DocumentManager

func (s *Server) DocumentManager() (types.DocumentManager, error)

func (*Server) Element

func (s *Server) Element(tagName string) (*M.CustomElement, bool)

func (*Server) ElementCount added in v0.4.1

func (s *Server) ElementCount() int

ElementCount returns the number of loaded elements

func (*Server) ElementDefinition

func (s *Server) ElementDefinition(tagName string) (types.ElementDefinition, bool)

func (*Server) ElementDescription

func (s *Server) ElementDescription(tagName string) (string, bool)

func (*Server) ElementSource

func (s *Server) ElementSource(tagName string) (string, bool)

func (*Server) Events added in v0.11.0

func (s *Server) Events(tagName string) (map[string]*M.Event, bool)

func (*Server) Fields added in v0.11.0

func (s *Server) Fields(tagName string) (map[string]*M.ClassField, bool)

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) Hover added in v0.11.1

func (s *Server) Hover(_ context.Context, params *protocol.HoverParams) (_ *protocol.Hover, err error)

func (*Server) Initialize added in v0.11.1

func (s *Server) Initialize(_ context.Context, params *protocol.InitializeParams) (_ *protocol.InitializeResult, err error)

func (*Server) InitializeForTesting

func (s *Server) InitializeForTesting() error

InitializeForTesting initializes the server without running stdio - for testing only

func (*Server) InitializeManifests

func (s *Server) InitializeManifests() error

func (*Server) Initialized added in v0.11.1

func (s *Server) Initialized(_ context.Context, params *protocol.InitializedParams) (err error)

func (*Server) InlayHint added in v0.11.1

func (s *Server) InlayHint(_ context.Context, params *protocol.InlayHintParams) (_ []protocol.InlayHint, err error)

func (*Server) InlayHintsEnabled added in v0.10.0

func (s *Server) InlayHintsEnabled() bool

InlayHintsEnabled returns whether inlay hints are enabled

func (*Server) ManifestCount added in v0.4.1

func (s *Server) ManifestCount() int

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 (s *Server) References(_ context.Context, params *protocol.ReferenceParams) (_ []protocol.Location, err error)

func (*Server) Registry

func (s *Server) Registry() *Registry

Registry returns the registry for testing purposes

func (*Server) Run

func (s *Server) Run() error

Run starts the LSP server using the configured transport

func (*Server) SetAdditionalPackages added in v0.9.3

func (s *Server) SetAdditionalPackages(packages []string)

SetAdditionalPackages sets the additional packages to load during manifest initialization

func (*Server) SetClient added in v0.11.1

func (s *Server) SetClient(client protocol.Client)

func (*Server) SetConfig added in v0.10.0

func (s *Server) SetConfig(config types.ServerConfig)

SetConfig updates the server configuration (thread-safe)

func (*Server) SetTrace added in v0.11.1

func (s *Server) SetTrace(_ context.Context, params *protocol.SetTraceParams) (err error)

func (*Server) SetUsePullDiagnostics added in v0.10.0

func (s *Server) SetUsePullDiagnostics(enabled bool)

SetUsePullDiagnostics sets whether pull diagnostics model is active

func (*Server) Shutdown added in v0.11.1

func (s *Server) Shutdown(_ context.Context) (err error)

func (*Server) Slots

func (s *Server) Slots(tagName string) ([]M.Slot, bool)

func (*Server) Symbols added in v0.11.1

func (*Server) SynthesizeEphemeralElements added in v0.9.5

func (s *Server) SynthesizeEphemeralElements(uri string)

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

func (s *Server) UsePullDiagnostics() bool

UsePullDiagnostics returns whether pull diagnostics model is active

func (*Server) Workspace

func (s *Server) Workspace() types.Workspace

func (*Server) WorkspaceRoot

func (s *Server) WorkspaceRoot() string

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"
)

Jump to

Keyboard shortcuts

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