Skip to content

Commit

Permalink
fix: fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanba committed Jan 30, 2024
1 parent 001dd4e commit 398506e
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 60 deletions.
3 changes: 2 additions & 1 deletion packages/libro-language-client/src/common/codeConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import type {
TextDocumentWillSaveEvent,
TextEdit,
Uri,
SymbolInformation as VSymbolInformation,
} from 'vscode';

import ProtocolCallHierarchyItem from './protocolCallHierarchyItem.js';
Expand Down Expand Up @@ -237,7 +238,7 @@ export interface Converter {

asTypeHierarchyItem(value: TypeHierarchyItem): proto.TypeHierarchyItem;

asWorkspaceSymbol(item: SymbolInformation): proto.WorkspaceSymbol;
asWorkspaceSymbol(item: VSymbolInformation): proto.WorkspaceSymbol;

asInlayHint(value: InlayHint): proto.InlayHint;

Expand Down
20 changes: 10 additions & 10 deletions packages/libro-language-client/src/common/documentSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import type {
TextDocument,
Disposable,
CancellationToken,
ProviderResult,
DocumentSymbolProvider,
DocumentSymbolProviderMetadata,
SymbolInformation as VSymbolInformation,
DocumentSymbol as VDocumentSymbol,
} from 'vscode';
import type {
ClientCapabilities,
DocumentSelector,
Expand All @@ -27,6 +17,16 @@ import {
SymbolKind,
SymbolTag,
} from '@difizen/vscode-languageserver-protocol';
import type {
TextDocument,
Disposable,
CancellationToken,
ProviderResult,
DocumentSymbolProvider,
DocumentSymbolProviderMetadata,
SymbolInformation as VSymbolInformation,
DocumentSymbol as VDocumentSymbol,
} from 'vscode';

import type { FeatureClient } from './features.js';
import { ensure, TextDocumentLanguageFeature } from './features.js';
Expand Down
22 changes: 12 additions & 10 deletions packages/libro-language-client/src/common/protocolConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import type {
TypeHierarchyItem,
WorkspaceEditEntryMetadata,
TextDocument,
MarkdownString as VMarkdownString,
SemanticTokens as VSemanticTokens,
} from 'vscode';
import { URI } from 'vscode-uri';

Expand Down Expand Up @@ -72,14 +74,14 @@ import {
FoldingRange,
FoldingRangeKind,
SelectionRange,
SemanticTokens,
SemanticTokensEdit,
SemanticTokensEdits,
CallHierarchyOutgoingCall,
InlineSuggestion as InlineCompletionItem,
InlineSuggestionList as InlineCompletionList,
LinkedEditingRanges,
MarkdownString,
SemanticTokens,
LinkedEditingRanges,
} from './vscodeAdaptor/vscodeAdaptor.js';
import {
DiagnosticRelatedInformation,
Expand Down Expand Up @@ -479,11 +481,11 @@ export interface Converter {
asSemanticTokens(
value: ls.SemanticTokens,
token?: CancellationToken,
): Promise<SemanticTokens>;
): Promise<VSemanticTokens>;
asSemanticTokens(
value: ls.SemanticTokens | undefined | null,
token?: CancellationToken,
): Promise<SemanticTokens | undefined>;
): Promise<VSemanticTokens | undefined>;

asSemanticTokensEdit(value: ls.SemanticTokensEdit): SemanticTokensEdit;

Expand Down Expand Up @@ -821,14 +823,14 @@ export function createConverter(

function asHoverContent(
value: ls.MarkedString | ls.MarkedString[] | ls.MarkupContent,
): MarkdownString | MarkdownString[] {
): VMarkdownString | VMarkdownString[] {
if (Is.string(value)) {
return asMarkdownString(value);
} else if (CodeBlock.is(value)) {
const result = asMarkdownString();
return result.appendCodeblock(value.value, value.language);
} else if (Array.isArray(value)) {
const result: MarkdownString[] = [];
const result: VMarkdownString[] = [];
for (const element of value) {
const item = asMarkdownString();
if (CodeBlock.is(element)) {
Expand All @@ -844,7 +846,7 @@ export function createConverter(
}
}

function asDocumentation(value: string | ls.MarkupContent): string | MarkdownString {
function asDocumentation(value: string | ls.MarkupContent): string | VMarkdownString {
if (Is.string(value)) {
return value;
} else {
Expand All @@ -859,7 +861,7 @@ export function createConverter(
}
}

function asMarkdownString(value?: string | ls.MarkupContent): MarkdownString {
function asMarkdownString(value?: string | ls.MarkupContent): VMarkdownString {
let result: MarkdownString;
if (value === undefined || typeof value === 'string') {
result = new MarkdownString(value);
Expand Down Expand Up @@ -2156,7 +2158,7 @@ export function createConverter(
return result;
}

function asTooltip(value: string | ls.MarkupContent): string | MarkdownString {
function asTooltip(value: string | ls.MarkupContent): string | VMarkdownString {
if (typeof value === 'string') {
return value;
}
Expand Down Expand Up @@ -2514,7 +2516,7 @@ export function createConverter(
if (typeof item.insertText === 'string') {
insertText = item.insertText;
} else {
insertText = new SnippetString(item.insertText.value);
insertText = new SnippetString(item.insertText.value).value;
}

let command: Command | undefined = undefined;
Expand Down
14 changes: 8 additions & 6 deletions packages/libro-language-client/src/common/semanticTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import {
SemanticTokensRegistrationType,
} from '@difizen/vscode-languageserver-protocol';
import type {
SemanticTokens as VSemanticTokens,
CancellationToken,
DocumentRangeSemanticTokensProvider,
DocumentSemanticTokensProvider,
ProviderResult,
SemanticTokensEdits,
TextDocument,
SemanticTokensLegend,
Range,
} from 'vscode';

import type { FeatureClient } from './features.js';
Expand All @@ -44,7 +46,7 @@ export interface DocumentSemanticsTokensSignature {
this: void,
document: TextDocument,
token: CancellationToken,
): ProviderResult<SemanticTokens>;
): ProviderResult<VSemanticTokens>;
}

export interface DocumentSemanticsTokensEditsSignature {
Expand All @@ -53,7 +55,7 @@ export interface DocumentSemanticsTokensEditsSignature {
document: TextDocument,
previousResultId: string,
token: CancellationToken,
): ProviderResult<SemanticTokensEdits | SemanticTokens>;
): ProviderResult<SemanticTokensEdits | VSemanticTokens>;
}

export interface DocumentRangeSemanticTokensSignature {
Expand All @@ -62,7 +64,7 @@ export interface DocumentRangeSemanticTokensSignature {
document: TextDocument,
range: Range,
token: CancellationToken,
): ProviderResult<SemanticTokens>;
): ProviderResult<VSemanticTokens>;
}

/**
Expand All @@ -76,21 +78,21 @@ export interface SemanticTokensMiddleware {
document: TextDocument,
token: CancellationToken,
next: DocumentSemanticsTokensSignature,
) => ProviderResult<SemanticTokens>;
) => ProviderResult<VSemanticTokens>;
provideDocumentSemanticTokensEdits?: (
this: void,
document: TextDocument,
previousResultId: string,
token: CancellationToken,
next: DocumentSemanticsTokensEditsSignature,
) => ProviderResult<SemanticTokensEdits | SemanticTokens>;
) => ProviderResult<SemanticTokensEdits | VSemanticTokens>;
provideDocumentRangeSemanticTokens?: (
this: void,
document: TextDocument,
range: Range,
token: CancellationToken,
next: DocumentRangeSemanticTokensSignature,
) => ProviderResult<SemanticTokens>;
) => ProviderResult<VSemanticTokens>;
}

export interface SemanticTokensProviderShape {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { EndOfLine, NotebookCellKind, Uri } from './vscodeAdaptor.js';

export const l2c = {
asNotebookDocument(libroView: LibroView): NotebookDocument {
const model = libroView.model;
const model = libroView.model as any;
if (!model.filePath) {
throw new Error('no filePath: invalid libro jupyter model');
}
const filePath = model.filePath as string;
return {
uri: Uri.parse(filePath),
Expand All @@ -28,17 +31,22 @@ export const l2c = {
},

asNotebookCell(cell: CellView): NotebookCell {
const model = cell.parent.model as any;
if (!model.filePath) {
throw new Error('no filePath: invalid libro jupyter model');
}
const filePath = model.filePath as string;
return {
index: cell.parent.findCellIndex(cell),
notebook: l2c.asNotebookDocument(cell.parent),
kind:
cell.model.type === 'code' ? NotebookCellKind.Code : NotebookCellKind.Markup,
document: {
uri: Uri.parse(cell.parent.model.filePath).with({
uri: Uri.parse(filePath).with({
scheme: NotebookDocumentSyncFeature.CellScheme,
query: `cellid=${cell.model.id}`,
}),
fileName: cell.parent.model.filePath,
fileName: filePath,
isUntitled: false,
languageId: 'python',
version: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { DisposableCollection } from '@difizen/mana-app';
import { MarkerSeverity } from '@difizen/monaco-editor-core';
import * as monaco from '@difizen/monaco-editor-core';
import type { editor } from '@difizen/monaco-editor-core';
import type { DiagnosticCollection } from 'vscode';
import type { Diagnostic, Uri, Disposable } from 'vscode';
import type { Diagnostic, Uri } from 'vscode';
import { URI } from 'vscode-uri';

import * as c2p from '../codeConverter.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ export class Diagnostic {
message: string;
severity: DiagnosticSeverity;
source?: string;
code?: string | number;
code?: string | number | { value: string | number; target: URI };
relatedInformation?: DiagnosticRelatedInformation[];
tags?: DiagnosticTag[];

Expand Down Expand Up @@ -1409,7 +1409,7 @@ export class SymbolInformation {
location!: Location;
kind: SymbolKind;
tags?: SymbolTag[];
containerName: string | undefined;
containerName: string;

constructor(
name: string,
Expand All @@ -1433,7 +1433,7 @@ export class SymbolInformation {
) {
this.name = name;
this.kind = kind;
this.containerName = containerName;
this.containerName = containerName ?? '';

if (typeof rangeOrContainer === 'string') {
this.containerName = rangeOrContainer;
Expand Down Expand Up @@ -1507,12 +1507,14 @@ export class CodeAction {

edit?: WorkspaceEdit;

diagnostics?: Diagnostic[];
diagnostics?: vscode.Diagnostic[];

kind?: CodeActionKind;

isPreferred?: boolean;

disabled?: { reason: string };

constructor(title: string, kind?: CodeActionKind) {
this.title = title;
this.kind = kind;
Expand Down Expand Up @@ -4231,10 +4233,22 @@ export enum StandardTokenType {
}

export class LinkedEditingRanges {
constructor(
public readonly ranges: Range[],
public readonly wordPattern: RegExp,
) {}
constructor(ranges: Range[], wordPattern?: RegExp | undefined) {
this.ranges = ranges;
this.wordPattern = wordPattern;
}

/**
* A list of ranges that can be edited together. The ranges must have
* identical length and text content. The ranges cannot overlap.
*/
readonly ranges: Range[];

/**
* An optional word pattern that describes valid contents for the given ranges.
* If no pattern is provided, the language configuration's word pattern will be used.
*/
readonly wordPattern: RegExp | undefined;
}

//#region ports
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { NotebookView } from '@difizen/libro-core';
import { EditorCellView } from '@difizen/libro-core';
import { LibroService } from '@difizen/libro-core';
import { inject, singleton } from '@difizen/mana-app';
import type { Event, FileSystemWatcher, GlobPattern, Uri } from 'vscode';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { FileStat, FileSystem, Uri } from 'vscode';

import { FileType } from './vscodeAdaptor.js';

export class LibroFS implements FileSystem {
stat(uri: Uri): Thenable<FileStat> {
return Promise.resolve<FileStat>({
type: FileType.File,
ctime: 0,
mtime: 0,
size: 0,
});
}
readDirectory(uri: Uri): Thenable<[string, FileType][]> {
throw new Error('Method not implemented.');
}
createDirectory(uri: Uri): Thenable<void> {
throw new Error('Method not implemented.');
}
readFile(uri: Uri): Thenable<Uint8Array> {
throw new Error('Method not implemented.');
}
writeFile(uri: Uri, content: Uint8Array): Thenable<void> {
throw new Error('Method not implemented.');
}
delete(
uri: Uri,
options?:
| { recursive?: boolean | undefined; useTrash?: boolean | undefined }
| undefined,
): Thenable<void> {
throw new Error('Method not implemented.');
}
rename(
source: Uri,
target: Uri,
options?: { overwrite?: boolean | undefined } | undefined,
): Thenable<void> {
throw new Error('Method not implemented.');
}
copy(
source: Uri,
target: Uri,
options?: { overwrite?: boolean | undefined } | undefined,
): Thenable<void> {
throw new Error('Method not implemented.');
}
isWritableFileSystem(scheme: string): boolean | undefined {
throw new Error('Method not implemented.');
}
}
Loading

0 comments on commit 398506e

Please sign in to comment.