Skip to content

Commit

Permalink
Merge branch 'master' into support-browser-debug
Browse files Browse the repository at this point in the history
  • Loading branch information
thegecko committed Feb 18, 2022
2 parents 94e48ff + cdc2d9f commit 6e92ea1
Show file tree
Hide file tree
Showing 74 changed files with 428 additions and 271 deletions.
1 change: 1 addition & 0 deletions configs/errors.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
}
}
],
"@theia/localization-check": "error",
"@theia/no-src-import": "error",
"@theia/runtime-import-check": "error",
"@theia/shared-dependencies": "error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export class WebpackGenerator extends AbstractGenerator {
const path = require('path');
const webpack = require('webpack');
const yargs = require('yargs');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
${this.ifMonaco(() => `const CopyWebpackPlugin = require('copy-webpack-plugin');
`)}const CircularDependencyPlugin = require('circular-dependency-plugin');
const CompressionPlugin = require('compression-webpack-plugin')
const outputPath = path.resolve(__dirname, 'lib');
Expand All @@ -75,13 +75,13 @@ const development = mode === 'development';${this.ifMonaco(() => `
const monacoEditorCorePath = development ? '${this.resolve('@theia/monaco-editor-core', 'dev/vs')}' : '${this.resolve('@theia/monaco-editor-core', 'min/vs')}';`)}
const plugins = [
new CopyWebpackPlugin({
patterns: [${this.ifMonaco(() => `{
${this.ifMonaco(() => `new CopyWebpackPlugin({
patterns: [{
from: monacoEditorCorePath,
to: 'vs'
}`)}]
}]
}),
new webpack.ProvidePlugin({
`)}new webpack.ProvidePlugin({
// the Buffer class doesn't exist in the browser but some dependencies rely on it
Buffer: ['buffer', 'Buffer']
})
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/application-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"@types/request": "^2.0.3",
"@types/semver": "^5.4.0",
"@types/write-json-file": "^2.2.1",
"changes-stream": "^2.2.0",
"deepmerge": "^4.2.2",
"fs-extra": "^4.0.2",
"is-electron": "^2.1.0",
"nano": "^9.0.5",
"request": "^2.82.0",
"semver": "^5.4.1",
"write-json-file": "^2.2.0"
Expand Down
14 changes: 6 additions & 8 deletions dev-packages/application-package/src/npm-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/* eslint-disable @typescript-eslint/no-explicit-any */
import * as request from 'request';
const ChangesStream = require('changes-stream');
import * as nano from 'nano';
import { NpmRegistryProps } from './application-props';

export interface IChangeStream {
Expand Down Expand Up @@ -92,7 +92,7 @@ export class NpmRegistry {
readonly props: NpmRegistryProps = { ...NpmRegistryProps.DEFAULT };
protected readonly options: NpmRegistryOptions;

protected changes: undefined | IChangeStream;
protected changes?: nano.ChangesReaderScope;
protected readonly index = new Map<string, Promise<ViewResult>>();

constructor(options?: Partial<NpmRegistryOptions>) {
Expand All @@ -115,13 +115,11 @@ export class NpmRegistry {
this.index.clear();
if (this.options.watchChanges && this.props.registry === NpmRegistryProps.DEFAULT.registry) {
if (this.changes) {
this.changes.destroy();
this.changes.stop();
}
// invalidate index with NPM registry web hooks
// see: https://github.com/npm/registry-follower-tutorial
const db = 'https://replicate.npmjs.com';
this.changes = new ChangesStream({ db }) as IChangeStream;
this.changes.on('data', change => this.invalidate(change.id));
// Invalidate index with NPM registry web hooks
this.changes = nano('https://replicate.npmjs.com').use('registry').changesReader;
this.changes.get({}).on('change', change => this.invalidate(change.id));
}
}
protected invalidate(name: string): void {
Expand Down
10 changes: 1 addition & 9 deletions dev-packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@
"@theia/localization-manager": "1.22.1",
"@theia/ovsx-client": "1.22.1",
"@types/chai": "^4.2.7",
"@types/mkdirp": "^0.5.2",
"@types/mocha": "^5.2.7",
"@types/node-fetch": "^2.5.7",
"@types/puppeteer": "^2.0.0",
"@types/requestretry": "^1.12.3",
"@types/tar": "^4.0.3",
"chai": "^4.2.0",
"chalk": "4.0.0",
"decompress": "^4.2.1",
Expand All @@ -52,18 +49,13 @@
"puppeteer": "^2.0.0",
"puppeteer-to-istanbul": "^1.2.2",
"temp": "^0.9.1",
"unzipper": "^0.9.11",
"yargs": "^15.3.1"
},
"devDependencies": {
"@types/chai": "^4.2.7",
"@types/mkdirp": "^0.5.2",
"@types/mocha": "^5.2.7",
"@types/node-fetch": "^2.5.7",
"@types/proxy-from-env": "^1.0.1",
"@types/puppeteer": "^2.0.0",
"@types/requestretry": "^1.12.3",
"@types/tar": "^4.0.3",
"@types/unzipper": "^0.9.2"
"@types/puppeteer": "^2.0.0"
}
}
6 changes: 6 additions & 0 deletions dev-packages/private-eslint-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ The plugin helps identify problems during development through static analysis in

## Rules

### `localization-check`:

The rule prevents the following localization related issues:
- incorrect usage of the `nls.localizeByDefault` function by using an incorrect default value.
- unnecessary call to `nls.localize` which could be replaced by `nls.localizeByDefault`.

### `no-src-import`:

The rule prevents imports using `/src/` rather than `/lib/` as it causes build failures.
Expand Down
1 change: 1 addition & 0 deletions dev-packages/private-eslint-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

/** @type {{[ruleId: string]: import('eslint').Rule.RuleModule}} */
exports.rules = {
"localization-check": require('./rules/localization-check'),
"no-src-import": require('./rules/no-src-import'),
"runtime-import-check": require('./rules/runtime-import-check'),
"shared-dependencies": require('./rules/shared-dependencies')
Expand Down
3 changes: 2 additions & 1 deletion dev-packages/private-eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"@theia/core": "1.22.1",
"@theia/ext-scripts": "1.22.1",
"@theia/re-exports": "1.22.1"
"@theia/re-exports": "1.22.1",
"js-levenshtein": "^1.1.6"
}
}
109 changes: 109 additions & 0 deletions dev-packages/private-eslint-plugin/rules/localization-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// @ts-check
/********************************************************************************
* Copyright (C) 2021 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

const levenshtein = require('js-levenshtein');

const metadata = require('@theia/core/src/common/i18n/nls.metadata.json');
const messages = new Set(Object.values(metadata.messages)
.reduceRight((prev, curr) => prev.concat(curr), [])
.map(e => e.replace(/&&/g, '')));

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
fixable: 'code',
docs: {
description: 'prevent incorrect use of \'nls.localize\'.',
},
},
create(context) {
return {
CallExpression(node) {
const callee = node.callee;
if (callee.type === 'Super') {
return;
}
const { value, byDefault, node: localizeNode } = evaluateLocalize(node);
if (value !== undefined) {
if (byDefault && !messages.has(value)) {
let lowestDistance = Number.MAX_VALUE;
let lowestMessage = '';
for (const message of messages) {
const distance = levenshtein(value, message);
if (distance < lowestDistance) {
lowestDistance = distance;
lowestMessage = message;
}
}
if (lowestMessage) {
context.report({
node: localizeNode,
message: `'${value}' is not a valid default value. Did you mean '${lowestMessage}'?`,
fix: function (fixer) {
const updatedCall = `'${lowestMessage.replace(/'/g, "\\'")}'`;
return fixer.replaceText(localizeNode, updatedCall);
}
});
} else {
context.report({
node: localizeNode,
message: `'${value}' is not a valid default value.`
});
}
} else if (!byDefault && messages.has(value)) {
context.report({
node,
message: `'${value}' can be translated using the 'nls.localizeByDefault' function.`,
fix: function (fixer) {
const code = context.getSourceCode();
const args = node.arguments.slice(1);
const argsCode = args.map(e => code.getText(e)).join(', ');
const updatedCall = `nls.localizeByDefault(${argsCode})`;
return fixer.replaceText(node, updatedCall);
}
});
}
}
}
};
function evaluateLocalize(/** @type {import('estree').CallExpression} */ node) {
const callee = node.callee;
if ('object' in callee && 'name' in callee.object && 'property' in callee && 'name' in callee.property && callee.object.name === 'nls') {
if (callee.property.name === 'localize') {
const defaultTextNode = node.arguments[1]; // The default text node is the second argument for `nls.localize`
if (defaultTextNode && defaultTextNode.type === 'Literal' && typeof defaultTextNode.value === 'string') {
return {
value: defaultTextNode.value,
byDefault: false
};
}
} else if (callee.property.name === 'localizeByDefault') {
const defaultTextNode = node.arguments[0]; // The default text node is the first argument for ``nls.localizeByDefault`
if (defaultTextNode && defaultTextNode.type === 'Literal' && typeof defaultTextNode.value === 'string') {
return {
node: defaultTextNode,
value: defaultTextNode.value,
byDefault: true
};
}
}
}
return {};
}
}
};
2 changes: 1 addition & 1 deletion doc/pull-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ If a rule causes distress during discussions itself, it has to be reviewed on [t
- Changes are thoroughly tested by an author.
- Changes thoroughly reviewed following the [review checklist](#review-checklist) by an author.
<a name="review-request-gh"></a>
- [2.](#review-request-gh) A review can be requested explicitly using GitHub: https://help.github.com/en/articles/requesting-a-pull-request-reviewed
- [2.](#review-request-gh) A review can be requested explicitly [using GitHub](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/requesting-a-pull-request-review).
<a name="review-request-comment"></a>
- [3.](#review-request-comment) A review can be also requested as a comment from any GitHub users.
- For example to invite the person who originally filed an issue for testing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class BulkEditTreeWidget extends TreeWidget {
if (CompositeTreeNode.is(model.root) && model.root.children.length > 0) {
return super.renderTree(model);
}
return <div className='theia-widget-noInfo noEdits'>{nls.localizeByDefault('No edits have been detected in the workspace so far.')}</div>;
return <div className='theia-widget-noInfo noEdits'>{nls.localizeByDefault('Made no edits')}</div>;
}

protected override renderCaption(node: TreeNode, props: NodeProps): React.ReactNode {
Expand Down
1 change: 0 additions & 1 deletion packages/callhierarchy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"dependencies": {
"@theia/core": "1.22.1",
"@theia/editor": "1.22.1",
"@theia/monaco": "1.22.1",
"ts-md5": "^1.2.2"
},
"publishConfig": {
Expand Down
3 changes: 0 additions & 3 deletions packages/callhierarchy/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
},
{
"path": "../editor"
},
{
"path": "../monaco"
}
]
}
9 changes: 7 additions & 2 deletions packages/core/src/browser/core-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,19 @@ export const corePreferenceSchema: PreferenceSchema = {
default: 300,
minimum: 0,
maximum: 2000,
description: nls.localizeByDefault('Controls the hover feedback delay in milliseconds of the dragging area in between views/editors.')
// nls-todo: Will be available with VSCode API 1.55
description: nls.localize('theia/core/sashDelay', 'Controls the hover feedback delay in milliseconds of the dragging area in between views/editors.')
},
'workbench.sash.size': {
type: 'number',
default: 4,
minimum: 1,
maximum: 20,
description: nls.localizeByDefault('Controls the feedback area size in pixels of the dragging area in between views/editors. Set it to a larger value if needed.')
// nls-todo: Will be available with VSCode API 1.55
description: nls.localize(
'theia/core/sashSize',
'Controls the feedback area size in pixels of the dragging area in between views/editors. Set it to a larger value if needed.'
)
},
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class BrowserKeyboardFrontendContribution implements CommandContribution
protected async chooseLayout(): Promise<KeyboardLayoutData | undefined> {
const current = this.layoutProvider.currentLayoutData;
const autodetect: QuickPickValue<'autodetect'> = {
label: nls.localizeByDefault('Auto-detect'),
label: nls.localizeByDefault('Auto Detect'),
description: this.layoutProvider.currentLayoutSource !== 'user-choice' ? nls.localize('theia/core/keyboard/current', '(current: {0})', current.name) : undefined,
detail: nls.localize('theia/core/keyboard/tryDetect', 'Try to detect the keyboard layout from browser information and pressed keys.'),
value: 'autodetect'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
protected async handleRequiredRestart(): Promise<void> {
const msgNode = document.createElement('div');
const message = document.createElement('p');
message.textContent = nls.localizeByDefault('A setting has changed that requires a restart to take effect');
message.textContent = nls.localizeByDefault('A setting has changed that requires a restart to take effect.');
const detail = document.createElement('p');
detail.textContent = nls.localizeByDefault(
'Press the restart button to restart {0} and enable the setting.', FrontendApplicationConfigProvider.get().applicationName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const electronWindowPreferencesSchema: PreferenceSchema = {
'maximum': ZoomLevel.MAX,
'scope': 'application',
// eslint-disable-next-line max-len
'description': nls.localizeByDefault('Adjust the zoom level of the window. The original size is 0 and each increment above (e.g. 1.0) or below (e.g. -1.0) represents zooming 20% larger or smaller. You can also enter decimals to adjust the zoom level with a finer granularity.')
'description': nls.localizeByDefault('Adjust the zoom level of the window. The original size is 0 and each increment above (e.g. 1) or below (e.g. -1) represents zooming 20% larger or smaller. You can also enter decimals to adjust the zoom level with a finer granularity.')
},
'window.titleBarStyle': {
type: 'string',
Expand Down
2 changes: 0 additions & 2 deletions packages/debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
"@theia/markers": "1.22.1",
"@theia/monaco": "1.22.1",
"@theia/output": "1.22.1",
"@theia/preferences": "1.22.1",
"@theia/process": "1.22.1",
"@theia/task": "1.22.1",
"@theia/terminal": "1.22.1",
"@theia/userstorage": "1.22.1",
"@theia/variable-resolver": "1.22.1",
"@theia/workspace": "1.22.1",
"jsonc-parser": "^2.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

/* eslint-disable @theia/localization-check */

import * as fs from '@theia/core/shared/fs-extra';
import * as path from 'path';
import { DebugAdapterExecutable, DebugAdapterContribution } from '../../common/debug-model';
Expand Down
6 changes: 0 additions & 6 deletions packages/debug/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
{
"path": "../output"
},
{
"path": "../preferences"
},
{
"path": "../process"
},
Expand All @@ -42,9 +39,6 @@
{
"path": "../terminal"
},
{
"path": "../userstorage"
},
{
"path": "../variable-resolver"
},
Expand Down
4 changes: 1 addition & 3 deletions packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"description": "Theia - Editor Extension",
"dependencies": {
"@theia/core": "1.22.1",
"@theia/variable-resolver": "1.22.1",
"@types/base64-arraybuffer": "0.1.0",
"base64-arraybuffer": "^0.1.5"
"@theia/variable-resolver": "1.22.1"
},
"publishConfig": {
"access": "public"
Expand Down
Loading

0 comments on commit 6e92ea1

Please sign in to comment.