Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace json theia extension with vscode one #8112

Merged
merged 3 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ cache:
- packages/filesystem/node_modules
- packages/getting-started/node_modules
- packages/git/node_modules
- packages/json/node_modules
- packages/keymaps/node_modules
- packages/languages/node_modules
- packages/markers/node_modules
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

- [core] fixed handling of environment variables on Windows [#7973](https://github.com/eclipse-theia/theia/pull/7973)

Breaking Changes:

<a name="1_4_0_replace_json"></a>
- [[json]](#1_4_0_replace_json) replaced `@theia/json` Theia extension with `vscode.json-language-features` VS Code extension [#8112](https://github.com/eclipse-theia/theia/pull/8112)
- You can register JSON validations at application startup by implementing `JsonSchemaContribution` Theia contribution point.
- Alternatively you can provide JSON validations using VS Code [contributes.jsonValidation](https://code.visualstudio.com/api/references/contribution-points#contributes.jsonValidation) contribution point.
<a name="1_4_0_absolute_user_storage_uri"></a>
- [[user-storage]](#1_4_0_absolute_user_storage_uri) settings URI must be an absolute to satisfy expectations of `vscode.json-language-features` [#8112](https://github.com/eclipse-theia/theia/pull/8112)
- If you imlpement a custom user storage make sure to check old relaitve locations, otherwise it can cause user data loss.
<a name="1_4_0_deprecate_languages"></a>
- [[languages]](#1_4_0_deprecate_languages) `@theia/languages` extension is deprecated, use VS Code extensions to provide language smartness:
https://code.visualstudio.com/api/language-extensions/language-server-extension-guide [#8112](https://github.com/eclipse-theia/theia/pull/8112)

## v1.3.0

- [cli] updated the download script to warn about mandatory `theiaPlugins` field [#8058](https://github.com/eclipse-theia/theia/pull/8058)
Expand Down
3 changes: 0 additions & 3 deletions configs/root-compilation.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
{
"path": "../packages/git/compile.tsconfig.json"
},
{
"path": "../packages/json/compile.tsconfig.json"
},
{
"path": "../packages/keymaps/compile.tsconfig.json"
},
Expand Down
3 changes: 1 addition & 2 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@theia/filesystem": "^1.3.0",
"@theia/getting-started": "^1.3.0",
"@theia/git": "^1.3.0",
"@theia/json": "^1.3.0",
"@theia/keymaps": "^1.3.0",
"@theia/languages": "^1.3.0",
"@theia/markers": "^1.3.0",
Expand Down Expand Up @@ -70,4 +69,4 @@
"devDependencies": {
"@theia/cli": "^1.3.0"
}
}
}
3 changes: 0 additions & 3 deletions examples/electron/compile.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
{
"path": "../../packages/git/compile.tsconfig.json"
},
{
"path": "../../packages/json/compile.tsconfig.json"
},
{
"path": "../../packages/keymaps/compile.tsconfig.json"
},
Expand Down
3 changes: 1 addition & 2 deletions examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@theia/filesystem": "^1.3.0",
"@theia/getting-started": "^1.3.0",
"@theia/git": "^1.3.0",
"@theia/json": "^1.3.0",
"@theia/keymaps": "^1.3.0",
"@theia/languages": "^1.3.0",
"@theia/markers": "^1.3.0",
Expand Down Expand Up @@ -66,4 +65,4 @@
"devDependencies": {
"@theia/cli": "^1.3.0"
}
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"vscode-builtin-jake": "https://open-vsx.org/api/vscode/jake/1.44.2/file/vscode.jake-1.44.2.vsix",
"vscode-builtin-java": "https://open-vsx.org/api/vscode/java/1.44.2/file/vscode.java-1.44.2.vsix",
"vscode-builtin-javascript": "https://open-vsx.org/api/vscode/javascript/1.44.2/file/vscode.javascript-1.44.2.vsix",
"vscode-builtin-json": "https://open-vsx.org/api/vscode/json/1.44.2/file/vscode.json-1.44.2.vsix",
"vscode-builtin-json": "https://open-vsx.org/api/vscode/json/1.46.1/file/vscode.json-1.46.1.vsix",
"vscode-builtin-json-language-features": "https://open-vsx.org/api/vscode/json-language-features/1.46.1/file/vscode.json-language-features-1.46.1.vsix",
"vscode-builtin-less": "https://open-vsx.org/api/vscode/less/1.44.2/file/vscode.less-1.44.2.vsix",
"vscode-builtin-log": "https://open-vsx.org/api/vscode/log/1.44.2/file/vscode.log-1.44.2.vsix",
"vscode-builtin-lua": "https://open-vsx.org/api/vscode/lua/1.44.2/file/vscode.lua-1.44.2.vsix",
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/browser/frontend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import { WebSocketConnectionProvider } from './messaging';
import { AboutDialog, AboutDialogProps } from './about-dialog';
import { EnvVariablesServer, envVariablesPath, EnvVariable } from './../common/env-variables';
import { FrontendApplicationStateService } from './frontend-application-state';
import { JsonSchemaStore } from './json-schema-store';
import { JsonSchemaStore, JsonSchemaContribution, DefaultJsonSchemaContribution } from './json-schema-store';
import { TabBarToolbarRegistry, TabBarToolbarContribution, TabBarToolbarFactory, TabBarToolbar } from './shell/tab-bar-toolbar';
import { bindCorePreferences } from './core-preferences';
import { QuickPickServiceImpl } from './quick-open/quick-pick-service-impl';
Expand Down Expand Up @@ -257,7 +257,11 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo
bindPreferenceService(bind);
bind(FrontendApplicationContribution).toService(PreferenceService);

bindContributionProvider(bind, JsonSchemaContribution);
bind(JsonSchemaStore).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(JsonSchemaStore);
bind(DefaultJsonSchemaContribution).toSelf().inSingletonScope();
bind(JsonSchemaContribution).toService(DefaultJsonSchemaContribution);

bind(PingService).toDynamicValue(ctx => {
// let's reuse a simple and cheap service from this package
Expand Down
133 changes: 89 additions & 44 deletions packages/core/src/browser/json-schema-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,65 +14,110 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import debounce = require('lodash.debounce');

import { injectable, inject } from 'inversify';
import { InMemoryResources } from '../common/resource';
import { Disposable, DisposableCollection } from '../common/disposable';
import { Emitter } from '../common/event';
import URI from '../common/uri';
import { injectable, inject, named } from 'inversify';
import { ContributionProvider } from '../common/contribution-provider';
import { FrontendApplicationContribution } from './frontend-application';
import { MaybePromise } from '../common';
import { Endpoint } from './endpoint';
import { timeout, Deferred } from '../common/promise-util';

export interface JsonSchemaConfiguration {
url: string
fileMatch: string[]
fileMatch: string | string[];
url: string;
}

@injectable()
export class JsonSchemaStore {

@inject(InMemoryResources)
protected readonly inMemoryResources: InMemoryResources;
export interface JsonSchemaRegisterContext {
registerSchema(config: JsonSchemaConfiguration): void;
}

private readonly schemas: JsonSchemaConfiguration[] = [];
export const JsonSchemaContribution = Symbol('JsonSchemaContribution');
export interface JsonSchemaContribution {
registerSchemas(store: JsonSchemaRegisterContext): MaybePromise<void>
}

protected readonly onSchemasChangedEmitter = new Emitter<void>();
readonly onSchemasChanged = this.onSchemasChangedEmitter.event;
@injectable()
export class JsonSchemaStore implements FrontendApplicationContribution {

protected readonly onDidChangeSchemaEmitter = new Emitter<URI>();
readonly onDidChangeSchema = this.onDidChangeSchemaEmitter.event;
@inject(ContributionProvider) @named(JsonSchemaContribution)
protected readonly contributions: ContributionProvider<JsonSchemaContribution>;

protected notifyChanged = debounce(() => {
this.onSchemasChangedEmitter.fire(undefined);
}, 500);
protected readonly _schemas = new Deferred<JsonSchemaConfiguration[]>();
get schemas(): Promise<JsonSchemaConfiguration[]> {
return this._schemas.promise;
}

registerSchema(config: JsonSchemaConfiguration): Disposable {
const toDispose = new DisposableCollection();
const uri = new URI(config.url);
if (uri.scheme === 'vscode') {
const resource = this.inMemoryResources.resolve(new URI(config.url));
if (resource && resource.onDidChangeContents) {
toDispose.push(resource.onDidChangeContents(() => {
this.onDidChangeSchemaEmitter.fire(uri);
this.notifyChanged();
onStart(): void {
const pendingRegistrations = [];
const schemas: JsonSchemaConfiguration[] = [];
const freeze = () => {
Object.freeze(schemas);
this._schemas.resolve(schemas);
};
const registerTimeout = this.getRegisterTimeout();
const frozenErrorCode = 'JsonSchemaRegisterContext.frozen';
const context: JsonSchemaRegisterContext = {
registerSchema: schema => {
if (Object.isFrozen(schemas)) {
throw new Error(frozenErrorCode);
}
schemas.push(schema);
}
};
for (const contribution of this.contributions.getContributions()) {
const result = contribution.registerSchemas(context);
if (result) {
pendingRegistrations.push(result.then(() => { }, e => {
if (e instanceof Error && e.message === frozenErrorCode) {
console.error(`${contribution.constructor.name}.registerSchemas is taking more than ${registerTimeout.toFixed(1)} ms, new schemas are ignored.`);
} else {
console.error(e);
}
}));
}
}
this.schemas.push(config);
toDispose.push(Disposable.create(() => {
const idx = this.schemas.indexOf(config);
if (idx > -1) {
this.schemas.splice(idx, 1);
this.onDidChangeSchemaEmitter.fire(uri);
this.notifyChanged();
if (pendingRegistrations.length) {
let pending = Promise.all(pendingRegistrations).then(() => { });
if (registerTimeout) {
pending = Promise.race([pending, timeout(registerTimeout)]);
}
}));
this.onDidChangeSchemaEmitter.fire(uri);
this.notifyChanged();
return toDispose;
pending.then(freeze);
} else {
freeze();
}
}

protected getRegisterTimeout(): number {
return 500;
}

getJsonSchemaConfigurations(): JsonSchemaConfiguration[] {
return [...this.schemas];
}

@injectable()
export class DefaultJsonSchemaContribution implements JsonSchemaContribution {

async registerSchemas(context: JsonSchemaRegisterContext): Promise<void> {
const url = `${new Endpoint().httpScheme}//schemastore.azurewebsites.net/api/json/catalog.json`;
const response = await fetch(url);
const schemas: DefaultJsonSchemaContribution.SchemaData[] = (await response.json()).schemas!;
for (const s of schemas) {
if (s.fileMatch) {
context.registerSchema({
fileMatch: s.fileMatch,
url: s.url
});
}
}
}

}
export namespace DefaultJsonSchemaContribution {
export interface SchemaData {
name: string;
description: string;
fileMatch?: string[];
url: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
schema: any;
}
}

2 changes: 1 addition & 1 deletion packages/core/src/common/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class MutableResource implements Resource {
@injectable()
export class InMemoryResources implements ResourceResolver {

private resources = new Map<string, MutableResource>();
private readonly resources = new Map<string, MutableResource>();

add(uri: URI, contents: string): Resource {
const resourceUri = uri.toString();
Expand Down
2 changes: 2 additions & 0 deletions packages/debug/src/browser/debug-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { DebugWatchManager } from './debug-watch-manager';
import { MonacoEditorService } from '@theia/monaco/lib/browser/monaco-editor-service';
import { DebugBreakpointWidget } from './editor/debug-breakpoint-widget';
import { DebugInlineValueDecorator } from './editor/debug-inline-value-decorator';
import { JsonSchemaContribution } from '@theia/core/lib/browser/json-schema-store';

export default new ContainerModule((bind: interfaces.Bind) => {
bind(DebugCallStackItemTypeKey).toDynamicValue(({ container }) =>
Expand Down Expand Up @@ -85,6 +86,7 @@ export default new ContainerModule((bind: interfaces.Bind) => {
DebugConsoleContribution.bindContribution(bind);

bind(DebugSchemaUpdater).toSelf().inSingletonScope();
bind(JsonSchemaContribution).toService(DebugSchemaUpdater);
bind(DebugConfigurationManager).toSelf().inSingletonScope();

bind(DebugInlineValueDecorator).toSelf().inSingletonScope();
Expand Down
26 changes: 13 additions & 13 deletions packages/debug/src/browser/debug-schema-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import { injectable, inject } from 'inversify';
import { JsonSchemaStore } from '@theia/core/lib/browser/json-schema-store';
import { JsonSchemaRegisterContext, JsonSchemaContribution } from '@theia/core/lib/browser/json-schema-store';
import { InMemoryResources, deepClone } from '@theia/core/lib/common';
import { IJSONSchema } from '@theia/core/lib/common/json-schema';
import URI from '@theia/core/lib/common/uri';
Expand All @@ -24,12 +24,21 @@ import { debugPreferencesSchema } from './debug-preferences';
import { inputsSchema } from '@theia/variable-resolver/lib/browser/variable-input-schema';

@injectable()
export class DebugSchemaUpdater {
export class DebugSchemaUpdater implements JsonSchemaContribution {

protected readonly uri = new URI(launchSchemaId);

@inject(JsonSchemaStore) protected readonly jsonSchemaStore: JsonSchemaStore;
@inject(InMemoryResources) protected readonly inmemoryResources: InMemoryResources;
@inject(DebugService) protected readonly debug: DebugService;

registerSchemas(context: JsonSchemaRegisterContext): void {
this.inmemoryResources.add(this.uri, '');
context.registerSchema({
fileMatch: ['launch.json'],
url: this.uri.toString()
});
}

async update(): Promise<void> {
const types = await this.debug.debugTypes();
const schema = { ...deepClone(launchSchema) };
Expand All @@ -48,17 +57,8 @@ export class DebugSchemaUpdater {
}
items.defaultSnippets!.push(...await this.debug.getConfigurationSnippets());

const uri = new URI(launchSchemaId);
const contents = JSON.stringify(schema);
try {
this.inmemoryResources.update(uri, contents);
} catch (e) {
this.inmemoryResources.add(uri, contents);
this.jsonSchemaStore.registerSchema({
fileMatch: ['launch.json'],
url: uri.toString()
});
}
this.inmemoryResources.update(this.uri, contents);
}
}

Expand Down
10 changes: 0 additions & 10 deletions packages/json/.eslintrc.js

This file was deleted.

Loading