Static type checker for Python with command-line tool and language server capabilities
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
LSP-compliant language server providing real-time type checking and IntelliSense features for Python development environments.
The language server binary that implements the Language Server Protocol for editor integration.
pyright-langserverCommunication Protocol:
Real-time language services for Python development.
interface PublishDiagnosticsParams {
uri: string;
diagnostics: Diagnostic[];
}
interface Diagnostic {
range: Range;
severity?: DiagnosticSeverity;
code?: number | string;
source?: string;
message: string;
relatedInformation?: DiagnosticRelatedInformation[];
}Provides real-time type checking and error reporting as you type.
interface CompletionParams {
textDocument: TextDocumentIdentifier;
position: Position;
context?: CompletionContext;
}
interface CompletionItem {
label: string;
kind?: CompletionItemKind;
detail?: string;
documentation?: string | MarkupContent;
insertText?: string;
additionalTextEdits?: TextEdit[];
}Provides intelligent code completion with:
interface HoverParams {
textDocument: TextDocumentIdentifier;
position: Position;
}
interface Hover {
contents: MarkupContent | MarkedString | MarkedString[];
range?: Range;
}Shows type information, documentation, and signatures on hover.
interface DefinitionParams {
textDocument: TextDocumentIdentifier;
position: Position;
}
type Definition = Location | Location[];Navigate to symbol definitions across files and packages.
interface ReferenceParams {
textDocument: TextDocumentIdentifier;
position: Position;
context: ReferenceContext;
}
type References = Location[];Find all usages of symbols throughout the codebase.
interface RenameParams {
textDocument: TextDocumentIdentifier;
position: Position;
newName: string;
}
interface WorkspaceEdit {
changes?: { [uri: string]: TextEdit[] };
documentChanges?: TextDocumentEdit[];
}Rename symbols with automatic updates across all references.
interface DocumentSymbolParams {
textDocument: TextDocumentIdentifier;
}
interface DocumentSymbol {
name: string;
detail?: string;
kind: SymbolKind;
range: Range;
selectionRange: Range;
children?: DocumentSymbol[];
}Provides document outline and symbol navigation.
interface WorkspaceSymbolParams {
query: string;
}
interface WorkspaceSymbol {
name: string;
kind: SymbolKind;
location: Location;
containerName?: string;
}Search for symbols across the entire workspace.
interface SignatureHelpParams {
textDocument: TextDocumentIdentifier;
position: Position;
}
interface SignatureHelp {
signatures: SignatureInformation[];
activeSignature?: number;
activeParameter?: number;
}Shows function signature information during function calls.
interface CodeActionParams {
textDocument: TextDocumentIdentifier;
range: Range;
context: CodeActionContext;
}
interface CodeAction {
title: string;
kind?: string;
diagnostics?: Diagnostic[];
edit?: WorkspaceEdit;
command?: Command;
}Provides quick fixes and refactoring actions:
interface CallHierarchyPrepareParams {
textDocument: TextDocumentIdentifier;
position: Position;
}
interface CallHierarchyItem {
name: string;
kind: SymbolKind;
uri: string;
range: Range;
selectionRange: Range;
}View incoming and outgoing call relationships.
The language server respects the same configuration files as the CLI:
interface ServerSettings {
// File watching
watchForSourceChanges: boolean;
watchForLibraryChanges: boolean;
watchForConfigChanges: boolean;
// Analysis scope
openFilesOnly: boolean;
useLibraryCodeForTypes: boolean;
// Features
disableLanguageServices: boolean;
autoImportCompletions: boolean;
// Type checking
typeCheckingMode: "off" | "basic" | "standard" | "strict";
diagnosticSeverityOverrides: { [rule: string]: "none" | "information" | "warning" | "error" };
// Display
functionSignatureDisplay: "compact" | "formatted";
logLevel: "Error" | "Warning" | "Information" | "Trace";
}{
"python.languageServer": "Pylance",
"python.analysis.typeCheckingMode": "strict",
"python.analysis.autoImportCompletions": true
}require'lspconfig'.pyright.setup{
settings = {
python = {
analysis = {
typeCheckingMode = "strict",
autoSearchPaths = true,
useLibraryCodeForTypes = true
}
}
}
}(use-package lsp-pyright
:ensure t
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp))))The language server includes several performance optimizations:
The language server supports standard LSP initialization:
interface InitializeParams {
processId: number | null;
rootPath?: string | null;
rootUri: string | null;
initializationOptions?: any;
capabilities: ClientCapabilities;
workspaceFolders?: WorkspaceFolder[] | null;
}
interface ServerCapabilities {
textDocumentSync?: TextDocumentSyncOptions;
completionProvider?: CompletionOptions;
hoverProvider?: boolean;
definitionProvider?: boolean;
referencesProvider?: boolean;
renameProvider?: RenameOptions;
documentSymbolProvider?: boolean;
workspaceSymbolProvider?: boolean;
signatureHelpProvider?: SignatureHelpOptions;
codeActionProvider?: CodeActionOptions;
callHierarchyProvider?: boolean;
}The language server handles errors gracefully:
Supports multiple project roots in a single workspace:
Install with Tessl CLI
npx tessl i tessl/npm-pyright