Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreadman committed Sep 28, 2024
2 parents d6ff8a8 + 2b0935a commit 9ecee04
Show file tree
Hide file tree
Showing 44 changed files with 594 additions and 284 deletions.
70 changes: 70 additions & 0 deletions .eslintplugin/code-limited-top-functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as eslint from 'eslint';
import { dirname, relative } from 'path';
import minimatch from 'minimatch';

export = new class implements eslint.Rule.RuleModule {

readonly meta: eslint.Rule.RuleMetaData = {
messages: {
layerbreaker: 'You are only allowed to define limited top level functions.'
},
schema: {
type: "array",
items: {
type: "object",
additionalProperties: {
type: "array",
items: {
type: "string"
}
}
}
}
};

create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
let fileRelativePath = relative(dirname(__dirname), context.getFilename());
if (!fileRelativePath.endsWith('/')) {
fileRelativePath += '/';
}
const ruleArgs = <Record<string, string[]>>context.options[0];

const matchingKey = Object.keys(ruleArgs).find(key => fileRelativePath.startsWith(key) || minimatch(fileRelativePath, key));
if (!matchingKey) {
// nothing
return {};
}

const restrictedFunctions = ruleArgs[matchingKey];

return {
FunctionDeclaration: (node: any) => {
const isTopLevel = node.parent.type === 'Program';
const functionName = node.id.name;
if (isTopLevel && !restrictedFunctions.includes(node.id.name)) {
context.report({
node,
message: `Top-level function '${functionName}' is restricted in this file. Allowed functions are: ${restrictedFunctions.join(', ')}.`
});
}
},
ExportNamedDeclaration(node: any) {
if (node.declaration && node.declaration.type === 'FunctionDeclaration') {
const functionName = node.declaration.id.name;
const isTopLevel = node.parent.type === 'Program';
if (isTopLevel && !restrictedFunctions.includes(node.declaration.id.name)) {
context.report({
node,
message: `Top-level function '${functionName}' is restricted in this file. Allowed functions are: ${restrictedFunctions.join(', ')}.`
});
}
}
}
}
}
};
9 changes: 9 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,15 @@
"**/*"
]
}
],
"local/code-limited-top-functions": [
"error",
{
"src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts": [
"webviewPreloads",
"preloadsScriptStr"
]
}
]
}
}
Expand Down
3 changes: 3 additions & 0 deletions extensions/postinstall.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ function processRoot() {
function processLib() {
const toDelete = new Set([
'tsc.js',
'_tsc.js',

'typescriptServices.js',
'_typescriptServices.js',
]);

const libRoot = path.join(root, 'lib');
Expand Down
2 changes: 1 addition & 1 deletion extensions/typescript-language-features/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
"configuration.tsserver.web.projectWideIntellisense.suppressSemanticErrors": "Suppresses semantic errors on web even when project wide IntelliSense is enabled. This is always on when project wide IntelliSense is not enabled or available. See `#typescript.tsserver.web.projectWideIntellisense.enabled#`",
"configuration.tsserver.web.typeAcquisition.enabled": "Enable/disable package acquisition on the web. This enables IntelliSense for imported packages. Requires `#typescript.tsserver.web.projectWideIntellisense.enabled#`. Currently not supported for Safari.",
"configuration.tsserver.nodePath": "Run TS Server on a custom Node installation. This can be a path to a Node executable, or 'node' if you want VS Code to detect a Node installation.",
"configuration.updateImportsOnPaste": "Automatically update imports when pasting code. Requires TypeScript 5.6+.",
"configuration.updateImportsOnPaste": "Automatically update imports when pasting code. Requires TypeScript 5.7+.",
"configuration.expandableHover": "(Experimental) Enable/disable expanding on hover.",
"walkthroughs.nodejsWelcome.title": "Get started with JavaScript and Node.js",
"walkthroughs.nodejsWelcome.description": "Make the most of Visual Studio Code's first-class JavaScript experience.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,24 @@ class DocumentPasteProvider implements vscode.DocumentPasteEditProvider {
private readonly _client: ITypeScriptServiceClient,
) { }

prepareDocumentPaste(document: vscode.TextDocument, ranges: readonly vscode.Range[], dataTransfer: vscode.DataTransfer, _token: vscode.CancellationToken) {
async prepareDocumentPaste(document: vscode.TextDocument, ranges: readonly vscode.Range[], dataTransfer: vscode.DataTransfer, token: vscode.CancellationToken) {
if (!this.isEnabled(document)) {
return;
}

const file = this._client.toOpenTsFilePath(document);
if (!file) {
return;
}

const response = await this._client.execute('preparePasteEdits', {
file,
copiedTextSpan: ranges.map(typeConverters.Range.toTextSpan),
}, token);
if (token.isCancellationRequested || response.type !== 'response' || !response.body) {
return;
}

dataTransfer.set(DocumentPasteProvider.metadataMimeType,
new vscode.DataTransferItem(new CopyMetadata(document.uri, ranges).toJSON()));
}
Expand All @@ -62,8 +79,7 @@ class DocumentPasteProvider implements vscode.DocumentPasteEditProvider {
_context: vscode.DocumentPasteEditContext,
token: vscode.CancellationToken,
): Promise<vscode.DocumentPasteEdit[] | undefined> {
const config = vscode.workspace.getConfiguration(this._modeId, document.uri);
if (!config.get(settingId, false)) {
if (!this.isEnabled(document)) {
return;
}

Expand Down Expand Up @@ -127,12 +143,17 @@ class DocumentPasteProvider implements vscode.DocumentPasteEditProvider {

return metadata ? CopyMetadata.fromJSON(metadata) : undefined;
}

private isEnabled(document: vscode.TextDocument) {
const config = vscode.workspace.getConfiguration(this._modeId, document.uri);
return config.get(settingId, false);
}
}

export function register(selector: DocumentSelector, language: LanguageDescription, client: ITypeScriptServiceClient) {
return conditionalRegistration([
requireSomeCapability(client, ClientCapability.Semantic),
requireMinVersion(client, API.v560),
requireMinVersion(client, API.v570),
requireGlobalConfiguration(language.id, settingId),
], () => {
return vscode.languages.registerDocumentPasteEditProvider(selector.semantic, new DocumentPasteProvider(language.id, client), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export class API {
public static readonly v520 = API.fromSimpleString('5.2.0');
public static readonly v544 = API.fromSimpleString('5.4.4');
public static readonly v540 = API.fromSimpleString('5.4.0');
public static readonly v550 = API.fromSimpleString('5.5.0');
public static readonly v560 = API.fromSimpleString('5.6.0');
public static readonly v570 = API.fromSimpleString('5.7.0');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,18 @@ declare module '../../../../node_modules/typescript/lib/typescript' {
interface Response {
readonly _serverType?: ServerType;
}

//#region PreparePasteEdits
interface PreparePasteEditsRequest extends FileRequest {
command: 'preparePasteEdits';
arguments: PreparePasteEditsRequestArgs;
}
interface PreparePasteEditsRequestArgs extends FileRequestArgs {
copiedTextSpan: TextSpan[];
}
interface PreparePasteEditsResponse extends Response {
body: boolean;
}
//#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ interface StandardTsServerRequests {
'linkedEditingRange': [Proto.FileLocationRequestArgs, Proto.LinkedEditingRangeResponse];
'mapCode': [Proto.MapCodeRequestArgs, Proto.MapCodeResponse];
'getPasteEdits': [Proto.GetPasteEditsRequestArgs, Proto.GetPasteEditsResponse];
'preparePasteEdits': [Proto.PreparePasteEditsRequestArgs, Proto.PreparePasteEditsResponse];
}

interface NoResponseTsServerRequests {
Expand Down
84 changes: 42 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@
"@vscode/windows-mutex": "^0.5.0",
"@vscode/windows-process-tree": "^0.6.0",
"@vscode/windows-registry": "^1.1.0",
"@xterm/addon-clipboard": "^0.2.0-beta.47",
"@xterm/addon-image": "^0.9.0-beta.64",
"@xterm/addon-search": "^0.16.0-beta.64",
"@xterm/addon-serialize": "^0.14.0-beta.64",
"@xterm/addon-unicode11": "^0.9.0-beta.64",
"@xterm/addon-webgl": "^0.19.0-beta.64",
"@xterm/headless": "^5.6.0-beta.64",
"@xterm/xterm": "^5.6.0-beta.64",
"@xterm/addon-clipboard": "^0.2.0-beta.48",
"@xterm/addon-image": "^0.9.0-beta.65",
"@xterm/addon-search": "^0.16.0-beta.65",
"@xterm/addon-serialize": "^0.14.0-beta.65",
"@xterm/addon-unicode11": "^0.9.0-beta.65",
"@xterm/addon-webgl": "^0.19.0-beta.65",
"@xterm/headless": "^5.6.0-beta.65",
"@xterm/xterm": "^5.6.0-beta.65",
"http-proxy-agent": "^7.0.0",
"https-proxy-agent": "^7.0.2",
"jschardet": "3.1.3",
Expand All @@ -99,7 +99,7 @@
"native-is-elevated": "0.7.0",
"native-keymap": "^3.3.5",
"native-watchdog": "^1.4.1",
"node-pty": "1.1.0-beta21",
"node-pty": "^1.1.0-beta22",
"open": "^8.4.2",
"tas-client-umd": "0.2.0",
"v8-inspect-profiler": "^0.1.1",
Expand Down
Loading

0 comments on commit 9ecee04

Please sign in to comment.