Skip to content

Commit

Permalink
Upgrade the Theia build to use Typescript 5.4.5 (#13628)
Browse files Browse the repository at this point in the history
Most changes are just typing to accomodate stricter checks in 5.4.5.

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder authored May 22, 2024
1 parent d9e58c3 commit 7286049
Show file tree
Hide file tree
Showing 21 changed files with 168 additions and 133 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<!-- ## not yet released
- [cli] Updated our build to use Typescript 5.4.5 [#13628](https://github.com/eclipse-theia/theia/pull/13628) - contributed on behalf of STMicroelectronics
<a name="breaking_changes_not_yet_released">[Breaking Changes:](#breaking_changes_not_yet_released)</a> -->

## 1.50.0
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/localization-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"fs-extra": "^4.0.2",
"glob": "^7.2.0",
"tslib": "^2.6.2",
"typescript": "~4.5.5"
"typescript": "~5.4.5"
},
"devDependencies": {
"@theia/ext-scripts": "1.49.0"
Expand Down
11 changes: 10 additions & 1 deletion dev-packages/localization-manager/src/localization-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class SingleFileServiceHost implements ts.LanguageServiceHost {
getScriptSnapshot = (name: string) => name === this.filename ? this.file : this.lib;
getCurrentDirectory = () => '';
getDefaultLibFileName = () => 'lib.d.ts';
readFile(file: string, encoding?: string | undefined): string | undefined {
if (file === this.filename) {
return this.file.getText(0, this.file.getLength());
}
}
fileExists(file: string): boolean {
return this.filename === file;
}
}

class TypeScriptError extends Error {
Expand Down Expand Up @@ -81,8 +89,9 @@ export async function extract(options: ExtractionOptions): Promise<void> {
const errors: string[] = [];
for (const file of files) {
const filePath = path.resolve(cwd, file);
const fileName = path.relative(cwd, file).split(path.sep).join('/');
const content = await fs.readFile(filePath, 'utf8');
const fileLocalization = await extractFromFile(file, content, errors, options);
const fileLocalization = await extractFromFile(fileName, content, errors, options);
localization = deepmerge(localization, fileLocalization);
}
if (errors.length > 0 && options.logs) {
Expand Down
2 changes: 1 addition & 1 deletion examples/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"allure-commandline": "^2.23.1",
"allure-playwright": "^2.5.0",
"rimraf": "^2.6.1",
"typescript": "~4.5.5"
"typescript": "~5.4.5"
},
"publishConfig": {
"access": "public"
Expand Down
5 changes: 3 additions & 2 deletions examples/playwright/src/theia-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export class TheiaApp {
return view;
}

async openEditor<T extends TheiaEditor>(filePath: string, editorFactory: { new(filePath: string, app: TheiaApp): T },
async openEditor<T extends TheiaEditor>(filePath: string,
editorFactory: { new(fp: string, app: TheiaApp): T },
editorName?: string, expectFileNodes = true): Promise<T> {
const explorer = await this.openView(TheiaExplorerView);
if (!explorer) {
Expand Down Expand Up @@ -135,7 +136,7 @@ export class TheiaApp {
return editor;
}

async activateExistingEditor<T extends TheiaEditor>(filePath: string, editorFactory: { new(filePath: string, app: TheiaApp): T }): Promise<T> {
async activateExistingEditor<T extends TheiaEditor>(filePath: string, editorFactory: { new(fp: string, app: TheiaApp): T }): Promise<T> {
const editor = new editorFactory(filePath, this);
if (!await editor.isTabVisible()) {
throw new Error(`Could not find opened editor for file ${filePath}`);
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"@types/node": "18",
"@types/sinon": "^10.0.6",
"@types/temp": "^0.9.1",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/eslint-plugin-tslint": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/eslint-plugin-tslint": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vscode/vsce": "^2.15.0",
"archiver": "^5.3.1",
"chai": "4.3.10",
Expand Down Expand Up @@ -54,7 +54,7 @@
"tslint": "^5.12.0",
"typedoc": "^0.22.11",
"typedoc-plugin-external-module-map": "1.3.2",
"typescript": "~4.5.5",
"typescript": "~5.4.5",
"yargs": "^15.3.1"
},
"scripts": {
Expand Down Expand Up @@ -114,4 +114,4 @@
"vscode.microsoft-authentication",
"ms-vscode.references-view"
]
}
}
3 changes: 2 additions & 1 deletion packages/core/src/browser/keybinding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ before(async () => {
bind(StatusBar).toConstantValue({} as StatusBar);
bind(MarkdownRendererImpl).toSelf().inSingletonScope();
bind(MarkdownRenderer).toService(MarkdownRendererImpl);
bind(MarkdownRendererFactory).toFactory(({ container }) => container.get(MarkdownRenderer));
bind(MarkdownRendererFactory).toFactory(({ container }) => () => container.get(MarkdownRenderer));

bind(CommandService).toService(CommandRegistry);
bind(LabelParser).toSelf().inSingletonScope();
bind(ContextKeyService).to(ContextKeyServiceDummyImpl).inSingletonScope();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/test/mock-storage-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { injectable } from 'inversify';
*/
@injectable()
export class MockStorageService implements StorageService {
readonly data = new Map<string, {} | undefined>();
readonly data = new Map<string, unknown | undefined>();

// eslint-disable-next-line @typescript-eslint/no-explicit-any
onSetDataCallback?: (key: string, data?: any) => void;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/encoding-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class EncodingService {
});
}

encodeStream(value: string | Readable<string>, options?: ResourceEncoding): Promise<BinaryBuffer | BinaryBufferReadable>
encodeStream(value: string | Readable<string>, options?: ResourceEncoding): Promise<BinaryBuffer | BinaryBufferReadable>;
encodeStream(value?: string | Readable<string>, options?: ResourceEncoding): Promise<BinaryBuffer | BinaryBufferReadable | undefined>;
async encodeStream(value: string | Readable<string> | undefined, options?: ResourceEncoding): Promise<BinaryBuffer | BinaryBufferReadable | undefined> {
let encoding = options?.encoding;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/selection-command-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { CommandHandler } from './command';
import { SelectionService } from '../common/selection-service';

export class SelectionCommandHandler<S> implements CommandHandler {
export class SelectionCommandHandler<S extends Object> implements CommandHandler {

constructor(
protected readonly selectionService: SelectionService,
Expand Down
3 changes: 2 additions & 1 deletion packages/filesystem/src/common/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ export interface WatchOptions {
}

export const enum FileSystemProviderCapabilities {
None = 0,
FileReadWrite = 1 << 1,
FileOpenReadWriteClose = 1 << 2,
FileReadStream = 1 << 4,
Expand Down Expand Up @@ -774,7 +775,7 @@ export interface ReadOnlyMessageFileSystemProvider {
export namespace ReadOnlyMessageFileSystemProvider {
export function is(arg: unknown): arg is ReadOnlyMessageFileSystemProvider {
return isObject<ReadOnlyMessageFileSystemProvider>(arg)
&& 'readOnlyMessage' in arg;
&& 'readOnlyMessage' in arg;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class RemoteFileSystemProvider implements Required<FileSystemProvider>, D
options: WatchOptions
}>();

private _capabilities: FileSystemProviderCapabilities = 0;
private _capabilities: FileSystemProviderCapabilities = FileSystemProviderCapabilities.None;
get capabilities(): FileSystemProviderCapabilities { return this._capabilities; }

private _readOnlyMessage: MarkdownString | undefined = undefined;
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ export interface StatusBarMessageRegistryMain {

export interface QuickOpenExt {
$onItemSelected(handle: number): void;
$validateInput(input: string): Promise<string | { content: string; severity: Severity; } | null | undefined> | undefined;
$validateInput(input: string): Promise<string | { content: string; severity: Severity; } | null | undefined>;

$acceptOnDidAccept(sessionId: number): Promise<void>;
$acceptDidChangeValue(sessionId: number, changedValue: string): Promise<void>;
Expand Down Expand Up @@ -1208,7 +1208,7 @@ export interface UndoStopOptions {
}

export interface ApplyEditsOptions extends UndoStopOptions {
setEndOfLine: EndOfLine;
setEndOfLine: EndOfLine | undefined;
}

export interface ThemeColor {
Expand Down Expand Up @@ -1859,12 +1859,12 @@ export interface WebviewViewsMain extends Disposable {
}

export interface CustomEditorsExt {
$resolveWebviewEditor<T>(
$resolveWebviewEditor(
resource: UriComponents,
newWebviewHandle: string,
viewType: string,
title: string,
widgetOpenerOptions: T | undefined,
widgetOpenerOptions: object | undefined,
options: theia.WebviewPanelOptions,
cancellation: CancellationToken): Promise<void>;
$createCustomDocument(resource: UriComponents, viewType: string, openContext: theia.CustomDocumentOpenContext, cancellation: CancellationToken): Promise<{ editable: boolean }>;
Expand All @@ -1887,7 +1887,7 @@ export interface CustomEditorsMain {
$registerTextEditorProvider(viewType: string, options: theia.WebviewPanelOptions, capabilities: CustomTextEditorCapabilities): void;
$registerCustomEditorProvider(viewType: string, options: theia.WebviewPanelOptions, supportsMultipleEditorsPerDocument: boolean): void;
$unregisterEditorProvider(viewType: string): void;
$createCustomEditorPanel<T>(handle: string, title: string, widgetOpenerOptions: T | undefined, options: theia.WebviewPanelOptions & theia.WebviewOptions): Promise<void>;
$createCustomEditorPanel(handle: string, title: string, widgetOpenerOptions: object | undefined, options: theia.WebviewPanelOptions & theia.WebviewOptions): Promise<void>;
$onDidEdit(resource: UriComponents, viewType: string, editId: number, label: string | undefined): void;
$onContentChange(resource: UriComponents, viewType: string): void;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/main/browser/quick-open-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class QuickOpenMainImpl implements QuickOpenMain, Disposable {
}

private toQuickPickItem(item: undefined): undefined;
private toQuickPickItem(item: TransferQuickPickItem): QuickPickItem
private toQuickPickItem(item: TransferQuickPickItem): QuickPickItem;
private toQuickPickItem(item: TransferQuickPickItem | undefined): QuickPickItem | undefined {
if (!item) {
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/plugin/custom-editors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class CustomEditorsExtImpl implements CustomEditorsExt {
handler: string,
viewType: string,
title: string,
widgetOpenerOptions: T | undefined,
widgetOpenerOptions: object | undefined,
options: theia.WebviewPanelOptions & theia.WebviewOptions,
cancellation: CancellationToken
): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/plugin/quick-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import { convertToTransferQuickPickItems } from './type-converters';
import { PluginPackage } from '../common/plugin-protocol';
import { QuickInputButtonHandle } from '@theia/core/lib/browser';
import { MaybePromise } from '@theia/core/lib/common/types';
import Severity from '@theia/monaco-editor-core/esm/vs/base/common/severity';
import { ThemeIcon as MonacoThemeIcon } from '@theia/monaco-editor-core/esm/vs/base/common/themables';
import { Severity } from '@theia/core/lib/common/severity';

const canceledName = 'Canceled';
/**
Expand Down
5 changes: 2 additions & 3 deletions packages/plugin-ext/src/plugin/text-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,21 +499,20 @@ export interface TextEditOperation {
export interface EditData {
documentVersionId: number;
edits: TextEditOperation[];
setEndOfLine: EndOfLine;
setEndOfLine: EndOfLine | undefined;
undoStopBefore: boolean;
undoStopAfter: boolean;
}

export class TextEditorEdit {
private readonly documentVersionId: number;
private collectedEdits: TextEditOperation[];
private eol: EndOfLine;
private eol: EndOfLine | undefined;
private readonly undoStopBefore: boolean;
private readonly undoStopAfter: boolean;
constructor(private document: theia.TextDocument, options: { undoStopBefore: boolean; undoStopAfter: boolean }) {
this.documentVersionId = document.version;
this.collectedEdits = [];
this.eol = 0;
this.undoStopBefore = options.undoStopBefore;
this.undoStopAfter = options.undoStopAfter;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class URI extends CodeURI implements theia.Uri {
*/
static override revive(data: UriComponents | CodeURI): URI;
static override revive(data: UriComponents | CodeURI | null): URI | null;
static override revive(data: UriComponents | CodeURI | undefined): URI | undefined
static override revive(data: UriComponents | CodeURI | undefined): URI | undefined;
static override revive(data: UriComponents | CodeURI | undefined | null): URI | undefined | null {
const uri = CodeURI.revive(data);
return uri ? new URI(uri) : undefined;
Expand Down Expand Up @@ -882,7 +882,7 @@ export class TextEdit {

protected _range: Range;
protected _newText: string;
protected _newEol: EndOfLine;
protected _newEol: EndOfLine | undefined;

get range(): Range {
return this._range;
Expand All @@ -906,7 +906,7 @@ export class TextEdit {
this._newText = value;
}

get newEol(): EndOfLine {
get newEol(): EndOfLine | undefined {
return this._newEol;
}

Expand Down Expand Up @@ -2060,8 +2060,8 @@ export class TreeItem {
readonly accessibilityInformation?: AccessibilityInformation
};

constructor(label: string | theia.TreeItemLabel, collapsibleState?: theia.TreeItemCollapsibleState)
constructor(resourceUri: URI, collapsibleState?: theia.TreeItemCollapsibleState)
constructor(label: string | theia.TreeItemLabel, collapsibleState?: theia.TreeItemCollapsibleState);
constructor(resourceUri: URI, collapsibleState?: theia.TreeItemCollapsibleState);
constructor(arg1: string | theia.TreeItemLabel | URI, public collapsibleState: theia.TreeItemCollapsibleState = TreeItemCollapsibleState.None) {
if (arg1 instanceof URI) {
this.resourceUri = arg1;
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7910,7 +7910,7 @@ export module '@theia/plugin' {
* @param pattern A file glob pattern like `*.{ts,js}` that will be matched on file paths
* relative to the base path.
*/
constructor(base: WorkspaceFolder | Uri | string, pattern: string)
constructor(base: WorkspaceFolder | Uri | string, pattern: string);
}

/**
Expand Down
13 changes: 0 additions & 13 deletions packages/workspace/src/browser/workspace-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,19 +519,6 @@ export class WorkspaceCommandContribution implements CommandContribution {
return registry.executeCommand(saveCommand.id);
}
}

protected areMultipleOpenHandlersPresent(openers: OpenHandler[], uri: URI): boolean {
let count = 0;
for (const opener of openers) {
if (opener.canHandle(uri) > 0) {
count++;
}
if (count > 1) {
return true;
}
}
return false;
}
}

export class WorkspaceRootUriAwareCommandHandler extends UriAwareCommandHandler<URI> {
Expand Down
Loading

0 comments on commit 7286049

Please sign in to comment.