repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
libro
github_2023
weavefox
typescript
createMethodMap
function createMethodMap<T, H, U extends keyof T = keyof T>( methods: AnyMethodType, handlerFactory: (method: U) => H, ): T { const result: { [key in U]?: H } = {}; for (const method of Object.values(methods)) { result[method as U] = handlerFactory(method as U); } return result as T; }
/** * Create a map between the request method and its handler */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L157-L166
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.closeSignal
get closeSignal(): Event<boolean> { return this._closeSignal.event; }
/** * Signal emitted when the connection is closed. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L231-L233
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.errorSignal
get errorSignal(): Event<any> { return this._errorSignal.event; }
/** * Signal emitted when the connection receives an error * message.. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L239-L241
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.serverInitialized
get serverInitialized(): Event<lsp.ServerCapabilities<any>> { return this._serverInitialized.event; }
/** * Signal emitted when the connection is initialized. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L246-L248
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.dispose
override dispose(): void { if (this.isDisposed) { return; } if (this.serverRequests) { Object.values(this.serverRequests).forEach((request) => request.clearHandler()); } this.close(); super.dispose(); }
/** * Dispose the connection. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L253-L262
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.log
log(kind: MessageKind, message: IMessageLog): void { if (this.logAllCommunication) { // eslint-disable-next-line no-console console.log(kind, message); } this.lspmonitor.log({ serverIdentifier: this.serverIdentifier ?? '', serverLanguage: this.serverLanguage ?? '', kind, ...
/** * Helper to print the logs to logger, for now we are using * directly the browser's console. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L268-L279
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.sendOpenWhenReady
sendOpenWhenReady(documentInfo: IDocumentInfo): void { if (this.isReady) { this.sendOpen(documentInfo); } else { this.documentsToOpen.push(documentInfo); } }
/** * Send the open request to the backend when the server is * ready. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L285-L291
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.sendSelectiveChange
sendSelectiveChange( changeEvent: lsp.TextDocumentContentChangeEvent, documentInfo: IDocumentInfo, ): void { this._sendChange([changeEvent], documentInfo); }
/** * Send the document changes to the server. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L296-L301
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.sendFullTextChange
sendFullTextChange(text: string, documentInfo: IDocumentInfo): void { this._sendChange([{ text }], documentInfo); }
/** * Send all changes to the server. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L306-L308
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.provides
provides(provider: keyof lsp.ServerCapabilities): boolean { return !!(this.serverCapabilities && this.serverCapabilities[provider]); }
/** * Check if a provider is available in the registered capabilities. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L313-L315
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.close
override close(): void { try { this._closingManually = true; super.close(); } catch (e) { this._closingManually = false; } }
/** * Close the connection to the server. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L320-L327
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.connect
override connect(socket: WebSocket): void { super.connect(socket); untilReady(() => { return this.isConnected; }, -1) .then(() => { const disposable = this.connection.onClose(() => { this._isConnected = false; this._closeSignal.fire(this._closingManually); });...
/** * initialize a connection over a web socket that speaks the LSP */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L332-L348
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.getCompletionResolve
async getCompletionResolve( completionItem: lsp.CompletionItem, ): Promise<lsp.CompletionItem | undefined> { if (!this.isReady) { return; } return this.connection.sendRequest<lsp.CompletionItem>( 'completionItem/resolve', completionItem, ); }
/** * Get send request to the server to get completion results * from a completion item */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L354-L364
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.constructNotificationHandlers
protected constructNotificationHandlers< T extends ServerNotifications | ClientNotifications, >(methods: typeof Method.ServerNotification | typeof Method.ClientNotification): T { const factory = () => new Emitter<any>(); return createMethodMap<T, Emitter<any>>(methods, factory); }
/** * Generate the notification handlers */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L375-L380
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.constructClientRequestHandler
protected constructClientRequestHandler< T extends ClientRequests, U extends keyof T = keyof T, >(methods: typeof Method.ClientRequest): T { return createMethodMap<T, IClientRequestHandler>( methods, (method) => new ClientRequestHandler(this.connection, method as U as any, this), ); }
/** * Generate the client request handler */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L385-L393
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.constructServerRequestHandler
protected constructServerRequestHandler< T extends ServerRequests, U extends keyof T = keyof T, >(methods: typeof Method.ServerRequest): T { return createMethodMap<T, IServerRequestHandler>( methods, (method) => new ServerRequestHandler(this.connection, method as U as any, this), ); }
/** * Generate the server response handler */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L398-L406
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.initializeParams
protected override initializeParams(): lsp.InitializeParams { return { ...super.initializeParams(), capabilities: this._options.capabilities, initializationOptions: null, processId: null, workspaceFolders: null, }; }
/** * Initialization parameters to be sent to the language server. * Subclasses can overload this when adding more features. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L412-L420
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.onServerInitialized
protected override onServerInitialized(params: lsp.InitializeResult): void { this.afterInitialized(); super.onServerInitialized(params); while (this.documentsToOpen.length) { this.sendOpen(this.documentsToOpen.pop()!); } this._serverInitialized.fire(this.serverCapabilities); }
/** * Callback called when the server is initialized. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L425-L432
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection.afterInitialized
protected afterInitialized(): void { const disposable = this.connection.onError((e) => this._errorSignal.fire(e)); this._disposables.push(disposable); for (const method of Object.values( Method.ServerNotification, ) as (keyof ServerNotifications)[]) { const signal = this.serverNotifications[...
/** * Once the server is initialized, this method generates the * client and server handlers */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L438-L520
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPConnection._sendChange
protected _sendChange( changeEvents: lsp.TextDocumentContentChangeEvent[], documentInfo: IDocumentInfo, ) { if (!this.isReady) { return; } if (documentInfo.uri.length === 0) { return; } if (!this.openedUris.get(documentInfo.uri)) { this.sendOpen(documentInfo); } c...
/** * Send the document changed data to the server. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/connection.ts#L536-L560
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
FeatureManager.featuresRegistered
get featuresRegistered(): Event<IFeature> { return this._featuresRegistered.event; }
/** * Signal emitted when a new feature is registered. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/feature.ts#L29-L31
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
FeatureManager.register
register(feature: IFeature): void { if (this.features.some((ft) => ft.id === feature.id)) { console.warn(`Feature with id ${feature.id} is already registered, skipping.`); } else { this.features.push(feature); this._featuresRegistered.fire(feature); } }
/** * Register a new feature, skip if it is already registered. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/feature.ts#L36-L43
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
FeatureManager.clientCapabilities
clientCapabilities(): LspClientCapabilities { let capabilities: LspClientCapabilities = {}; for (const feature of this.features) { if (!feature.capabilities) { continue; } capabilities = mergeWith(capabilities, feature.capabilities); } return capabilities; }
/** * Get the capabilities of all clients. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/feature.ts#L48-L57
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPAppContribution.activateNotebookLanguageServer
async activateNotebookLanguageServer(notebook: LibroView): Promise<void> { await notebook.initialized; await this.serverManager.ready; const adapter = this.notebookAdapterFactory({ editorWidget: notebook, connectionManager: this.connectionManager, featureManager: this.featureManager, ...
/** * Activate the language server for notebook. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/lsp-app-contribution.ts#L72-L84
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.isEnabled
get isEnabled(): boolean { return this._enabled; }
/** * Check if the manager is enabled or disabled */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L67-L69
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.isDisposed
get isDisposed(): boolean { return this._isDisposed; }
/** * Check if the manager is disposed. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L73-L75
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.specs
get specs(): TSpecsMap { return this._specs; }
/** * Get the language server specs. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L80-L82
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.statusUrl
get statusUrl(): string { const baseUrl = this.serverConnection.settings.baseUrl ?? this._baseUrl; return URL.join(baseUrl, URL_NS, 'status'); }
/** * Get the status end point. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L87-L90
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.sessionsChanged
get sessionsChanged(): Event<void> { return this._sessionsChanged.event; }
/** * Signal emitted when a language server session is changed */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L95-L97
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.sessions
get sessions(): TSessionMap { return this._sessions; }
/** * Get the map of language server sessions. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L102-L104
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.ready
get ready(): Promise<void> { return this._ready.promise; }
/** * A promise resolved when this server manager is ready. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L109-L111
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.statusCode
get statusCode(): number { return this._statusCode; }
/** * Get the status code of server's responses. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L116-L118
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.enable
async enable(): Promise<void> { this._enabled = true; await this.fetchSessions(); }
/** * Enable the language server services */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L123-L126
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.disable
disable(): void { this._enabled = false; this._sessions = new Map(); this._sessionsChanged.fire(void 0); }
/** * Disable the language server services */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L131-L135
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.dispose
dispose(): void { if (this._isDisposed) { return; } this._pollSessions.dispose(); this._isDisposed = true; }
/** * Dispose the manager. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L140-L146
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.setConfiguration
setConfiguration(configuration: TLanguageServerConfigurations): void { this._configuration = configuration; }
/** * Update the language server configuration. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L151-L153
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.getMatchingServers
getMatchingServers(options: IGetServerIdOptions): TLanguageServerId[] { if (!options.language) { console.error( 'Cannot match server by language: language not available; ensure that kernel and specs provide language and MIME type', ); return []; } const matchingSessionsKeys: TLang...
/** * Get matching language server for input language option. * * modify lsp server rank on ~/.jupyter/lab/user-settings/@jupyterlab/lsp-extension */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L160-L177
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.getMatchingSpecs
getMatchingSpecs(options: IGetServerIdOptions): TSpecsMap { const result: TSpecsMap = new Map(); for (const [key, specification] of this._specs.entries()) { if (this.isMatchingSpec(options, specification)) { result.set(key, specification); } } return result; }
/** * Get matching language server spec for input language option. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L182-L191
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.fetchSessions
async fetchSessions(): Promise<void> { if (!this._enabled) { return; } let sessions: Record<string, any>; try { const response = await this.serverConnection.makeRequest(this.statusUrl, {}); this._statusCode = response.status; if (!response.ok) { if (this._retries > 0) ...
/** * Fetch the server session list from the status endpoint. The server * manager is ready once this method finishes. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L197-L251
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.isMatchingSpec
protected isMatchingSpec( options: IGetServerIdOptions, spec: ServerSpecProperties, ): boolean { // most things speak language // if language is not known, it is guessed based on MIME type earlier // so some language should be available by now (which can be not so obvious, e.g. "plain" for txt doc...
/** * Check if input language option maths the language server spec. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L261-L272
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.warnOnce
protected warnOnce(arg: string): void { if (!this._warningsEmitted.has(arg)) { this._warningsEmitted.add(arg); console.warn(arg); } }
/** * Helper function to warn a message only once. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L277-L282
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LanguageServerManager.compareRanks
protected compareRanks(a: TLanguageServerId, b: TLanguageServerId): number { const DEFAULT_RANK = 50; const defaultServerRank: Record<TLanguageServerId, number> = { 'libro-analyzer': DEFAULT_RANK + 3, pyright: DEFAULT_RANK + 2, pylsp: DEFAULT_RANK + 1, 'bash-language-server': DEFAULT_RAN...
/** * Compare the rank of two servers with the same language. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/manager.ts#L287-L314
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LSPMonitor.log
log(message: LogMessage) { this.onMessageEmitter.fire(message); }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/monitor.ts#L25-L27
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.documentPath
get documentPath(): string { return this.fileContents.path; }
/** * Get current path of the document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L74-L76
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.mimeType
get mimeType(): string { let mimeType: string | string[]; const languageMetadata = this.language_info(); if (!languageMetadata || !languageMetadata.mimetype) { // fallback to the code cell mime type if no kernel in use mimeType = this.fileContents.mimetype!; } else { mimeType = languag...
/** * Get the mime type of the document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L81-L91
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.languageFileExtension
get languageFileExtension(): string | undefined { const languageMetadata = this.language_info(); if (!languageMetadata || !languageMetadata.file_extension) { return; } return languageMetadata.file_extension.replace('.', ''); }
/** * Get the file extension of the document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L96-L102
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.wrapperElement
get wrapperElement(): HTMLElement { // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain return this.widget.container?.current!; }
/** * Get the inner HTMLElement of the document widget. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L107-L110
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.editors
get editors(): Document.ICodeBlockOptions[] { if (this.disposed) { return []; } this._editorToCell.clear(); return this.editor.model.cells .filter((item) => EditorCellView.is(item) && item.model.mimeType === MIME.python) .map((cell) => { return { ceEditor: this.getC...
/** * Get the list of CM editor with its type in the document, */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L115-L131
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.activeEditor
get activeEditor(): Document.IEditor | undefined { return this.editor.activeCell ? this.getCellEditor(this.editor.activeCell) : undefined; }
/** * Get the activated CM editor. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L136-L140
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.ready
get ready(): Promise<void> { return this._readyDelegate.promise; }
/** * Promise that resolves once the adapter is initialized */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L145-L147
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.getEditorIndexAt
getEditorIndexAt(position: IVirtualPosition): number { const cell = this._getCellAt(position); return this.editor.model.cells.findIndex((otherCell) => { return cell === otherCell; }); }
/** * Get the index of editor from the cursor position in the virtual * document. * * @param position - the position of cursor in the virtual document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L155-L160
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.getEditorIndex
getEditorIndex(ceEditor: Document.IEditor): number { const cell = this._editorToCell.get(ceEditor)!; return this.editor.model.cells.findIndex((otherCell) => { return cell === otherCell; }); }
/** * Get the index of input editor * * @param ceEditor - instance of the code editor */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L167-L172
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.getEditorWrapper
getEditorWrapper(ceEditor: Document.IEditor): HTMLElement | undefined { const cell = this._editorToCell.get(ceEditor)!; return EditorCellView.is(cell) ? cell.editor?.host : undefined; }
/** * Get the wrapper of input editor. * * @param ceEditor - instance of the code editor */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L179-L182
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.handleCellChange
onKernelChanged = async (): Promise<void> => { try { // note: we need to wait until ready before updating language info const oldLanguageInfo = this._languageInfo; await untilReady(this.isReady, -1); await this._updateLanguageInfo(); const newLanguageInfo = this._languageInfo; if...
/** * Callback on kernel changed event, it will disconnect the * document with the language server and then reconnect. * * @param _session - Session context of changed kernel * @param change - Changed data */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.dispose
override dispose(): void { if (this.disposed) { return; } super.dispose(); // editors are needed for the parent dispose() to unbind signals, so they are the last to go this._editorToCell.clear(); }
/** * Dispose the widget. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L220-L229
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.isReady
isReady(): boolean { return ( !this.widget.isDisposed && // this.notebookModel.currentKernelStatus !== undefined && this.widget.isVisible && this.notebookModel.cells.length > 0 && this.notebookModel.kernelConnection !== null ); }
/** * Method to check if the notebook context is ready. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L234-L242
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.createVirtualDocument
createVirtualDocument(): VirtualDocument { return this.docFactory({ language: this.language, foreignCodeExtractors: this.options.foreignCodeExtractorsManager, path: this.documentPath, fileExtension: this.languageFileExtension, // notebooks are continuous, each cell is dependent on the ...
/** * Generate the virtual document associated with the document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L312-L323
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.language_info
protected language_info(): ILanguageInfoMetadata { return this._languageInfo; }
/** * Get the metadata of notebook. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L328-L330
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter._connectModelSignals
protected _connectModelSignals(notebook: LibroView) { if (notebook.model === null) { console.warn( `Model is missing for notebook ${notebook}, cannot connect cell changed signal!`, ); } else { notebook.model.onSourceChanged(this.handleCellSourceChange); notebook.model.onCellViewC...
/** * Connect the cell changed event to its handler * * @param notebook - The notebook that emitted event. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L362-L371
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter._updateLanguageInfo
protected async _updateLanguageInfo(): Promise<void> { const language_info = (await this.notebookModel.kernelConnection?.info) ?.language_info; // const language_info = (await this.widget.context.sessionContext?.session?.kernel?.info) // ?.language_info; if (language_info) { this._language...
/** * Update the stored language info with the one from the notebook. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L376-L388
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter._activeCellChanged
protected _activeCellChanged(libroModel: LibroModel | null) { if (!libroModel || libroModel.active?.model.type !== this._type) { return; } if (libroModel.active) { this._activeEditorChanged.fire({ editor: this.getCellEditor(libroModel.active)!, }); } }
/** * Handle the cell changed event * @param notebook - The notebook that emitted event * @param cell - Changed cell. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L395-L405
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter._getCellAt
protected _getCellAt(pos: IVirtualPosition): CellView { const editor = this.virtualDocument!.getEditorAtVirtualLine(pos); return this._editorToCell.get(editor)!; }
/** * Get the cell at the cursor position of the virtual document. * @param pos - Position in the virtual document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L411-L414
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
NotebookAdapter.getCellEditor
getCellEditor(cell: CellView): Document.IEditor | undefined { if (!EditorCellView.is(cell)) { return; } if (!this._cellToEditor.has(cell)) { const editor = Object.freeze({ getEditor: () => cell.editor!, ready: async () => { // await cell.ready; return cell.edi...
/** * Get the cell editor and add new ones to the mappings. * * @param cell Cell widget * @returns Cell editor accessor */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/notebook-adapter.ts#L422-L455
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
StatusMessage.changed
get changed(): Emitter<void> { return this._changed; }
/** * Signal emitted on status changed event. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/status-message.ts#L29-L31
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
StatusMessage.isDisposed
get isDisposed(): boolean { return this._isDisposed; }
/** * Test whether the object is disposed. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/status-message.ts#L36-L38
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
StatusMessage.dispose
dispose(): void { if (this.isDisposed) { return; } this._isDisposed = true; if (this._timer) { window.clearTimeout(this._timer); } }
/** * Dispose the object. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/status-message.ts#L43-L51
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
StatusMessage.message
get message(): string { return this._message; }
/** * The text message to be shown on the statusbar. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/status-message.ts#L56-L58
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
StatusMessage.set
set(message: string, timeout: number = 1000 * 3): void { this._expireTimer(); this._message = message; this._changed.fire(); if (timeout !== -1) { this._timer = window.setTimeout(this.clear.bind(this), timeout); } }
/** * Set the text message and (optionally) the timeout to remove it. * @param message * @param timeout - number of ms to until the message is cleaned; * -1 if the message should stay up indefinitely; * defaults to 3000ms (3 seconds) */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/status-message.ts#L67-L74
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
StatusMessage.clear
clear(): void { this._message = ''; this._changed.fire(); }
/** * Clear the status message. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/status-message.ts#L79-L82
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
StatusMessage._expireTimer
protected _expireTimer(): void { if (this._timer !== null) { window.clearTimeout(this._timer); this._timer = null; } }
/** * Clear the previous `setTimeout` call. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/adapters/status-message.ts#L87-L92
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CodeExtractorsManager.getExtractors
getExtractors( cellType: string, hostLanguage: string | null, ): IForeignCodeExtractor[] { if (hostLanguage) { const currentMap = this._extractorMap.get(cellType); if (!currentMap) { return []; } return currentMap.get(hostLanguage) ?? []; } else { return this._ext...
/** * Get the extractors for the input cell type and the main language of * the document * * @param cellType - type of cell * @param hostLanguage - main language of the document */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/extractors/manager.ts#L28-L41
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CodeExtractorsManager.register
register(extractor: IForeignCodeExtractor, hostLanguage: string | null): void { const cellType = extractor.cellType; if (hostLanguage) { cellType.forEach((type) => { if (!this._extractorMap.has(type)) { this._extractorMap.set(type, new Map()); } const currentMap = this._e...
/** * Register an extractor to extract foreign code from host documents of specified language. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/extractors/manager.ts#L46-L69
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
TextForeignCodeExtractor.hasForeignCode
hasForeignCode(code: string, cellType: string): boolean { return this.cellType.includes(cellType); }
/** * Test if there is any foreign code in provided code snippet. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/extractors/text-extractor.ts#L43-L45
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
TextForeignCodeExtractor.extractForeignCode
extractForeignCode(code: string): IExtractedCode[] { const lines = code.split('\n'); const extracts = new Array<IExtractedCode>(); const foreignCodeFragment = code; const start = positionAtOffset(0, lines); const end = positionAtOffset(foreignCodeFragment.length, lines); extracts.push({ ...
/** * Split the code into the host and foreign code (if any foreign code was detected) */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/extractors/text-extractor.ts#L50-L68
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocumentInfo.constructor
constructor(@inject(VirtualDocumentInfoOptions) document: VirtualDocument) { this._document = document; }
/** * Creates an instance of VirtualDocumentInfo. * @param document - the virtual document need to * be wrapped. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L120-L122
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocumentInfo.text
get text(): string { return this._document.value; }
/** * Get the text content of the virtual document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L132-L134
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocumentInfo.uri
get uri(): string { const uris = this.connectionManager.solveUris(this._document, this.languageId); if (!uris) { return ''; } return uris.document; }
/** * Get the uri of the virtual document, if the document is not available, * it returns an empty string, users need to check for the length of returned * value before using it. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L141-L147
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocumentInfo.languageId
get languageId(): string { return this._document.language; }
/** * Get the language identifier of the document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L152-L154
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.ceToCm
static ceToCm(position: CodeEditorPosition): LspPosition { return { line: position.line, ch: position.column }; }
/** * Convert from code editor position into code mirror position. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L271-L273
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.isDisposed
get isDisposed(): boolean { return this._isDisposed; }
/** * Test whether the document is disposed. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L350-L352
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.foreignDocumentClosed
get foreignDocumentClosed(): Event<Document.IForeignContext> { return this._foreignDocumentClosed.event; }
/** * Signal emitted when the foreign document is closed */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L357-L359
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.foreignDocumentOpened
get foreignDocumentOpened(): Event<Document.IForeignContext> { return this._foreignDocumentOpened.event; }
/** * Signal emitted when the foreign document is opened */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L364-L366
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.changed
get changed(): Event<VirtualDocument> { return this._changed.event; }
/** * Signal emitted when the foreign document is changed */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L371-L373
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.virtualId
get virtualId(): VirtualDocument.virtualId { // for easier debugging, the language information is included in the ID: return this.standalone ? this.instanceId + '(' + this.language + ')' : this.language; }
/** * Id of the virtual document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L378-L383
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.ancestry
get ancestry(): VirtualDocument[] { if (!this.parent) { return [this]; } return this.parent.ancestry.concat([this]); }
/** * Return the ancestry to this document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L388-L393
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.idPath
get idPath(): VirtualDocument.idPath { if (!this.parent) { return this.virtualId; } return this.parent.idPath + '-' + this.virtualId; }
/** * Return the id path to the virtual document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L398-L403
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.uri
get uri(): VirtualDocument.uri { const encodedPath = encodeURI(this.path); if (!this.parent) { return encodedPath; } return encodedPath + '.' + this.idPath + '.' + this.fileExtension; }
/** * Get the uri of the virtual document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L408-L414
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.value
get value(): string { const linesPadding = '\n'.repeat(this.blankLinesBetweenCells); return this.lineBlocks.join(linesPadding); }
/** * Get the text value of the document */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L419-L422
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.lastLine
get lastLine(): string { const linesInLastBlock = this.lineBlocks[this.lineBlocks.length - 1].split('\n'); return linesInLastBlock[linesInLastBlock.length - 1]; }
/** * Get the last line in the virtual document */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L427-L430
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.root
get root(): VirtualDocument { return this.parent ? this.parent.root : this; }
/** * Get the root document of current virtual document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L435-L437
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.dispose
dispose(): void { if (this._isDisposed) { return; } this._isDisposed = true; this.parent = null; this.closeAllForeignDocuments(); this.updateManager.dispose(); // clear all the maps this.foreignDocuments.clear(); this.sourceLines.clear(); this.unusedDocuments.clear(); ...
/** * Dispose the virtual document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L442-L466
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.clear
clear(): void { for (const document of this.foreignDocuments.values()) { document.clear(); } // TODO - deep clear (assure that there is no memory leak) this.unusedStandaloneDocuments.clear(); this.unusedDocuments = new Set(); this.virtualLines.clear(); this.sourceLines.clear(); t...
/** * Clear the virtual document and all related stuffs */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L471-L485
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.documentAtSourcePosition
documentAtSourcePosition(position: ISourcePosition): VirtualDocument { const sourceLine = this.sourceLines.get(position.line); if (!sourceLine) { return this; } const sourcePositionCe: CodeEditorPosition = { line: sourceLine.editorLine, column: position.ch, }; for (const [ ...
/** * Get the virtual document from the cursor position of the source * document * @param position - position in source document */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L492-L519
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.isWithinForeign
isWithinForeign(sourcePosition: ISourcePosition): boolean { const sourceLine = this.sourceLines.get(sourcePosition.line)!; const sourcePositionCe: CodeEditorPosition = { line: sourceLine.editorLine, column: sourcePosition.ch, }; for (const [range] of sourceLine.foreignDocumentsMap) { ...
/** * Detect if the input source position is belong to the current * virtual document. * * @param sourcePosition - position in the source document */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L527-L540
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.transformFromEditorToRoot
transformFromEditorToRoot( editor: Document.IEditor, position: IEditorPosition, ): IRootPosition | null { if (!this._editorToSourceLine.has(editor)) { console.warn('Editor not found in _editorToSourceLine map'); return null; } const shift = this._editorToSourceLine.get(editor)!; re...
/** * Compute the position in root document from the position of * a child editor. * * @param editor - the active editor. * @param position - position in the active editor. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L549-L562
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.transformEditorToVirtual
transformEditorToVirtual( editor: Document.IEditor, position: IEditorPosition, ): IVirtualPosition | null { const rootPosition = this.transformFromEditorToRoot(editor, position); if (!rootPosition) { return null; } return this.virtualPositionAtDocument(rootPosition); }
/** * Compute the position in virtual document from the position of * a child editor. * * @param editor - the active editor. * @param position - position in the active editor. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L571-L580
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.virtualPositionAtDocument
virtualPositionAtDocument(sourcePosition: ISourcePosition): IVirtualPosition { const sourceLine = this.sourceLines.get(sourcePosition.line); if (!sourceLine) { throw new Error('Source line not mapped to virtual position'); } const virtualLine = sourceLine.virtualLine; // position inside the c...
/** * Compute the position in the virtual document from the position * in the source document. * * @param sourcePosition - position in source document */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L588-L624
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.appendCodeBlock
appendCodeBlock( block: Document.ICodeBlockOptions, editorShift: CodeEditorPosition = { line: 0, column: 0 }, virtualShift?: CodeEditorPosition, ): void { const cellCode = block.value; const ceEditor = block.ceEditor; if (this.isDisposed) { console.warn('Cannot append code block: docume...
/** * Append a code block to the end of the virtual document. * * @param block - block to be appended * @param editorShift - position shift in source * document * @param [virtualShift] - position shift in * virtual document. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L635-L691
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.prepareCodeBlock
prepareCodeBlock( block: Document.ICodeBlockOptions, editorShift: CodeEditorPosition = { line: 0, column: 0 }, ): { lines: string[]; foreignDocumentsMap: Map<IRange, Document.IVirtualDocumentBlock>; } { const { cellCodeKept, foreignDocumentsMap } = this.extractForeignCode( block, edi...
/** * Extract a code block into list of string in supported language and * a map of foreign document if any. * @param block - block to be appended * @param editorShift - position shift in source document */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L699-L712
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
VirtualDocument.extractForeignCode
extractForeignCode( block: Document.ICodeBlockOptions, editorShift: CodeEditorPosition, ): { cellCodeKept: string; foreignDocumentsMap: Map<IRange, Document.IVirtualDocumentBlock>; } { const foreignDocumentsMap = new Map<IRange, Document.IVirtualDocumentBlock>(); let cellCode = block.value;...
/** * Extract the foreign code from input block by using the registered * extractors. * @param block - block to be appended * @param editorShift - position shift in source document */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L720-L788
371f9fa4903254d60ed3142e335dbf3f6d8d03e4