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 | VirtualDocument.closeForeign | closeForeign(document: VirtualDocument): void {
this._foreignDocumentClosed.fire({
foreignDocument: document,
parentHost: this,
});
// remove it from foreign documents list
this.foreignDocuments.delete(document.virtualId);
// and delete the documents within it
document.closeAllForeignDocuments();
// document.foreignDocumentClosed.disconnect(this.forwardClosedSignal, this);
// document.foreignDocumentOpened.disconnect(this.forwardOpenedSignal, this);
document.dispose();
} | /**
* Close a foreign document and disconnect all associated signals
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L793-L806 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.closeAllForeignDocuments | closeAllForeignDocuments(): void {
for (const document of this.foreignDocuments.values()) {
this.closeForeign(document);
}
} | /**
* Close all foreign documents.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L811-L815 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.closeExpiredDocuments | closeExpiredDocuments(): void {
for (const document of this.unusedDocuments.values()) {
document.remainingLifetime -= 1;
if (document.remainingLifetime <= 0) {
document.dispose();
}
}
} | /**
* Close all expired documents.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L820-L827 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.transformSourceToEditor | transformSourceToEditor(pos: ISourcePosition): IEditorPosition {
const sourceLine = this.sourceLines.get(pos.line)!;
const editorLine = sourceLine.editorLine;
const editorShift = sourceLine.editorShift;
return {
// only shift column in the line beginning the virtual document (first list of the editor in cell magics, but might be any line of editor in line magics!)
ch: pos.ch + (editorLine === 0 ? editorShift.column : 0),
line: editorLine + editorShift.line,
// TODO or:
// line: pos.line + editor_shift.line - this.first_line_of_the_block(editor)
} as IEditorPosition;
} | /**
* Transform the position of the source to the editor
* position.
*
* @param pos - position in the source document
* @return position in the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L836-L847 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.transformVirtualToEditor | transformVirtualToEditor(virtualPosition: IVirtualPosition): IEditorPosition | null {
const sourcePosition = this.transformVirtualToSource(virtualPosition);
if (!sourcePosition) {
return null;
}
return this.transformSourceToEditor(sourcePosition);
} | /**
* Transform the position in the virtual document to the
* editor position.
* Can be null because some lines are added as padding/anchors
* to the virtual document and those do not exist in the source document
* and thus they are absent in the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L856-L862 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.transformVirtualToSource | transformVirtualToSource(position: IVirtualPosition): ISourcePosition | null {
const line = this.virtualLines.get(position.line)!.sourceLine;
if (line === null) {
return null;
}
return {
ch: position.ch,
line: line,
} as ISourcePosition;
} | /**
* Transform the position in the virtual document to the source.
* Can be null because some lines are added as padding/anchors
* to the virtual document and those do not exist in the source document.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L869-L878 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.getEditorAtVirtualLine | getEditorAtVirtualLine(pos: IVirtualPosition): Document.IEditor {
let line = pos.line;
// tolerate overshot by one (the hanging blank line at the end)
if (!this.virtualLines.has(line)) {
line -= 1;
}
return this.virtualLines.get(line)!.editor;
} | /**
* Get the corresponding editor of the virtual line.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L883-L890 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.getEditorAtSourceLine | getEditorAtSourceLine(pos: ISourcePosition): Document.IEditor {
return this.sourceLines.get(pos.line)!.editor;
} | /**
* Get the corresponding editor of the source line
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L895-L897 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.maybeEmitChanged | maybeEmitChanged(): void {
if (this.value !== this.previousValue) {
this._changed.fire(this);
}
this.previousValue = this.value;
for (const document of this.foreignDocuments.values()) {
document.maybeEmitChanged();
}
} | /**
* Recursively emits changed signal from the document or any descendant foreign document.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L902-L910 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.remainingLifetime | protected get remainingLifetime(): number {
if (!this.parent) {
return Infinity;
}
return this._remainingLifetime;
} | /**
* When this counter goes down to 0, the document will be destroyed and the associated connection will be closed;
* This is meant to reduce the number of open connections when a a foreign code snippet was removed from the document.
*
* Note: top level virtual documents are currently immortal (unless killed by other means); it might be worth
* implementing culling of unused documents, but if and only if JupyterLab will also implement culling of
* idle kernels - otherwise the user experience could be a bit inconsistent, and we would need to invent our own rules.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L920-L925 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.chooseForeignDocument | protected chooseForeignDocument(extractor: IForeignCodeExtractor): VirtualDocument {
let foreignDocument: VirtualDocument;
// if not standalone, try to append to existing document
const foreignExists = this.foreignDocuments.has(extractor.language);
if (!extractor.standalone && foreignExists) {
foreignDocument = this.foreignDocuments.get(extractor.language)!;
} else {
// if (previous document does not exists) or (extractor produces standalone documents
// and no old standalone document could be reused): create a new document
foreignDocument = this.openForeign(
extractor.language,
extractor.standalone,
extractor.fileExtension,
);
}
return foreignDocument;
} | /**
* Get the foreign document that can be opened with the input extractor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L955-L971 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.openForeign | protected openForeign(
language: language,
standalone: boolean,
fileExtension: string,
): VirtualDocument {
const document = this.factory({
...this.options,
parent: this,
standalone: standalone,
fileExtension: fileExtension,
language: language,
});
const context: Document.IForeignContext = {
foreignDocument: document,
parentHost: this,
};
this._foreignDocumentOpened.fire(context);
// pass through any future signals
document.foreignDocumentClosed(() => this.forwardClosedSignal(context));
document.foreignDocumentOpened(() => this.forwardOpenedSignal(context));
this.foreignDocuments.set(document.virtualId, document);
return document;
} | /**
* Create a foreign document from input language and file extension.
*
* @param language - the required language
* @param standalone - the document type is supported natively by LSP?
* @param fileExtension - File extension.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L980-L1004 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.forwardClosedSignal | protected forwardClosedSignal(context: Document.IForeignContext) {
this._foreignDocumentClosed.fire(context);
} | /**
* Forward the closed signal from the foreign document to the host document's
* signal
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1010-L1012 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument.forwardOpenedSignal | protected forwardOpenedSignal(context: Document.IForeignContext) {
this._foreignDocumentOpened.fire(context);
} | /**
* Forward the opened signal from the foreign document to the host document's
* signal
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1018-L1020 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument._updateBeganSlot | protected _updateBeganSlot(): void {
this._editorToSourceLineNew = new Map();
} | /**
* Slot of the `updateBegan` signal.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1025-L1027 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument._blockAddedSlot | protected _blockAddedSlot(blockData: IBlockAddedInfo): void {
this._editorToSourceLineNew.set(
blockData.block.ceEditor,
blockData.virtualDocument.lastSourceLine,
);
} | /**
* Slot of the `blockAdded` signal.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1032-L1037 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | VirtualDocument._updateFinishedSlot | protected _updateFinishedSlot(): void {
this._editorToSourceLine = this._editorToSourceLineNew;
} | /**
* Slot of the `updateFinished` signal.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1042-L1044 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | UpdateManager.constructor | constructor(protected virtualDocument: VirtualDocument) {
this._blockAdded = new Emitter<IBlockAddedInfo>();
this._documentUpdated = new Emitter<VirtualDocument>();
this._updateBegan = new Emitter<Document.ICodeBlockOptions[]>();
this._updateFinished = new Emitter<Document.ICodeBlockOptions[]>();
this.documentUpdated(this._onUpdated);
} | // eslint-disable-next-line @typescript-eslint/parameter-properties, @typescript-eslint/no-parameter-properties | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1101-L1107 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | UpdateManager.updateDone | get updateDone(): Promise<void> {
return this._updateDone;
} | /**
* Promise resolved when the updating process finishes.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1112-L1114 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | UpdateManager.blockAdded | get blockAdded(): Event<IBlockAddedInfo> {
return this._blockAdded.event;
} | /**
* Signal emitted when a code block is added to the document.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1125-L1127 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | UpdateManager.documentUpdated | get documentUpdated(): Event<VirtualDocument> {
return this._documentUpdated.event;
} | /**
* Signal emitted by the editor that triggered the update,
* providing the root document of the updated documents.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1133-L1135 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | UpdateManager.updateBegan | get updateBegan(): Event<Document.ICodeBlockOptions[]> {
return this._updateBegan.event;
} | /**
* Signal emitted when the update is started
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1140-L1142 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | UpdateManager.updateFinished | get updateFinished(): Event<Document.ICodeBlockOptions[]> {
return this._updateFinished.event;
} | /**
* Signal emitted when the update is finished
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1147-L1149 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | UpdateManager.dispose | dispose(): void {
if (this._isDisposed) {
return;
}
this._isDisposed = true;
} | /**
* Dispose the class
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1154-L1159 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | UpdateManager.withUpdateLock | async withUpdateLock(fn: () => void): Promise<void> {
await untilReady(() => this._canUpdate(), 12, 10).then(() => {
try {
this._updateLock = true;
fn();
} catch (ex) {
console.error(ex);
} finally {
this._updateLock = false;
}
return;
});
} | /**
* Execute provided callback within an update-locked context, which guarantees that:
* - the previous updates must have finished before the callback call, and
* - no update will happen when executing the callback
* @param fn - the callback to execute in update lock
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1167-L1179 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | UpdateManager.updateDocuments | async updateDocuments(blocks: Document.ICodeBlockOptions[]): Promise<void> {
const update = new Promise<void>((resolve, reject) => {
// defer the update by up to 50 ms (10 retrials * 5 ms break),
// awaiting for the previous update to complete.
untilReady(() => this._canUpdate(), 10, 5)
.then(() => {
if (this.isDisposed || !this.virtualDocument) {
resolve();
}
try {
this._isUpdateInProgress = true;
this._updateBegan.fire(blocks);
this.virtualDocument.clear();
for (const codeBlock of blocks) {
this._blockAdded.fire({
block: codeBlock,
virtualDocument: this.virtualDocument,
});
this.virtualDocument.appendCodeBlock(codeBlock);
}
this._updateFinished.fire(blocks);
if (this.virtualDocument) {
this._documentUpdated.fire(this.virtualDocument);
this.virtualDocument.maybeEmitChanged();
}
resolve();
} catch (e) {
console.warn('Documents update failed:', e);
reject(e);
} finally {
this._isUpdateInProgress = false;
}
return;
})
.catch(console.error);
});
this._updateDone = update;
return update;
} | /**
* Update all the virtual documents, emit documents updated with root document if succeeded,
* and resolve a void promise. The promise does not contain the text value of the root document,
* as to avoid an easy trap of ignoring the changes in the virtual documents.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1186-L1229 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | UpdateManager._onUpdated | protected _onUpdated(rootDocument: VirtualDocument) {
try {
rootDocument.closeExpiredDocuments();
} catch (e) {
console.warn('Failed to close expired documents');
}
} | /**
* Once all the foreign documents were refreshed, the unused documents (and their connections)
* should be terminated if their lifetime has expired.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1259-L1265 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | UpdateManager._canUpdate | protected _canUpdate() {
return !this.isDisposed && !this._isUpdateInProgress && !this._updateLock;
} | /**
* Check if the document can be updated.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/virtual/document.ts#L1270-L1272 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | registerServerCapability | function registerServerCapability(
serverCapabilities: ServerCapabilities,
registration: Registration,
): ServerCapabilities | null {
const serverCapabilitiesCopy = JSON.parse(
JSON.stringify(serverCapabilities),
) as IFlexibleServerCapabilities;
const { method, registerOptions } = registration;
const providerName = method.substring(13) + 'Provider';
if (providerName) {
if (!registerOptions) {
serverCapabilitiesCopy[providerName] = true;
} else {
serverCapabilitiesCopy[providerName] = JSON.parse(
JSON.stringify(registerOptions),
);
}
} else {
console.warn('Could not register server capability.', registration);
return null;
}
return serverCapabilitiesCopy;
} | /**
* Register the capabilities with the server capabilities provider
*
* @param serverCapabilities - server capabilities provider.
* @param registration - capabilities to be registered.
* @return - the new server capabilities provider
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/server-capability-registration.ts#L29-L53 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | unregisterServerCapability | function unregisterServerCapability(
serverCapabilities: ServerCapabilities,
unregistration: Unregistration,
): ServerCapabilities {
const serverCapabilitiesCopy = JSON.parse(
JSON.stringify(serverCapabilities),
) as IFlexibleServerCapabilities;
const { method } = unregistration;
const providerName = method.substring(13) + 'Provider';
delete serverCapabilitiesCopy[providerName];
return serverCapabilitiesCopy;
} | /**
* Unregister the capabilities with the server capabilities provider
*
* @param serverCapabilities - server capabilities provider.
* @param registration - capabilities to be unregistered.
* @return - the new server capabilities provider
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/server-capability-registration.ts#L62-L75 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.isConnected | get isConnected(): boolean {
return this._isConnected;
} | /**
* Is the language server is connected?
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L35-L37 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.isInitialized | get isInitialized(): boolean {
return this._isInitialized;
} | /**
* Is the language server is initialized?
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L42-L44 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.isReady | get isReady() {
return this._isConnected && this._isInitialized;
} | /**
* Is the language server is connected and initialized?
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L49-L51 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.onDisposed | get onDisposed(): Event<void> {
return this._disposed.event;
} | /**
* A signal emitted when the connection is disposed.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L56-L58 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.isDisposed | get isDisposed(): boolean {
return this._isDisposed;
} | /**
* Check if the connection is disposed
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L63-L65 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.connect | connect(socket: WebSocket): void {
this.socket = socket;
listen({
webSocket: this.socket,
logger: new ConsoleLogger(),
onConnection: (connection: MessageConnection) => {
connection.listen();
this._isConnected = true;
this.connection = connection;
this.sendInitialize();
const registerCapabilityDisposable = this.connection.onRequest(
'client/registerCapability',
(params: protocol.RegistrationParams) => {
params.registrations.forEach(
(capabilityRegistration: protocol.Registration) => {
try {
this.serverCapabilities = registerServerCapability(
this.serverCapabilities,
capabilityRegistration,
)!;
} catch (err) {
console.error(err);
}
},
);
},
);
this._disposables.push(registerCapabilityDisposable);
const unregisterCapabilityDisposable = this.connection.onRequest(
'client/unregisterCapability',
(params: protocol.UnregistrationParams) => {
params.unregisterations.forEach(
(capabilityUnregistration: protocol.Unregistration) => {
this.serverCapabilities = unregisterServerCapability(
this.serverCapabilities,
capabilityUnregistration,
);
},
);
},
);
this._disposables.push(unregisterCapabilityDisposable);
const disposable = this.connection.onClose(() => {
this._isConnected = false;
});
this._disposables.push(disposable);
},
});
} | /**
* Initialize a connection over a web socket that speaks the LSP protocol
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L70-L122 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.close | close() {
if (this.connection) {
this.connection.dispose();
}
this.openedUris.clear();
this.socket.close();
} | /**
* Close the connection
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L127-L133 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.sendInitialize | sendInitialize() {
if (!this._isConnected) {
return;
}
this.openedUris.clear();
const message: protocol.InitializeParams = this.initializeParams();
this.connection
.sendRequest<protocol.InitializeResult>('initialize', message)
.then(
(params) => {
this.onServerInitialized(params);
return;
},
(e) => {
console.warn('LSP websocket connection initialization failure', e);
},
)
.catch(console.error);
} | /**
* The initialize request telling the server which options the client supports
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L138-L159 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.sendOpen | sendOpen(documentInfo: IDocumentInfo) {
const textDocumentMessage: protocol.DidOpenTextDocumentParams = {
textDocument: {
uri: documentInfo.uri,
languageId: documentInfo.languageId,
text: documentInfo.text,
version: documentInfo.version,
} as protocol.TextDocumentItem,
};
this.connection
.sendNotification('textDocument/didOpen', textDocumentMessage)
.catch(console.error);
this.openedUris.set(documentInfo.uri, true);
this.sendChange(documentInfo);
} | /**
* Inform the server that the document was opened
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L164-L178 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.sendChange | sendChange(documentInfo: IDocumentInfo) {
if (!this.isReady) {
return;
}
if (!this.openedUris.get(documentInfo.uri)) {
this.sendOpen(documentInfo);
return;
}
const textDocumentChange: protocol.DidChangeTextDocumentParams = {
textDocument: {
uri: documentInfo.uri,
version: documentInfo.version,
} as protocol.VersionedTextDocumentIdentifier,
contentChanges: [{ text: documentInfo.text }],
};
this.connection
.sendNotification('textDocument/didChange', textDocumentChange)
.catch(console.error);
documentInfo.version++;
} | /**
* Sends the full text of the document to the server
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L183-L202 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.sendSaved | sendSaved(documentInfo: IDocumentInfo) {
if (!this.isReady) {
return;
}
const textDocumentChange: protocol.DidSaveTextDocumentParams = {
textDocument: {
uri: documentInfo.uri,
version: documentInfo.version,
} as protocol.VersionedTextDocumentIdentifier,
text: documentInfo.text,
};
this.connection
.sendNotification('textDocument/didSave', textDocumentChange)
.catch(console.error);
} | /**
* Send save notification to the server.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L207-L222 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.sendConfigurationChange | sendConfigurationChange(settings: protocol.DidChangeConfigurationParams) {
if (!this.isReady) {
return;
}
this.connection
.sendNotification('workspace/didChangeConfiguration', settings)
.catch(console.error);
} | /**
* Send configuration change to the server.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L227-L235 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.dispose | dispose(): void {
if (this._isDisposed) {
return;
}
this._isDisposed = true;
this._disposables.forEach((disposable) => {
disposable.dispose();
});
this._disposed.fire();
} | /**
* Dispose the connection.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L240-L249 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.onServerInitialized | protected onServerInitialized(params: protocol.InitializeResult): void {
this._isInitialized = true;
this.serverCapabilities = params.capabilities;
this.connection.sendNotification('initialized', {}).catch(console.error);
this.connection
.sendNotification('workspace/didChangeConfiguration', {
settings: {},
})
.catch(console.error);
} | /**
* Callback called when the server is initialized.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L290-L299 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LspWsConnection.initializeParams | protected initializeParams(): protocol.InitializeParams {
return {
capabilities: {} as protocol.ClientCapabilities,
processId: null,
rootUri: this._rootUri,
workspaceFolders: null,
};
} | /**
* Initialization parameters to be sent to the language server.
* Subclasses should override this when adding more features.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-lsp/src/ws-connection/ws-connection.ts#L305-L312 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | convertBundle | function convertBundle(bundle: IMimeBundle): PartialJSONObject {
const map: PartialJSONObject = Object.create(null);
for (const mimeType in bundle) {
map[mimeType] = extract(bundle, mimeType);
}
return map;
} | /**
* Convert a mime bundle to mime data.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-output/src/output-utils.ts#L78-L84 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | RenderMimeRegistry.constructor | constructor(
@inject(IRenderMimeRegistryOptions) options: IRenderMimeRegistryOptions,
@inject(MarkdownParser) markdownParser: MarkdownParser,
) {
// Parse the options.
// this.translator = options.translator ?? nullTranslator;
this.resolver = options.resolver ?? null;
this.linkHandler = options.linkHandler ?? null;
this.markdownParser = options.markdownParser ?? markdownParser;
this.sanitizer = options.sanitizer ?? defaultSanitizer;
// Add the initial factories.
if (options.initialFactories) {
for (const factory of options.initialFactories) {
this.addFactory(factory);
}
}
} | /**
* Construct a new rendermime.
*
* @param options - The options for initializing the instance.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-registry.ts#L43-L60 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | RenderMimeRegistry.mimeTypes | get mimeTypes(): readonly string[] {
return this._types || (this._types = sortedTypes(this._ranks));
} | /**
* The ordered list of mimeTypes.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-registry.ts#L93-L95 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | RenderMimeRegistry.preferredMimeType | preferredMimeType(
model: BaseOutputView,
// safe: 'ensure' | 'prefer' | 'any' = 'ensure',
): string | undefined {
// // Try to find a safe factory first, if preferred.
// if (safe === 'ensure' || safe === 'prefer') {
// for (const mt of this.mimeTypes) {
// if (mt in bundle && this._factories[mt].safe) {
// return mt;
// }
// }
// }
// if (safe !== 'ensure') {
// // Otherwise, search for the best factory among all factories.
// for (const mt of this.mimeTypes) {
// if (mt in bundle) {
// return mt;
// }
// }
// }
const sortedRenderMimes = this.getSortedRenderMimes(model);
for (const renderMime of sortedRenderMimes) {
for (const mt of renderMime.mimeTypes) {
if (mt in model.data) {
return mt;
}
}
}
for (const mt of this.mimeTypes) {
if (mt in model.data) {
return mt;
}
}
// Otherwise, no matching mime type exists.
return undefined;
} | /**
* Find the preferred mime type for a mime bundle.
*
* @param bundle - The bundle of mime data.
*
* @param safe - How to consider safe/unsafe factories. If 'ensure',
* it will only consider safe factories. If 'any', any factory will be
* considered. If 'prefer', unsafe factories will be considered, but
* only after the safe options have been exhausted.
*
* @returns The preferred mime type from the available factories,
* or `undefined` if the mime type cannot be rendered.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-registry.ts#L133-L172 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | RenderMimeRegistry.createRenderer | createRenderer(
mimeType: string,
model: BaseOutputView, // model: BaseOutputModel,
// host: HTMLElement,
): IRendererFactory {
const renderMimes = this.getSortedRenderMimes(model);
for (const renderMime of renderMimes) {
for (const mt of renderMime.mimeTypes) {
if (mimeType === mt) {
this.renderMimeEmitter.fire({
renderType: renderMime.renderType,
mimeType,
});
return renderMime;
}
}
}
// Throw an error if no factory exists for the mime type.
if (!(mimeType in this._factories)) {
throw new Error(`No factory for mime type: '${mimeType}'`);
}
const renderMime = this._factories[mimeType];
this.renderMimeEmitter.fire({
renderType: this._factories[mimeType].renderType,
mimeType,
});
// Invoke the best factory for the given mime type.
return renderMime;
} | /**
* Create a renderer for a mime type.
*
* @param mimeType - The mime type of interest.
*
* @returns A new renderer for the given mime type.
*
* @throws An error if no factory exists for the mime type.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-registry.ts#L183-L212 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | RenderMimeRegistry.getFactory | getFactory(mimeType: string): IRendererFactory | undefined {
return this._factories[mimeType];
} | /**
* Get the renderer factory registered for a mime type.
*
* @param mimeType - The mime type of interest.
*
* @returns The factory for the mime type, or `undefined`.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-registry.ts#L221-L223 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | RenderMimeRegistry.addFactory | addFactory(factory: IRendererFactory, _rank?: number): void {
let rank = _rank;
if (rank === undefined) {
rank = factory.defaultRank;
if (rank === undefined) {
rank = 100;
}
}
for (const mt of factory.mimeTypes) {
this._factories[mt] = factory;
this._ranks[mt] = { rank, id: this._id++ };
}
this._types = null;
} | /**
* Add a renderer factory to the rendermime.
*
* @param factory - The renderer factory of interest.
*
* @param _rank - The rank of the renderer. A lower rank indicates
* a higher priority for rendering. If not given, the rank will
* defer to the `defaultRank` of the factory. If no `defaultRank`
* is given, it will default to 100.
*
* #### Notes
* The renderer will replace an existing renderer for the given
* mimeType.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-registry.ts#L239-L252 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | RenderMimeRegistry.removeMimeType | removeMimeType(mimeType: string): void {
delete this._factories[mimeType];
delete this._ranks[mimeType];
this._types = null;
} | /**
* Remove a mime type.
*
* @param mimeType - The mime type of interest.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-registry.ts#L259-L263 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | RenderMimeRegistry.getRank | getRank(mimeType: string): number | undefined {
const rank = this._ranks[mimeType];
return rank && rank.rank;
} | /**
* Get the rank for a given mime type.
*
* @param mimeType - The mime type of interest.
*
* @returns The rank of the mime type or undefined.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-registry.ts#L272-L275 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | RenderMimeRegistry.setRank | setRank(mimeType: string, rank: number): void {
if (!this._ranks[mimeType]) {
return;
}
const id = this._id++;
this._ranks[mimeType] = { rank, id };
this._types = null;
} | /**
* Set the rank of a given mime type.
*
* @param mimeType - The mime type of interest.
*
* @param rank - The new rank to assign.
*
* #### Notes
* This is a no-op if the mime type is not registered.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-registry.ts#L287-L294 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | convertBundle | function convertBundle(bundle: IMimeBundle): PartialJSONObject {
const map: PartialJSONObject = Object.create(null);
for (const mimeType in bundle) {
map[mimeType] = extract(bundle, mimeType);
}
return map;
} | /**
* Convert a mime bundle to mime data.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-utils.ts#L63-L69 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | pushColoredChunk | function pushColoredChunk(
chunk: string,
fg: number | number[],
bg: number | number[],
bold: boolean,
underline: boolean,
inverse: boolean,
out: string[],
): void {
let _fg = fg;
let _bg = bg;
if (chunk) {
const classes = [];
const styles = [];
if (bold && typeof _fg === 'number' && 0 <= _fg && _fg < 8) {
_fg += 8; // Bold text uses "intense" colors
}
if (inverse) {
[_fg, _bg] = [_bg, _fg];
}
if (typeof _fg === 'number') {
classes.push(ANSI_COLORS[_fg] + '-fg');
} else if (_fg.length) {
styles.push(`color: rgb(${_fg})`);
} else if (inverse) {
classes.push('ansi-default-inverse-fg');
}
if (typeof _bg === 'number') {
classes.push(ANSI_COLORS[_bg] + '-bg');
} else if (_bg.length) {
styles.push(`background-color: rgb(${_bg})`);
} else if (inverse) {
classes.push('ansi-default-inverse-bg');
}
if (bold) {
classes.push('ansi-bold');
}
if (underline) {
classes.push('ansi-underline');
}
if (classes.length || styles.length) {
out.push('<span');
if (classes.length) {
out.push(` class="${classes.join(' ')}"`);
}
if (styles.length) {
out.push(` style="${styles.join('; ')}"`);
}
out.push('>');
out.push(chunk);
out.push('</span>');
} else {
out.push(chunk);
}
}
} | /**
* Create HTML tags for a string with given foreground, background etc. and
* add them to the `out` array.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-utils.ts#L94-L155 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | getExtendedColors | function getExtendedColors(numbers: number[]): number | number[] {
let r;
let g;
let b;
const n = numbers.shift();
if (n === 2 && numbers.length >= 3) {
// 24-bit RGB
r = numbers.shift()!;
g = numbers.shift()!;
b = numbers.shift()!;
if ([r, g, b].some((c) => c < 0 || 255 < c)) {
throw new RangeError('Invalid range for RGB colors');
}
} else if (n === 5 && numbers.length >= 1) {
// 256 colors
const idx = numbers.shift()!;
if (idx < 0) {
throw new RangeError('Color index must be >= 0');
} else if (idx < 16) {
// 16 default terminal colors
return idx;
} else if (idx < 232) {
// 6x6x6 color cube, see https://stackoverflow.com/a/27165165/500098
r = Math.floor((idx - 16) / 36);
r = r > 0 ? 55 + r * 40 : 0;
g = Math.floor(((idx - 16) % 36) / 6);
g = g > 0 ? 55 + g * 40 : 0;
b = (idx - 16) % 6;
b = b > 0 ? 55 + b * 40 : 0;
} else if (idx < 256) {
// grayscale, see https://stackoverflow.com/a/27165165/500098
r = g = b = (idx - 232) * 10 + 8;
} else {
throw new RangeError('Color index must be < 256');
}
} else {
throw new RangeError('Invalid extended color specification');
}
return [r, g, b];
} | /**
* Convert ANSI extended colors to R/G/B triple.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-utils.ts#L160-L199 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | handleAttr | async function handleAttr(
node: HTMLElement,
name: 'src' | 'href',
resolver: IResolver,
): Promise<void> {
const source = node.getAttribute(name) || '';
const isLocal = resolver.isLocal ? resolver.isLocal(source) : URL.isLocal(source);
if (!source || !isLocal) {
return;
}
try {
const urlPath = await resolver.resolveUrl(source);
let url = await resolver.getDownloadUrl(urlPath);
if (new URI(url).scheme !== 'data:') {
// Bust caching for local src attrs.
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache
url += (/\?/.test(url) ? '&' : '?') + new Date().getTime();
}
node.setAttribute(name, url);
} catch (err) {
// If there was an error getting the url,
// just make it an empty link and report the error.
node.setAttribute(name, '');
throw err;
}
} | /**
* Handle a node with a `src` or `href` attribute.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-utils.ts#L551-L576 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | handleAnchor | function handleAnchor(
anchor: HTMLAnchorElement,
resolver: IResolver,
linkHandler: ILinkHandler | null,
): Promise<void> {
// Get the link path without the location prepended.
// (e.g. "./foo.md#Header 1" vs "http://localhost:8888/foo.md#Header 1")
let href = anchor.getAttribute('href') || '';
const isLocal = resolver.isLocal ? resolver.isLocal(href) : URL.isLocal(href);
// Bail if it is not a file-like url.
if (!href || !isLocal) {
return Promise.resolve(undefined);
}
// Remove the hash until we can handle it.
const hash = anchor.hash;
if (hash) {
// Handle internal link in the file.
if (hash === href) {
anchor.target = '_self';
return Promise.resolve(undefined);
}
// For external links, remove the hash until we have hash handling.
href = href.replace(hash, '');
}
// Get the appropriate file path.
return resolver
.resolveUrl(href)
.then((urlPath) => {
// decode encoded url from url to api path
const path = decodeURIComponent(urlPath);
// Handle the click override.
if (linkHandler) {
linkHandler.handleLink(anchor, path, hash);
}
// Get the appropriate file download path.
return resolver.getDownloadUrl(urlPath);
})
.then((url) => {
// Set the visible anchor.
anchor.href = url + hash;
return;
})
.catch(() => {
// If there was an error getting the url,
// just make it an empty link.
anchor.href = '';
});
} | /**
* Handle an anchor node.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-rendermime/src/rendermime-utils.ts#L581-L628 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeCellSearchProviderContribution.getInitialQuery | getInitialQuery = (cell: CellView): string => {
if (cell instanceof LibroCodeCellView) {
const selection = cell.editor?.getSelectionValue();
// if there are newlines, just return empty string
return selection?.search(/\r?\n|\r/g) === -1 ? selection : '';
}
return '';
} | /**
* Get an initial query value if applicable so that it can be entered
* into the search box as an initial query
*
* @returns Initial value used to populate the search box.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-cell-search-provider-contribution.ts | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeCellSearchProvider.constructor | constructor(
@inject(CodeEditorSearchHighlighterFactory)
highlighterFactory: CodeEditorSearchHighlighterFactory,
@inject(GenericSearchProviderFactory)
genericSearchProviderFactory: GenericSearchProviderFactory,
@inject(CodeCellSearchOption) option: CodeCellSearchOption,
) {
super(highlighterFactory, option.cell);
this.genericSearchProviderFactory = genericSearchProviderFactory;
this.currentProviderIndex = -1;
this.outputsProvider = [];
this.setupOutputProvider();
this.toDispose.push(
this.cell.outputArea.onUpdate(() => {
this.setupOutputProvider();
}),
);
this.toDispose.push(
watch(this.cell.model, 'hasOutputHidden', async () => {
await this.refresh();
}),
);
this.toDispose.push(
watch(this.cell, 'hasInputHidden', async () => {
await this.refresh();
}),
);
} | /**
* Constructor
*
* @param cell Cell widget
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-cell-search-provider.ts#L24-L52 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeCellSearchProvider.matchesCount | override get matchesCount(): number {
if (!this.isActive) {
return 0;
}
return (
super.matchesCount +
this.outputsProvider.reduce(
(sum, provider) => sum + (provider.matchesCount ?? 0),
0,
)
);
} | /**
* Number of matches in the cell.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-cell-search-provider.ts#L57-L69 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeCellSearchProvider.clearHighlight | override async clearHighlight(): Promise<void> {
await super.clearHighlight();
await Promise.all(
this.outputsProvider.map((provider) => provider.clearHighlight()),
);
} | /**
* Clear currently highlighted match.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-cell-search-provider.ts#L74-L79 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeCellSearchProvider.dispose | override dispose(): void {
if (this.isDisposed) {
return;
}
super.dispose();
this.outputsProvider.map((provider) => {
provider.dispose();
});
this.outputsProvider.length = 0;
} | /**
* Dispose the search provider
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-cell-search-provider.ts#L84-L93 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeCellSearchProvider.highlightNext | override async highlightNext(): Promise<SearchMatch | undefined> {
if (this.matchesCount === 0 || !this.isActive) {
this.currentIndex = undefined;
} else {
if (this.currentProviderIndex === -1) {
const match = await super.highlightNext();
if (match) {
this.currentIndex = this.editorHighlighter.currentIndex;
return match;
} else {
this.currentProviderIndex = 0;
}
}
while (this.currentProviderIndex < this.outputsProvider.length) {
const provider = this.outputsProvider[this.currentProviderIndex];
const match = await provider.highlightNext(false);
if (match) {
this.currentIndex =
super.matchesCount +
this.outputsProvider
.slice(0, this.currentProviderIndex)
.reduce((sum, p) => (sum += p.matchesCount ?? 0), 0) +
provider.currentMatchIndex!;
return match;
} else {
this.currentProviderIndex += 1;
}
}
this.currentProviderIndex = -1;
this.currentIndex = undefined;
return undefined;
}
return;
} | /**
* Highlight the next match.
*
* @returns The next match if there is one.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-cell-search-provider.ts#L100-L135 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeCellSearchProvider.highlightPrevious | override async highlightPrevious(): Promise<SearchMatch | undefined> {
if (this.matchesCount === 0 || !this.isActive) {
this.currentIndex = undefined;
} else {
if (this.currentIndex === undefined) {
this.currentProviderIndex = this.outputsProvider.length - 1;
}
while (this.currentProviderIndex >= 0) {
const provider = this.outputsProvider[this.currentProviderIndex];
const match = await provider.highlightPrevious(false);
if (match) {
this.currentIndex =
super.matchesCount +
this.outputsProvider
.slice(0, this.currentProviderIndex)
.reduce((sum, p) => (sum += p.matchesCount ?? 0), 0) +
provider.currentMatchIndex!;
return match;
} else {
this.currentProviderIndex -= 1;
}
}
const match = await super.highlightPrevious();
if (match) {
this.currentIndex = this.editorHighlighter.currentIndex;
return match;
} else {
this.currentIndex = undefined;
return undefined;
}
}
return;
} | /**
* Highlight the previous match.
*
* @returns The previous match if there is one.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-cell-search-provider.ts#L142-L177 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeCellSearchProvider.startQuery | override async startQuery(
query: RegExp | null,
filters?: SearchFilters,
): Promise<void> {
await super.startQuery(query, filters);
// Search outputs
if (filters?.searchCellOutput) {
await Promise.all(
this.outputsProvider.map((provider) => {
provider.startQuery(query, this.filters);
}),
);
}
} | /**
* Initialize the search using the provided options. Should update the UI to highlight
* all matches and "select" the first match.
*
* @param query A RegExp to be use to perform the search
* @param filters Filter parameters to pass to provider
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-cell-search-provider.ts#L186-L199 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.constructor | constructor(
@inject(CodeEditorSearchHighlighterFactory)
highlighterFactory: CodeEditorSearchHighlighterFactory,
cell: LibroCodeCellView,
) {
this.cell = cell;
this.highlighterFactory = highlighterFactory;
this.currentIndex = undefined;
this.stateChangedEmitter = new Emitter<void>();
this.toDispose.push(this.stateChangedEmitter);
this.editorHighlighter = this.highlighterFactory(this.cell.editor);
this.toDispose.push(watch(this.cell.model, 'value', this.updateMatches));
this.toDispose.push(
this.cell.editorView?.onEditorStatusChange((e) => {
if (e.status === 'ready') {
const editor = this.cell.editorView?.editor;
if (editor) {
this.editorHighlighter.setEditor(editor);
}
if (e.prevState === 'init') {
if (this.cell.hasInputHidden === true) {
this.endQuery();
} else {
this.startQuery(this.query, this.filters);
}
}
}
}) ?? Disposable.NONE,
);
} | /**
* Constructor
*
* @param cell Cell widget
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L48-L78 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.getInitialQuery | getInitialQuery(): string {
const selection = this.cell?.editor?.getSelectionValue();
// if there are newlines, just return empty string
return selection?.search(/\r?\n|\r/g) === -1 ? selection : '';
} | /**
* Get an initial query value if applicable so that it can be entered
* into the search box as an initial query
*
* @returns Initial value used to populate the search box.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L86-L90 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.stateChanged | get stateChanged(): Event<void> {
return this.stateChangedEmitter.event;
} | /**
* Changed signal to be emitted when search matches change.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L105-L107 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.currentMatchIndex | get currentMatchIndex(): number | undefined {
return this.isActive ? this.currentIndex : undefined;
} | /**
* Current match index
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L112-L114 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.isActive | get isActive(): boolean {
return this._isActive;
} | /**
* Whether the cell search is active.
*
* This is used when applying search only on selected cells.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L121-L123 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.isDisposed | get isDisposed(): boolean {
return this._isDisposed;
} | /**
* Whether the search provider is disposed or not.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L128-L130 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.matchesCount | get matchesCount(): number {
return this.isActive ? this.editorHighlighter.matches.length : 0;
} | /**
* Number of matches in the cell.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L135-L137 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.clearHighlight | clearHighlight(): Promise<void> {
this.currentIndex = undefined;
this.editorHighlighter.clearHighlight();
return Promise.resolve();
} | /**
* Clear currently highlighted match
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L146-L151 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.dispose | dispose(): void {
if (this.isDisposed) {
return;
}
this.toDispose.dispose();
this._isDisposed = true;
if (this.isActive) {
this.endQuery().catch((reason) => {
console.error(`Failed to end search query on cells.`, reason);
});
}
} | /**
* Dispose the search provider
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L156-L167 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.setIsActive | async setIsActive(v: boolean): Promise<void> {
if (this.isActive !== v) {
this._isActive = v;
}
if (this.isActive) {
if (this.query !== null) {
await this.startQuery(this.query, this.filters);
}
} else {
await this.endQuery();
}
} | /**
* Set `isActive` status.
*
* #### Notes
* It will start or end the search
*
* @param v New value
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L177-L188 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.startQuery | async startQuery(query: RegExp | null, filters?: SearchFilters): Promise<void> {
this.query = query;
this.filters = filters;
if (this.cell.hasInputHidden) {
return;
}
await this.setEditor();
// Search input
await this.updateMatches();
} | /**
* Initialize the search using the provided options. Should update the UI
* to highlight all matches and "select" the first match.
*
* @param query A RegExp to be use to perform the search
* @param filters Filter parameters to pass to provider
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L197-L206 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.endQuery | async endQuery(): Promise<void> {
this.currentIndex = undefined;
this.query = null;
await this.editorHighlighter.endQuery();
} | /**
* Stop the search and clean any UI elements.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L211-L215 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.highlightNext | async highlightNext(): Promise<SearchMatch | undefined> {
if (this.matchesCount === 0 || !this.isActive) {
this.currentIndex = undefined;
} else {
if (this.lastReplacementPosition) {
this.cell.editor?.setCursorPosition(this.lastReplacementPosition);
this.lastReplacementPosition = null;
}
// This starts from the cursor position
const match = await this.editorHighlighter.highlightNext();
if (match) {
this.currentIndex = this.editorHighlighter.currentIndex;
} else {
this.currentIndex = undefined;
}
return match;
}
return Promise.resolve(this.getCurrentMatch());
} | /**
* Highlight the next match.
*
* @returns The next match if there is one.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L222-L243 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.highlightPrevious | async highlightPrevious(): Promise<SearchMatch | undefined> {
if (this.matchesCount === 0 || !this.isActive) {
this.currentIndex = undefined;
} else {
// This starts from the cursor position
const match = await this.editorHighlighter.highlightPrevious();
if (match) {
this.currentIndex = this.editorHighlighter.currentIndex;
} else {
this.currentIndex = undefined;
}
return match;
}
return Promise.resolve(this.getCurrentMatch());
} | /**
* Highlight the previous match.
*
* @returns The previous match if there is one.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L250-L265 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.replaceCurrentMatch | replaceCurrentMatch(newText: string): Promise<boolean> {
if (!this.isActive) {
return Promise.resolve(false);
}
let occurred = false;
if (
this.currentIndex !== undefined &&
this.currentIndex < this.editorHighlighter.matches.length
) {
const editor = this.cell.editor;
const selection = editor?.getSelectionValue();
const match = this.getCurrentMatch();
if (!match) {
return Promise.resolve(occurred);
}
// If cursor is not on a selection, highlight the next match
if (selection !== match?.text) {
this.currentIndex = undefined;
// The next will be highlighted as a consequence of this returning false
} else {
this.editorHighlighter.matches.splice(this.currentIndex, 1);
this.currentIndex = undefined;
// Store the current position to highlight properly the next search hit
this.lastReplacementPosition = editor?.getCursorPosition() ?? null;
editor?.replaceSelection(newText, {
start: editor.getPositionAt(match.position)!,
end: editor.getPositionAt(match.position + match.text.length)!,
});
occurred = true;
}
}
return Promise.resolve(occurred);
} | /**
* Replace the currently selected match with the provided text.
*
* If no match is selected, it won't do anything.
*
* @param newText The replacement text.
* @returns Whether a replace occurred.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L275-L309 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.replaceAllMatches | replaceAllMatches = (newText: string): Promise<boolean> => {
if (!this.isActive) {
return Promise.resolve(false);
}
const occurred = this.editorHighlighter.matches.length > 0;
// const src = this.cell.model.value;
// let lastEnd = 0;
// const finalSrc = this.cmHandler.matches.reduce((agg, match) => {
// const start = match.position as number;
// const end = start + match.text.length;
// const newStep = `${agg}${src.slice(lastEnd, start)}${newText}`;
// lastEnd = end;
// return newStep;
// }, '');
const editor = this.cell.editor;
if (occurred && editor) {
const changes = this.editorHighlighter.matches.map((match) => ({
range: {
start: editor.getPositionAt(match.position)!,
end: editor.getPositionAt(match.position + match.text.length)!,
},
text: newText,
}));
editor?.replaceSelections(changes);
this.editorHighlighter.matches = [];
this.currentIndex = undefined;
// this.cell.model.setSource(`${finalSrc}${src.slice(lastEnd)}`);
}
return Promise.resolve(occurred);
} | /**
* Replace all matches in the cell source with the provided text
*
* @param newText The replacement text.
* @returns Whether a replace occurred.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorCellSearchProvider.getCurrentMatch | protected getCurrentMatch(): SearchMatch | undefined {
if (this.currentIndex === undefined) {
return undefined;
} else {
let match: SearchMatch | undefined = undefined;
if (this.currentIndex < this.editorHighlighter.matches.length) {
match = this.editorHighlighter.matches[this.currentIndex];
}
return match;
}
} | /**
* Get the current match if it exists.
*
* @returns The current match
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/code-editor-cell-search-provider.ts#L355-L365 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchHighlighter.matches | get matches(): SearchMatch[] {
return this._matches;
} | /**
* The list of matches
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/search-highlighter.ts#L27-L29 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchHighlighter.constructor | constructor() {
this._matches = new Array<SearchMatch>();
this.currentIndex = undefined;
} | /**
* Constructor
*
* @param editor The CodeMirror editor
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/search-highlighter.ts#L50-L53 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchHighlighter.clearHighlight | clearHighlight(): void {
this.currentIndex = undefined;
this._highlightCurrentMatch();
} | /**
* Clear all highlighted matches
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/search-highlighter.ts#L58-L61 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchHighlighter.endQuery | endQuery(): Promise<void> {
this._currentIndex = undefined;
this._matches = [];
if (this.editor) {
this.editor.highlightMatches([], undefined);
const selection = this.editor.getSelection();
const start = this.editor.getOffsetAt(selection.start);
const end = this.editor.getOffsetAt(selection.end);
// Setting a reverse selection to allow search-as-you-type to maintain the
// current selected match. See comment in _findNext for more details.
if (start !== end) {
this.editor.setSelection(selection);
}
}
return Promise.resolve();
} | /**
* Clear the highlighted matches.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/search-highlighter.ts#L66-L86 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchHighlighter.highlightNext | highlightNext(): Promise<SearchMatch | undefined> {
this.currentIndex = this._findNext(false);
this._highlightCurrentMatch();
return Promise.resolve(
this.currentIndex !== undefined ? this._matches[this.currentIndex] : undefined,
);
} | /**
* Highlight the next match
*
* @returns The next match if available
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/search-highlighter.ts#L93-L99 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchHighlighter.highlightPrevious | highlightPrevious(): Promise<SearchMatch | undefined> {
this.currentIndex = this._findNext(true);
this._highlightCurrentMatch();
return Promise.resolve(
this.currentIndex !== undefined ? this._matches[this.currentIndex] : undefined,
);
} | /**
* Highlight the previous match
*
* @returns The previous match if available
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/search-highlighter.ts#L106-L112 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchHighlighter.setEditor | setEditor(editor: IEditor): void {
this.editor = editor;
this.refresh();
if (this.currentIndex !== undefined) {
this._highlightCurrentMatch();
}
} | /**
* Set the editor
*
* @param editor Editor
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search-code-cell/src/search-highlighter.ts#L119-L125 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchProvider.isApplicable | static isApplicable(domain: View): boolean {
return !!domain.container?.current;
} | /**
* Report whether or not this provider has the ability to search on the given object
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search/src/libro-search-generic-provider.ts#L35-L37 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchProvider.currentMatchIndex | override get currentMatchIndex(): number | undefined {
return this._currentMatchIndex >= 0 ? this._currentMatchIndex : undefined;
} | /**
* The current index of the selected match.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search/src/libro-search-generic-provider.ts#L42-L44 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchProvider.currentMatch | get currentMatch(): HTMLSearchMatch | undefined {
return this._matches[this._currentMatchIndex] ?? undefined;
} | /**
* The current match
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search/src/libro-search-generic-provider.ts#L49-L51 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchProvider.matches | get matches(): HTMLSearchMatch[] {
// Ensure that no other fn can overwrite matches index property
// We shallow clone each node
return this._matches
? this._matches.map((m) => Object.assign({}, m))
: this._matches;
} | /**
* The current matches
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search/src/libro-search-generic-provider.ts#L56-L62 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchProvider.matchesCount | override get matchesCount(): number | undefined {
return this._matches.length;
} | /**
* The number of matches.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search/src/libro-search-generic-provider.ts#L67-L69 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchProvider.clearHighlight | clearHighlight(): Promise<void> {
if (this._currentMatchIndex >= 0) {
const hit = this._markNodes[this._currentMatchIndex];
hit.classList.remove(...LIBRO_SEARCH_SELECTED_CLASSES);
}
this._currentMatchIndex = -1;
return Promise.resolve();
} | /**
* Clear currently highlighted match.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search/src/libro-search-generic-provider.ts#L84-L92 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchProvider.dispose | override dispose(): void {
if (this.isDisposed) {
return;
}
this.endQuery().catch((reason) => {
console.error(`Failed to end search query.`, reason);
});
super.dispose();
} | /**
* Dispose of the resources held by the search provider.
*
* #### Notes
* If the object's `dispose` method is called more than once, all
* calls made after the first will be a no-op.
*
* #### Undefined Behavior
* It is undefined behavior to use any functionality of the object
* after it has been disposed unless otherwise explicitly noted.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search/src/libro-search-generic-provider.ts#L105-L114 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | GenericSearchProvider.highlightNext | async highlightNext(loop?: boolean): Promise<HTMLSearchMatch | undefined> {
return this._highlightNext(false, loop ?? true) ?? undefined;
} | /**
* Move the current match indicator to the next match.
*
* @param loop Whether to loop within the matches list.
*
* @returns A promise that resolves once the action has completed.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-search/src/libro-search-generic-provider.ts#L123-L125 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.