diff --git a/.eslintrc.json b/.eslintrc.json index c33949be69a..7dcc958075c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -519,7 +519,8 @@ "**/vs/workbench/services/**/common/**", "**/vs/workbench/api/**/common/**", "vscode-textmate", - "vscode-oniguruma" + "vscode-oniguruma", + "iconv-lite-umd" ] }, { diff --git a/.github/commands.json b/.github/commands.json index 674eb10e5ea..45e8b89deae 100644 --- a/.github/commands.json +++ b/.github/commands.json @@ -221,6 +221,19 @@ "addLabel": "*caused-by-extension", "comment": "It looks like this is caused by the C++ extension. Please file it with the repository [here](https://github.com/Microsoft/vscode-cpptools). Make sure to check their issue reporting template and provide them relevant information such as the extension version you're using. See also our [issue reporting](https://aka.ms/vscodeissuereporting) guidelines for more information.\n\nHappy Coding!" }, + { + "type": "comment", + "name": "extCpp", + "allowUsers": [ + "cleidigh", + "usernamehw", + "gjsjohnmurray", + "IllusionMH" + ], + "action": "close", + "addLabel": "*caused-by-extension", + "comment": "It looks like this is caused by the C++ extension. Please file it with the repository [here](https://github.com/Microsoft/vscode-cpptools). Make sure to check their issue reporting template and provide them relevant information such as the extension version you're using. See also our [issue reporting](https://aka.ms/vscodeissuereporting) guidelines for more information.\n\nHappy Coding!" + }, { "type": "comment", "name": "extTS", diff --git a/.github/workflows/on-open.yml b/.github/workflows/on-open.yml index 11d498ec4c2..2d6eb4e0748 100644 --- a/.github/workflows/on-open.yml +++ b/.github/workflows/on-open.yml @@ -48,6 +48,14 @@ jobs: mustNotMatch: "^We have written the needed data into your clipboard because it was too large to send\\. Please paste\\.$" comment: "It looks like you're using the VS Code Issue Reporter but did not paste the text generated into the created issue. We've closed this issue, please open a new one containing the text we placed in your clipboard.\n\nHappy Coding!" + - name: Run Clipboard Labeler (Chinese) + uses: ./actions/regex-labeler + with: + appInsightsKey: ${{secrets.TRIAGE_ACTIONS_APP_INSIGHTS}} + label: "invalid" + mustNotMatch: "^所需的数据太大,无法直接发送。我们已经将其写入剪贴板,请粘贴。$" + comment: "看起来您正在使用 VS Code 问题报告程序,但是没有将生成的文本粘贴到创建的问题中。我们将关闭这个问题,请使用剪贴板中的内容创建一个新的问题。\n\n祝您使用愉快!" + # source of truth in ./english-please.yml - name: Run English Please uses: ./actions/english-please diff --git a/.yarnrc b/.yarnrc index 1406d749d70..4c5125d8923 100644 --- a/.yarnrc +++ b/.yarnrc @@ -1,3 +1,3 @@ disturl "https://atom.io/download/electron" -target "7.3.1" +target "8.3.3" runtime "electron" diff --git a/build/lib/i18n.js b/build/lib/i18n.js index 51c65bbed9d..def00ab6cc3 100644 --- a/build/lib/i18n.js +++ b/build/lib/i18n.js @@ -1175,9 +1175,10 @@ function createIslFile(originalFilePath, messages, language, innoSetup) { }); const basename = path.basename(originalFilePath); const filePath = `${basename}.${language.id}.isl`; + const encoded = iconv.encode(Buffer.from(content.join('\r\n'), 'utf8').toString(), innoSetup.codePage); return new File({ path: filePath, - contents: iconv.encode(Buffer.from(content.join('\r\n'), 'utf8').toString(), innoSetup.codePage) + contents: Buffer.from(encoded), }); } function encodeEntities(value) { diff --git a/build/lib/i18n.ts b/build/lib/i18n.ts index b3297263560..7e386a7fd6f 100644 --- a/build/lib/i18n.ts +++ b/build/lib/i18n.ts @@ -1339,10 +1339,11 @@ function createIslFile(originalFilePath: string, messages: Map, language const basename = path.basename(originalFilePath); const filePath = `${basename}.${language.id}.isl`; + const encoded = iconv.encode(Buffer.from(content.join('\r\n'), 'utf8').toString(), innoSetup.codePage); return new File({ path: filePath, - contents: iconv.encode(Buffer.from(content.join('\r\n'), 'utf8').toString(), innoSetup.codePage) + contents: Buffer.from(encoded), }); } diff --git a/build/package.json b/build/package.json index 3cceece5861..c56762aacad 100644 --- a/build/package.json +++ b/build/package.json @@ -38,7 +38,7 @@ "gulp-bom": "^1.0.0", "gulp-sourcemaps": "^1.11.0", "gulp-uglify": "^3.0.0", - "iconv-lite-umd": "0.6.2", + "iconv-lite-umd": "0.6.3", "mime": "^1.3.4", "minimatch": "3.0.4", "minimist": "^1.2.3", diff --git a/build/yarn.lock b/build/yarn.lock index 2219d00a035..5c1e7b954ab 100644 --- a/build/yarn.lock +++ b/build/yarn.lock @@ -1415,10 +1415,10 @@ http-signature@~1.2.0: jsprim "^1.2.2" sshpk "^1.7.0" -iconv-lite-umd@0.6.2: - version "0.6.2" - resolved "https://registry.yarnpkg.com/iconv-lite-umd/-/iconv-lite-umd-0.6.2.tgz#6410d3dc1bf5b0e0863f833d67e8168fcd52d47c" - integrity sha512-KOOIU5p4j/NOXybhgOF7ZMRMQ7+iOWwnr1+DSQaPCzCRfR1+vMzvEmjmrmUZ59kHkhcqZW7eABTa/axpc3i81w== +iconv-lite-umd@0.6.3: + version "0.6.3" + resolved "https://registry.yarnpkg.com/iconv-lite-umd/-/iconv-lite-umd-0.6.3.tgz#61307cab8ac29939992d0724d3ab8799467f0e97" + integrity sha512-fQ/8XE8reiCZ6t+SX4tX6/tQdV4tThJZv5qtMe5Sk+IWsExz0S2Zd+GiBS5IEPgDxnsmiJSpH67+qzN3FT4lKw== ignore@^5.1.1: version "5.1.2" diff --git a/cgmanifest.json b/cgmanifest.json index b1fd733d7ea..7988a56c999 100644 --- a/cgmanifest.json +++ b/cgmanifest.json @@ -6,7 +6,7 @@ "git": { "name": "chromium", "repositoryUrl": "https://chromium.googlesource.com/chromium/src", - "commitHash": "e4745133a1d3745f066e068b8033c6a269b59caf" + "commitHash": "052d3b44972e6d94ef40054d46c150b7cdd7a5d8" } }, "licenseDetail": [ @@ -40,7 +40,7 @@ "SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ], "isOnlyProductionDependency": true, - "version": "78.0.3904.130" + "version": "80.0.3987.165" }, { "component": { @@ -48,11 +48,11 @@ "git": { "name": "nodejs", "repositoryUrl": "https://github.com/nodejs/node", - "commitHash": "787378879acfb212ed4ff824bf9f767a24a5cb43a" + "commitHash": "42cce5a9d0fd905bf4ad7a2528c36572dfb8b5ad" } }, "isOnlyProductionDependency": true, - "version": "12.8.1" + "version": "12.13.0" }, { "component": { @@ -60,12 +60,12 @@ "git": { "name": "electron", "repositoryUrl": "https://github.com/electron/electron", - "commitHash": "bc8fc0d406d32e4c02f3ec9f161deaacbe4f5989" + "commitHash": "87fd06bc96bce8f46ca05b8315657fd230bcac85" } }, "isOnlyProductionDependency": true, "license": "MIT", - "version": "7.3.1" + "version": "8.3.3" }, { "component": { diff --git a/extensions/css-language-features/client/src/customData.ts b/extensions/css-language-features/client/src/customData.ts index 50540528d63..24b56f12b06 100644 --- a/extensions/css-language-features/client/src/customData.ts +++ b/extensions/css-language-features/client/src/customData.ts @@ -76,17 +76,13 @@ function getCustomDataPathsInAllWorkspaces(): string[] { function getCustomDataPathsFromAllExtensions(): string[] { const dataPaths: string[] = []; - for (const extension of extensions.all) { - const contributes = extension.packageJSON && extension.packageJSON.contributes; - - if (contributes && contributes.css && contributes.css.customData && Array.isArray(contributes.css.customData)) { - const relativePaths: string[] = contributes.css.customData; - relativePaths.forEach(rp => { + const customData = extension.packageJSON?.contributes?.css?.customData; + if (Array.isArray(customData)) { + for (const rp of customData) { dataPaths.push(joinPath(extension.extensionUri, rp).toString()); - }); + } } } - return dataPaths; } diff --git a/extensions/css-language-features/server/src/customData.ts b/extensions/css-language-features/server/src/customData.ts index 724dbf9de3f..ccfc706452c 100644 --- a/extensions/css-language-features/server/src/customData.ts +++ b/extensions/css-language-features/server/src/customData.ts @@ -29,7 +29,7 @@ function parseCSSData(source: string): ICSSDataProvider { } return newCSSDataProvider({ - version: 1, + version: rawData.version || 1, properties: rawData.properties || [], atDirectives: rawData.atDirectives || [], pseudoClasses: rawData.pseudoClasses || [], diff --git a/extensions/git/package.json b/extensions/git/package.json index 70ed49b3682..b926e802dfc 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -1878,7 +1878,7 @@ "dependencies": { "byline": "^5.0.0", "file-type": "^7.2.0", - "iconv-lite-umd": "0.6.2", + "iconv-lite-umd": "0.6.3", "jschardet": "2.1.1", "vscode-extension-telemetry": "0.1.1", "vscode-nls": "^4.0.0", diff --git a/extensions/git/yarn.lock b/extensions/git/yarn.lock index 81f05e40430..1aa042197f2 100644 --- a/extensions/git/yarn.lock +++ b/extensions/git/yarn.lock @@ -425,10 +425,10 @@ https-proxy-agent@^2.2.1: agent-base "^4.3.0" debug "^3.1.0" -iconv-lite-umd@0.6.2: - version "0.6.2" - resolved "https://registry.yarnpkg.com/iconv-lite-umd/-/iconv-lite-umd-0.6.2.tgz#6410d3dc1bf5b0e0863f833d67e8168fcd52d47c" - integrity sha512-KOOIU5p4j/NOXybhgOF7ZMRMQ7+iOWwnr1+DSQaPCzCRfR1+vMzvEmjmrmUZ59kHkhcqZW7eABTa/axpc3i81w== +iconv-lite-umd@0.6.3: + version "0.6.3" + resolved "https://registry.yarnpkg.com/iconv-lite-umd/-/iconv-lite-umd-0.6.3.tgz#61307cab8ac29939992d0724d3ab8799467f0e97" + integrity sha512-fQ/8XE8reiCZ6t+SX4tX6/tQdV4tThJZv5qtMe5Sk+IWsExz0S2Zd+GiBS5IEPgDxnsmiJSpH67+qzN3FT4lKw== inflight@^1.0.4: version "1.0.6" diff --git a/extensions/json-language-features/server/package.json b/extensions/json-language-features/server/package.json index 751e1dd5c37..eb2b984af06 100644 --- a/extensions/json-language-features/server/package.json +++ b/extensions/json-language-features/server/package.json @@ -10,7 +10,7 @@ "bin": { "vscode-json-languageserver": "./bin/vscode-json-languageserver" }, - "main": "./out/jsonServerMain", + "main": "./out/node/jsonServerMain", "dependencies": { "jsonc-parser": "^2.2.1", "request-light": "^0.3.0", diff --git a/extensions/npm/extension-browser.webpack.config.js b/extensions/npm/extension-browser.webpack.config.js new file mode 100644 index 00000000000..ab50c8718a3 --- /dev/null +++ b/extensions/npm/extension-browser.webpack.config.js @@ -0,0 +1,36 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +//@ts-check + +'use strict'; + +const withDefaults = require('../shared.webpack.config'); +const path = require('path'); + +const clientConfig = withDefaults({ + target: 'webworker', + context: __dirname, + entry: { + extension: './src/npmBrowserMain.ts' + }, + output: { + filename: 'npmBrowserMain.js' + }, + performance: { + hints: false + }, + resolve: { + alias: { + 'vscode-nls': path.resolve(__dirname, '../../build/polyfills/vscode-nls.js') + } + }, + node: { + 'child_process': 'empty' + } +}); +clientConfig.module.rules[0].use.shift(); // remove nls loader + +module.exports = clientConfig; diff --git a/extensions/npm/extension.webpack.config.js b/extensions/npm/extension.webpack.config.js index 56a1589f460..1c6d9493e33 100644 --- a/extensions/npm/extension.webpack.config.js +++ b/extensions/npm/extension.webpack.config.js @@ -14,12 +14,10 @@ const withDefaults = require('../shared.webpack.config'); module.exports = withDefaults({ context: __dirname, entry: { - extension: './src/main.ts', + extension: './src/npmMain.ts', }, output: { - filename: 'main.js', - path: path.join(__dirname, 'dist'), - libraryTarget: 'commonjs', + filename: 'npmMain.js', }, resolve: { mainFields: ['module', 'main'], diff --git a/extensions/npm/package.json b/extensions/npm/package.json index ed1e8bd9015..a80135fac28 100644 --- a/extensions/npm/package.json +++ b/extensions/npm/package.json @@ -20,14 +20,15 @@ "dependencies": { "jsonc-parser": "^2.2.1", "minimatch": "^3.0.4", - "request-light": "^0.2.5", + "request-light": "^0.4.0", "vscode-nls": "^4.1.1" }, "devDependencies": { "@types/minimatch": "^3.0.3", "@types/node": "^12.11.7" }, - "main": "./out/main", + "main": "./out/npmMain", + "browser": "./dist/npmBrowserMain", "activationEvents": [ "onCommand:workbench.action.tasks.runTask", "onCommand:npm.runScriptFromFolder", @@ -181,12 +182,12 @@ } ], "explorer/context": [ - { - "when": "config.npm.enableRunFromFolder && explorerViewletVisible && explorerResourceIsFolder", + { + "when": "config.npm.enableRunFromFolder && explorerViewletVisible && explorerResourceIsFolder", "command": "npm.runScriptFromFolder", - "group": "2_workspace" - } - ] + "group": "2_workspace" + } + ] }, "configuration": { "id": "npm", diff --git a/extensions/npm/src/features/bowerJSONContribution.ts b/extensions/npm/src/features/bowerJSONContribution.ts index 705e40d34e7..cd648732fc7 100644 --- a/extensions/npm/src/features/bowerJSONContribution.ts +++ b/extensions/npm/src/features/bowerJSONContribution.ts @@ -3,11 +3,10 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { MarkedString, CompletionItemKind, CompletionItem, DocumentSelector, SnippetString, workspace } from 'vscode'; +import { MarkdownString, CompletionItemKind, CompletionItem, DocumentSelector, SnippetString, workspace } from 'vscode'; import { IJSONContribution, ISuggestionsCollector } from './jsonContributions'; import { XHRRequest } from 'request-light'; import { Location } from 'jsonc-parser'; -import { textToMarkedString } from './markedTextUtil'; import * as nls from 'vscode-nls'; const localize = nls.loadMessageBundle(); @@ -181,13 +180,15 @@ export class BowerJSONContribution implements IJSONContribution { }); } - public getInfoContribution(_resource: string, location: Location): Thenable | null { + public getInfoContribution(_resource: string, location: Location): Thenable | null { if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']))) { const pack = location.path[location.path.length - 1]; if (typeof pack === 'string') { return this.getInfo(pack).then(documentation => { if (documentation) { - return [textToMarkedString(documentation)]; + const str = new MarkdownString(); + str.appendText(documentation); + return [str]; } return null; }); diff --git a/extensions/npm/src/features/jsonContributions.ts b/extensions/npm/src/features/jsonContributions.ts index 4a255baf823..3873b2dc31a 100644 --- a/extensions/npm/src/features/jsonContributions.ts +++ b/extensions/npm/src/features/jsonContributions.ts @@ -30,8 +30,8 @@ export interface IJSONContribution { resolveSuggestion?(item: CompletionItem): Thenable | null; } -export function addJSONProviders(xhr: XHRRequest): Disposable { - const contributions = [new PackageJSONContribution(xhr), new BowerJSONContribution(xhr)]; +export function addJSONProviders(xhr: XHRRequest, canRunNPM: boolean): Disposable { + const contributions = [new PackageJSONContribution(xhr, canRunNPM), new BowerJSONContribution(xhr)]; const subscriptions: Disposable[] = []; contributions.forEach(contribution => { const selector = contribution.getDocumentSelector(); diff --git a/extensions/npm/src/features/packageJSONContribution.ts b/extensions/npm/src/features/packageJSONContribution.ts index 4789886891c..135b632071c 100644 --- a/extensions/npm/src/features/packageJSONContribution.ts +++ b/extensions/npm/src/features/packageJSONContribution.ts @@ -3,11 +3,10 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { MarkedString, CompletionItemKind, CompletionItem, DocumentSelector, SnippetString, workspace } from 'vscode'; +import { MarkedString, CompletionItemKind, CompletionItem, DocumentSelector, SnippetString, workspace, MarkdownString } from 'vscode'; import { IJSONContribution, ISuggestionsCollector } from './jsonContributions'; import { XHRRequest } from 'request-light'; import { Location } from 'jsonc-parser'; -import { textToMarkedString } from './markedTextUtil'; import * as cp from 'child_process'; import * as nls from 'vscode-nls'; @@ -28,14 +27,12 @@ export class PackageJSONContribution implements IJSONContribution { 'jsdom', 'stylus', 'when', 'readable-stream', 'aws-sdk', 'concat-stream', 'chai', 'Thenable', 'wrench']; private knownScopes = ['@types', '@angular', '@babel', '@nuxtjs', '@vue', '@bazel']; - private xhr: XHRRequest; public getDocumentSelector(): DocumentSelector { return [{ language: 'json', scheme: '*', pattern: '**/package.json' }]; } - public constructor(xhr: XHRRequest) { - this.xhr = xhr; + public constructor(private xhr: XHRRequest, private canRunNPM: boolean) { } public collectDefaultSuggestions(_fileName: string, result: ISuggestionsCollector): Thenable { @@ -191,23 +188,23 @@ export class PackageJSONContribution implements IJSONContribution { const currentKey = location.path[location.path.length - 1]; if (typeof currentKey === 'string') { const info = await this.fetchPackageInfo(currentKey); - if (info && info.distTagsLatest) { + if (info && info.version) { - let name = JSON.stringify(info.distTagsLatest); + let name = JSON.stringify(info.version); let proposal = new CompletionItem(name); proposal.kind = CompletionItemKind.Property; proposal.insertText = name; proposal.documentation = localize('json.npm.latestversion', 'The currently latest version of the package'); result.add(proposal); - name = JSON.stringify('^' + info.distTagsLatest); + name = JSON.stringify('^' + info.version); proposal = new CompletionItem(name); proposal.kind = CompletionItemKind.Property; proposal.insertText = name; proposal.documentation = localize('json.npm.majorversion', 'Matches the most recent major version (1.x.x)'); result.add(proposal); - name = JSON.stringify('~' + info.distTagsLatest); + name = JSON.stringify('~' + info.version); proposal = new CompletionItem(name); proposal.kind = CompletionItemKind.Property; proposal.insertText = name; @@ -219,14 +216,27 @@ export class PackageJSONContribution implements IJSONContribution { return null; } + private getDocumentation(description: string | undefined, version: string | undefined, homepage: string | undefined): MarkdownString { + const str = new MarkdownString(); + if (description) { + str.appendText(description); + } + if (version) { + str.appendText('\n\n'); + str.appendText(localize('json.npm.version.hover', 'Latest version: {0}', version)); + } + if (homepage) { + str.appendText('\n\n'); + str.appendText(homepage); + } + return str; + } + public resolveSuggestion(item: CompletionItem): Thenable | null { - if (item.kind === CompletionItemKind.Property && item.documentation === '') { - return this.getInfo(item.label).then(infos => { - if (infos.length > 0) { - item.documentation = infos[0]; - if (infos.length > 1) { - item.detail = infos[1]; - } + if (item.kind === CompletionItemKind.Property && !item.documentation) { + return this.fetchPackageInfo(item.label).then(info => { + if (info) { + item.documentation = this.getDocumentation(info.description, info.version, info.homepage); return item; } return null; @@ -235,21 +245,11 @@ export class PackageJSONContribution implements IJSONContribution { return null; } - private async getInfo(pack: string): Promise { - let info = await this.fetchPackageInfo(pack); - if (info) { - const result: string[] = []; - result.push(info.description || ''); - result.push(info.distTagsLatest ? localize('json.npm.version.hover', 'Latest version: {0}', info.distTagsLatest) : ''); - result.push(info.homepage || ''); - return result; - } - - return []; - } - private async fetchPackageInfo(pack: string): Promise { - let info = await this.npmView(pack); + let info: ViewPackageInfo | undefined; + if (this.canRunNPM) { + info = await this.npmView(pack); + } if (!info) { info = await this.npmjsView(pack); } @@ -259,14 +259,14 @@ export class PackageJSONContribution implements IJSONContribution { private npmView(pack: string): Promise { return new Promise((resolve, _reject) => { - const command = 'npm view --json ' + pack + ' description dist-tags.latest homepage'; + const command = 'npm view --json ' + pack + ' description dist-tags.latest homepage version'; cp.exec(command, (error, stdout) => { if (!error) { try { const content = JSON.parse(stdout); resolve({ description: content['description'], - distTagsLatest: content['dist-tags.latest'], + version: content['dist-tags.latest'] || content['version'], homepage: content['homepage'] }); return; @@ -280,22 +280,20 @@ export class PackageJSONContribution implements IJSONContribution { } private async npmjsView(pack: string): Promise { - const queryUrl = 'https://registry.npmjs.org/' + encodeURIComponent(pack).replace(/%40/g, '@'); + const queryUrl = 'https://api.npms.io/v2/package/' + encodeURIComponent(pack); try { const success = await this.xhr({ url: queryUrl, agent: USER_AGENT }); const obj = JSON.parse(success.responseText); - if (obj) { - const latest = obj && obj['dist-tags'] && obj['dist-tags']['latest']; - if (latest) { - return { - description: obj.description || '', - distTagsLatest: latest, - homepage: obj.homepage || '' - }; - } + const metadata = obj?.collected?.metadata; + if (metadata) { + return { + description: metadata.description || '', + version: metadata.version, + homepage: metadata.links?.homepage || '' + }; } } catch (e) { @@ -308,9 +306,9 @@ export class PackageJSONContribution implements IJSONContribution { if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) { const pack = location.path[location.path.length - 1]; if (typeof pack === 'string') { - return this.getInfo(pack).then(infos => { - if (infos.length) { - return [infos.map(textToMarkedString).join('\n\n')]; + return this.fetchPackageInfo(pack).then(info => { + if (info) { + return [this.getDocumentation(info.description, info.version, info.homepage)]; } return null; }); @@ -339,7 +337,7 @@ export class PackageJSONContribution implements IJSONContribution { proposal.kind = CompletionItemKind.Property; proposal.insertText = insertText; proposal.filterText = JSON.stringify(name); - proposal.documentation = pack.description || ''; + proposal.documentation = this.getDocumentation(pack.description, pack.version, pack?.links?.homepage); collector.add(proposal); } } @@ -349,10 +347,11 @@ interface SearchPackageInfo { name: string; description?: string; version?: string; + links?: { homepage?: string; }; } interface ViewPackageInfo { description: string; - distTagsLatest?: string; + version?: string; homepage?: string; } diff --git a/extensions/npm/src/features/markedTextUtil.ts b/extensions/npm/src/npmBrowserMain.ts similarity index 51% rename from extensions/npm/src/features/markedTextUtil.ts rename to extensions/npm/src/npmBrowserMain.ts index 856fad050e5..96cfe579505 100644 --- a/extensions/npm/src/features/markedTextUtil.ts +++ b/extensions/npm/src/npmBrowserMain.ts @@ -3,8 +3,13 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { MarkedString } from 'vscode'; +import * as httpRequest from 'request-light'; +import * as vscode from 'vscode'; +import { addJSONProviders } from './features/jsonContributions'; -export function textToMarkedString(text: string): MarkedString { - return text.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&'); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash -} \ No newline at end of file +export async function activate(context: vscode.ExtensionContext): Promise { + context.subscriptions.push(addJSONProviders(httpRequest.xhr, false)); +} + +export function deactivate(): void { +} diff --git a/extensions/npm/src/main.ts b/extensions/npm/src/npmMain.ts similarity index 86% rename from extensions/npm/src/main.ts rename to extensions/npm/src/npmMain.ts index b79638ed1f0..764be6ea0fc 100644 --- a/extensions/npm/src/main.ts +++ b/extensions/npm/src/npmMain.ts @@ -14,13 +14,19 @@ import { invalidateHoverScriptsCache, NpmScriptHoverProvider } from './scriptHov let treeDataProvider: NpmScriptsTreeDataProvider | undefined; export async function activate(context: vscode.ExtensionContext): Promise { - registerTaskProvider(context); - treeDataProvider = registerExplorer(context); - registerHoverProvider(context); - configureHttpRequest(); - let d = vscode.workspace.onDidChangeConfiguration((e) => { - configureHttpRequest(); + context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => { + if (e.affectsConfiguration('http.proxy') || e.affectsConfiguration('http.proxyStrictSSL')) { + configureHttpRequest(); + } + })); + + const canRunNPM = canRunNpmInCurrentWorkspace(); + context.subscriptions.push(addJSONProviders(httpRequest.xhr, canRunNPM)); + + treeDataProvider = registerExplorer(context); + + context.subscriptions.push(vscode.workspace.onDidChangeConfiguration((e) => { if (e.affectsConfiguration('npm.exclude') || e.affectsConfiguration('npm.autoDetect')) { invalidateTasksCache(); if (treeDataProvider) { @@ -32,15 +38,12 @@ export async function activate(context: vscode.ExtensionContext): Promise treeDataProvider.refresh(); } } - }); - context.subscriptions.push(d); + })); + + registerTaskProvider(context); + registerHoverProvider(context); - d = vscode.workspace.onDidChangeTextDocument((e) => { - invalidateHoverScriptsCache(e.document); - }); - context.subscriptions.push(d); context.subscriptions.push(vscode.commands.registerCommand('npm.runSelectedScript', runSelectedScript)); - context.subscriptions.push(addJSONProviders(httpRequest.xhr)); if (await hasPackageJson()) { vscode.commands.executeCommand('setContext', 'npm:showScriptExplorer', true); @@ -49,6 +52,13 @@ export async function activate(context: vscode.ExtensionContext): Promise context.subscriptions.push(vscode.commands.registerCommand('npm.runScriptFromFolder', selectAndRunScriptFromFolder)); } +function canRunNpmInCurrentWorkspace() { + if (vscode.workspace.workspaceFolders) { + return vscode.workspace.workspaceFolders.some(f => f.uri.scheme === 'file'); + } + return false; +} + function registerTaskProvider(context: vscode.ExtensionContext): vscode.Disposable | undefined { function invalidateScriptCaches() { diff --git a/extensions/npm/src/scriptHover.ts b/extensions/npm/src/scriptHover.ts index 46992af2088..aa803dbc1d4 100644 --- a/extensions/npm/src/scriptHover.ts +++ b/extensions/npm/src/scriptHover.ts @@ -32,6 +32,9 @@ export class NpmScriptHoverProvider implements HoverProvider { constructor(context: ExtensionContext) { context.subscriptions.push(commands.registerCommand('npm.runScriptFromHover', this.runScriptFromHover, this)); context.subscriptions.push(commands.registerCommand('npm.debugScriptFromHover', this.debugScriptFromHover, this)); + context.subscriptions.push(workspace.onDidChangeTextDocument((e) => { + invalidateHoverScriptsCache(e.document); + })); } public provideHover(document: TextDocument, position: Position, _token: CancellationToken): ProviderResult { diff --git a/extensions/npm/yarn.lock b/extensions/npm/yarn.lock index 9b8a23c9264..5e85de9297e 100644 --- a/extensions/npm/yarn.lock +++ b/extensions/npm/yarn.lock @@ -71,7 +71,7 @@ http-proxy-agent@^2.1.0: agent-base "4" debug "3.1.0" -https-proxy-agent@^2.2.3: +https-proxy-agent@^2.2.4: version "2.2.4" resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz#4ee7a737abd92678a293d9b34a1af4d0d08c787b" integrity sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg== @@ -96,16 +96,21 @@ ms@2.0.0: resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= -request-light@^0.2.5: - version "0.2.5" - resolved "https://registry.yarnpkg.com/request-light/-/request-light-0.2.5.tgz#38a3da7b2e56f7af8cbba57e8a94930ee2380746" - integrity sha512-eBEh+GzJAftUnex6tcL6eV2JCifY0+sZMIUpUPOVXbs2nV5hla4ZMmO3icYKGuGVuQ2zHE9evh4OrRcH4iyYYw== +request-light@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/request-light/-/request-light-0.4.0.tgz#c6b91ef00b18cb0de75d2127e55b3a2c9f7f90f9" + integrity sha512-fimzjIVw506FBZLspTAXHdpvgvQebyjpNyLRd0e6drPPRq7gcrROeGWRyF81wLqFg5ijPgnOQbmfck5wdTqpSA== dependencies: http-proxy-agent "^2.1.0" - https-proxy-agent "^2.2.3" - vscode-nls "^4.1.1" + https-proxy-agent "^2.2.4" + vscode-nls "^4.1.2" vscode-nls@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-4.1.1.tgz#f9916b64e4947b20322defb1e676a495861f133c" integrity sha512-4R+2UoUUU/LdnMnFjePxfLqNhBS8lrAFyX7pjb2ud/lqDkrUavFUTcG7wR0HBZFakae0Q6KLBFjMS6W93F403A== + +vscode-nls@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-4.1.2.tgz#ca8bf8bb82a0987b32801f9fddfdd2fb9fd3c167" + integrity sha512-7bOHxPsfyuCqmP+hZXscLhiHwe7CSuFE4hyhbs22xPIhQ4jv99FcR4eBzfYYVLP356HNFpdvz63FFb/xw6T4Iw== diff --git a/package.json b/package.json index 57b0c76ab6f..c925d7cb74d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "code-oss-dev", "version": "1.47.0", - "distro": "9521a559bbdc4e0fb1de84f14deb16cf56e7fdfa", + "distro": "6eb887883773e6b33879837bdf8dda3340a9fa75", "author": { "name": "Microsoft Corporation" }, @@ -41,7 +41,7 @@ "graceful-fs": "4.2.3", "http-proxy-agent": "^2.1.0", "https-proxy-agent": "^2.2.3", - "iconv-lite-umd": "0.6.2", + "iconv-lite-umd": "0.6.3", "jschardet": "2.1.1", "keytar": "^5.5.0", "minimist": "^1.2.5", @@ -98,7 +98,7 @@ "css-loader": "^3.2.0", "debounce": "^1.0.0", "deemon": "^1.4.0", - "electron": "7.3.1", + "electron": "8.3.3", "eslint": "6.8.0", "eslint-plugin-jsdoc": "^19.1.0", "event-stream": "3.3.4", diff --git a/remote/package.json b/remote/package.json index bc1091427f0..4264ccb2a11 100644 --- a/remote/package.json +++ b/remote/package.json @@ -8,7 +8,7 @@ "graceful-fs": "4.2.3", "http-proxy-agent": "^2.1.0", "https-proxy-agent": "^2.2.3", - "iconv-lite-umd": "0.6.2", + "iconv-lite-umd": "0.6.3", "jschardet": "2.1.1", "minimist": "^1.2.5", "native-watchdog": "1.3.0", diff --git a/remote/web/package.json b/remote/web/package.json index 52ab34a220c..51feaf5cd2d 100644 --- a/remote/web/package.json +++ b/remote/web/package.json @@ -3,6 +3,8 @@ "version": "0.0.0", "dependencies": { "semver-umd": "^5.5.7", + "iconv-lite-umd": "0.6.3", + "jschardet": "2.1.1", "vscode-oniguruma": "1.3.1", "vscode-textmate": "5.1.1", "xterm": "4.7.0-beta.3", diff --git a/remote/web/yarn.lock b/remote/web/yarn.lock index 6e53d5b53e2..55c51a387bd 100644 --- a/remote/web/yarn.lock +++ b/remote/web/yarn.lock @@ -2,6 +2,16 @@ # yarn lockfile v1 +iconv-lite-umd@0.6.3: + version "0.6.3" + resolved "https://registry.yarnpkg.com/iconv-lite-umd/-/iconv-lite-umd-0.6.3.tgz#61307cab8ac29939992d0724d3ab8799467f0e97" + integrity sha512-fQ/8XE8reiCZ6t+SX4tX6/tQdV4tThJZv5qtMe5Sk+IWsExz0S2Zd+GiBS5IEPgDxnsmiJSpH67+qzN3FT4lKw== + +jschardet@2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/jschardet/-/jschardet-2.1.1.tgz#af6f8fd0b3b0f5d46a8fd9614a4fce490575c184" + integrity sha512-pA5qG9Zwm8CBpGlK/lo2GE9jPxwqRgMV7Lzc/1iaPccw6v4Rhj8Zg2BTyrdmHmxlJojnbLupLeRnaPLsq03x6Q== + semver-umd@^5.5.7: version "5.5.7" resolved "https://registry.yarnpkg.com/semver-umd/-/semver-umd-5.5.7.tgz#966beb5e96c7da6fbf09c3da14c2872d6836c528" diff --git a/remote/yarn.lock b/remote/yarn.lock index eb1e14d6df2..d96f13682aa 100644 --- a/remote/yarn.lock +++ b/remote/yarn.lock @@ -176,10 +176,10 @@ https-proxy-agent@^2.2.3: agent-base "^4.3.0" debug "^3.1.0" -iconv-lite-umd@0.6.2: - version "0.6.2" - resolved "https://registry.yarnpkg.com/iconv-lite-umd/-/iconv-lite-umd-0.6.2.tgz#6410d3dc1bf5b0e0863f833d67e8168fcd52d47c" - integrity sha512-KOOIU5p4j/NOXybhgOF7ZMRMQ7+iOWwnr1+DSQaPCzCRfR1+vMzvEmjmrmUZ59kHkhcqZW7eABTa/axpc3i81w== +iconv-lite-umd@0.6.3: + version "0.6.3" + resolved "https://registry.yarnpkg.com/iconv-lite-umd/-/iconv-lite-umd-0.6.3.tgz#61307cab8ac29939992d0724d3ab8799467f0e97" + integrity sha512-fQ/8XE8reiCZ6t+SX4tX6/tQdV4tThJZv5qtMe5Sk+IWsExz0S2Zd+GiBS5IEPgDxnsmiJSpH67+qzN3FT4lKw== ip@^1.1.5: version "1.1.5" diff --git a/resources/serverless/code-web.js b/resources/serverless/code-web.js index 17a23a5bb26..3f35bea7bc8 100644 --- a/resources/serverless/code-web.js +++ b/resources/serverless/code-web.js @@ -91,13 +91,13 @@ async function initialize() { const packageJSONPath = path.join(EXTENSIONS_ROOT, folderName, 'package.json'); if (await exists(packageJSONPath)) { try { - const manifest = JSON.parse((await readFile(packageJSONPath)).toString()); - if (manifest.main && !manifest.browser) { + const packageJSON = JSON.parse((await readFile(packageJSONPath)).toString()); + if (packageJSON.main && !packageJSON.browser) { return; // unsupported } - if (manifest.browser) { - manifest.main = manifest.browser; + if (packageJSON.browser) { + packageJSON.main = packageJSON.browser; const webpackConfigLocations = await util.promisify(glob)( path.join(EXTENSIONS_ROOT, folderName, '**', 'extension-browser.webpack.config.js'), @@ -117,31 +117,14 @@ async function initialize() { } } - const packageNlsPath = path.join(EXTENSIONS_ROOT, folderName, 'package.nls.json'); - if (await exists(packageNlsPath)) { - const packageNls = JSON.parse((await readFile(packageNlsPath)).toString()); - const translate = (obj) => { - for (let key in obj) { - const val = obj[key]; - if (Array.isArray(val)) { - val.forEach(translate); - } else if (val && typeof val === 'object') { - translate(val); - } else if (typeof val === 'string' && val.charCodeAt(0) === CharCode_PC && val.charCodeAt(val.length - 1) === CharCode_PC) { - const translated = packageNls[val.substr(1, val.length - 2)]; - if (translated) { - obj[key] = translated; - } - } - } - }; - translate(manifest); - } - manifest.extensionKind = ['web']; // enable for Web + packageJSON.extensionKind = ['web']; // enable for Web + + const packageNLSPath = path.join(folderName, 'package.nls.json'); + const packageNLSExists = await exists(path.join(EXTENSIONS_ROOT, packageNLSPath)); builtinExtensions.push({ - identifier: { id: `${manifest.publisher}.${manifest.name}`}, - manifest, + packageJSON, location: toStaticExtensionUri(folderName), + packageNLSUrl: packageNLSExists ? toStaticExtensionUri(packageNLSPath) : undefined, readmeUrl, changelogUrl }); diff --git a/resources/win32/bin/code.sh b/resources/win32/bin/code.sh index c751647f2ec..4fbdd0a3b51 100644 --- a/resources/win32/bin/code.sh +++ b/resources/win32/bin/code.sh @@ -15,7 +15,7 @@ VSCODE_PATH="$(dirname "$(dirname "$(realpath "$0")")")" ELECTRON="$VSCODE_PATH/$NAME.exe" if grep -qi Microsoft /proc/version; then # in a wsl shell - WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft.*|([0-9]+).([0-9]+).([0-9]+)-microsoft-standard.*|.*/\1\2\3\4/') + WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft.*|([0-9]+).([0-9]+).([0-9]+)-microsoft.*|.*/\1\2\3\4/') if [ -z "$WSL_BUILD" ]; then WSL_BUILD=0 fi @@ -30,17 +30,9 @@ if grep -qi Microsoft /proc/version; then # use the Remote WSL extension if installed WSL_EXT_ID="ms-vscode-remote.remote-wsl" - if [ $WSL_BUILD -ge 41955 -a $WSL_BUILD -lt 41959 ]; then - # WSL2 workaround for https://github.com/microsoft/WSL/issues/4337 - CWD="$(pwd)" - cd "$VSCODE_PATH" - cmd.exe /C ".\\bin\\$APP_NAME.cmd --locate-extension $WSL_EXT_ID >%TEMP%\\remote-wsl-loc.txt" - WSL_EXT_WLOC=$(cmd.exe /C type %TEMP%\\remote-wsl-loc.txt) - cd "$CWD" - else - ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID >/tmp/remote-wsl-loc.txt 2>/dev/null - WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt) - fi + ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID >/tmp/remote-wsl-loc.txt 2>/dev/null + WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt) + if [ -n "$WSL_EXT_WLOC" ]; then # replace \r\n with \n in WSL_EXT_WLOC WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh diff --git a/src/vs/base/parts/contextmenu/electron-main/contextmenu.ts b/src/vs/base/parts/contextmenu/electron-main/contextmenu.ts index 6222be78028..7b43355ed6d 100644 --- a/src/vs/base/parts/contextmenu/electron-main/contextmenu.ts +++ b/src/vs/base/parts/contextmenu/electron-main/contextmenu.ts @@ -9,9 +9,10 @@ import { ISerializableContextMenuItem, CONTEXT_MENU_CLOSE_CHANNEL, CONTEXT_MENU_ export function registerContextMenuListener(): void { ipcMain.on(CONTEXT_MENU_CHANNEL, (event: IpcMainEvent, contextMenuId: number, items: ISerializableContextMenuItem[], onClickChannel: string, options?: IPopupOptions) => { const menu = createMenu(event, onClickChannel, items); + const window = BrowserWindow.fromWebContents(event.sender); menu.popup({ - window: BrowserWindow.fromWebContents(event.sender), + window: window ? window : undefined, x: options ? options.x : undefined, y: options ? options.y : undefined, positioningItem: options ? options.positioningItem : undefined, diff --git a/src/vs/code/browser/workbench/workbench-dev.html b/src/vs/code/browser/workbench/workbench-dev.html index 56287aee144..b91569fe60b 100644 --- a/src/vs/code/browser/workbench/workbench-dev.html +++ b/src/vs/code/browser/workbench/workbench-dev.html @@ -37,6 +37,8 @@ 'xterm-addon-unicode11': `${window.location.origin}/static/remote/web/node_modules/xterm-addon-unicode11/lib/xterm-addon-unicode11.js`, 'xterm-addon-webgl': `${window.location.origin}/static/remote/web/node_modules/xterm-addon-webgl/lib/xterm-addon-webgl.js`, 'semver-umd': `${window.location.origin}/static/remote/web/node_modules/semver-umd/lib/semver-umd.js`, + 'iconv-lite-umd': `${window.location.origin}/static/remote/web/node_modules/iconv-lite-umd/lib/iconv-lite-umd.js`, + 'jschardet': `${window.location.origin}/static/remote/web/node_modules/jschardet/dist/jschardet.min.js`, } }; diff --git a/src/vs/code/browser/workbench/workbench.html b/src/vs/code/browser/workbench/workbench.html index f0e5267f130..c68730498de 100644 --- a/src/vs/code/browser/workbench/workbench.html +++ b/src/vs/code/browser/workbench/workbench.html @@ -23,6 +23,8 @@ + + @@ -41,6 +43,8 @@ 'xterm-addon-unicode11': `${window.location.origin}/static/node_modules/xterm-addon-unicode11/lib/xterm-addon-unicode11.js`, 'xterm-addon-webgl': `${window.location.origin}/static/node_modules/xterm-addon-webgl/lib/xterm-addon-webgl.js`, 'semver-umd': `${window.location.origin}/static/node_modules/semver-umd/lib/semver-umd.js`, + 'iconv-lite-umd': `${window.location.origin}/static/node_modules/iconv-lite-umd/lib/iconv-lite-umd.js`, + 'jschardet': `${window.location.origin}/static/node_modules/jschardet/dist/jschardet.min.js`, } }; diff --git a/src/vs/editor/browser/controller/coreCommands.ts b/src/vs/editor/browser/controller/coreCommands.ts index f56dff9bd9f..2013ad47528 100644 --- a/src/vs/editor/browser/controller/coreCommands.ts +++ b/src/vs/editor/browser/controller/coreCommands.ts @@ -7,7 +7,7 @@ import * as nls from 'vs/nls'; import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import * as types from 'vs/base/common/types'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { Command, EditorCommand, ICommandOptions, registerEditorCommand } from 'vs/editor/browser/editorExtensions'; +import { Command, EditorCommand, ICommandOptions, registerEditorCommand, MultiCommand, UndoCommand, RedoCommand, SelectAllCommand } from 'vs/editor/browser/editorExtensions'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { ColumnSelection, IColumnSelectResult } from 'vs/editor/common/controller/cursorColumnSelection'; import { CursorState, EditOperationType, IColumnSelectData, PartialCursorState } from 'vs/editor/common/controller/cursorCommon'; @@ -20,7 +20,6 @@ import { Range } from 'vs/editor/common/core/range'; import { Handler, ScrollType } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { VerticalRevealType } from 'vs/editor/common/view/viewEvents'; -import { MenuId } from 'vs/platform/actions/common/actions'; import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; @@ -276,6 +275,48 @@ export namespace RevealLine_ { }; } +abstract class EditorOrNativeTextInputCommand { + + constructor(target: MultiCommand) { + // 1. handle case when focus is in editor. + target.addImplementation(10000, (accessor: ServicesAccessor, args: any) => { + // Only if editor text focus (i.e. not if editor has widget focus). + const focusedEditor = accessor.get(ICodeEditorService).getFocusedCodeEditor(); + if (focusedEditor && focusedEditor.hasTextFocus()) { + this.runEditorCommand(accessor, focusedEditor, args); + return true; + } + return false; + }); + + // 2. handle case when focus is in some other `input` / `textarea`. + target.addImplementation(1000, (accessor: ServicesAccessor, args: any) => { + // Only if focused on an element that allows for entering text + const activeElement = document.activeElement; + if (activeElement && ['input', 'textarea'].indexOf(activeElement.tagName.toLowerCase()) >= 0) { + this.runDOMCommand(); + return true; + } + return false; + }); + + // 3. (default) handle case when focus is somewhere else. + target.addImplementation(0, (accessor: ServicesAccessor, args: any) => { + // Redirecting to active editor + const activeEditor = accessor.get(ICodeEditorService).getActiveCodeEditor(); + if (activeEditor) { + activeEditor.focus(); + this.runEditorCommand(accessor, activeEditor, args); + return true; + } + return false; + }); + } + + public abstract runDOMCommand(): void; + public abstract runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: any): void; +} + export namespace CoreNavigationCommands { class BaseMoveToCommand extends CoreEditorCommand { @@ -1594,25 +1635,32 @@ export namespace CoreNavigationCommands { } }); - export const SelectAll: CoreEditorCommand = registerEditorCommand(new class extends CoreEditorCommand { + export const SelectAll = new class extends EditorOrNativeTextInputCommand { constructor() { - super({ - id: 'selectAll', - precondition: undefined - }); + super(SelectAllCommand); + } + public runDOMCommand(): void { + document.execCommand('selectAll'); + } + public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void { + const viewModel = editor._getViewModel(); + if (!viewModel) { + // the editor has no view => has no cursors + return; + } + this.runCoreEditorCommand(viewModel, args); } - public runCoreEditorCommand(viewModel: IViewModel, args: any): void { viewModel.model.pushStackElement(); viewModel.setCursorStates( - args.source, + 'keyboard', CursorChangeReason.Explicit, [ CursorMoveCommands.selectAll(viewModel, viewModel.getPrimaryCursorState()) ] ); } - }); + }(); export const SetSelection: CoreEditorCommand = registerEditorCommand(new class extends CoreEditorCommand { constructor() { @@ -1655,97 +1703,6 @@ registerColumnSelection(CoreNavigationCommands.CursorColumnSelectPageUp.id, KeyM registerColumnSelection(CoreNavigationCommands.CursorColumnSelectDown.id, KeyMod.Shift | KeyCode.DownArrow); registerColumnSelection(CoreNavigationCommands.CursorColumnSelectPageDown.id, KeyMod.Shift | KeyCode.PageDown); -/** - * A command that will: - * 1. invoke a command on the focused editor. - * 2. otherwise, invoke a browser built-in command on the `activeElement`. - * 3. otherwise, invoke a command on the workbench active editor. - */ -abstract class EditorOrNativeTextInputCommand extends Command { - - public runCommand(accessor: ServicesAccessor, args: any): void { - - const focusedEditor = accessor.get(ICodeEditorService).getFocusedCodeEditor(); - // Only if editor text focus (i.e. not if editor has widget focus). - if (focusedEditor && focusedEditor.hasTextFocus()) { - return this.runEditorCommand(accessor, focusedEditor, args); - } - - // Ignore this action when user is focused on an element that allows for entering text - const activeElement = document.activeElement; - if (activeElement && ['input', 'textarea'].indexOf(activeElement.tagName.toLowerCase()) >= 0) { - return this.runDOMCommand(); - } - - // Redirecting to active editor - const activeEditor = accessor.get(ICodeEditorService).getActiveCodeEditor(); - if (activeEditor) { - activeEditor.focus(); - return this.runEditorCommand(accessor, activeEditor, args); - } - } - - public abstract runDOMCommand(): void; - public abstract runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void; -} - -class SelectAllCommand extends EditorOrNativeTextInputCommand { - constructor() { - super({ - id: 'editor.action.selectAll', - precondition: EditorContextKeys.textInputFocus, - kbOpts: { - weight: CORE_WEIGHT, - kbExpr: null, - primary: KeyMod.CtrlCmd | KeyCode.KEY_A - }, - menuOpts: [{ - menuId: MenuId.MenubarSelectionMenu, - group: '1_basic', - title: nls.localize({ key: 'miSelectAll', comment: ['&& denotes a mnemonic'] }, "&&Select All"), - order: 1 - }, { - menuId: MenuId.CommandPalette, - group: '', - title: nls.localize('selectAll', "Select All"), - order: 1 - }] - }); - } - public runDOMCommand(): void { - document.execCommand('selectAll'); - } - public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void { - args = args || {}; - args.source = 'keyboard'; - CoreNavigationCommands.SelectAll.runEditorCommand(accessor, editor, args); - } -} - -class UndoCommand extends EditorOrNativeTextInputCommand { - public runDOMCommand(): void { - document.execCommand('undo'); - } - public runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: any): void { - if (!editor.hasModel() || editor.getOption(EditorOption.readOnly) === true) { - return; - } - editor.getModel().undo(); - } -} - -class RedoCommand extends EditorOrNativeTextInputCommand { - public runDOMCommand(): void { - document.execCommand('redo'); - } - public runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: any): void { - if (!editor.hasModel() || editor.getOption(EditorOption.readOnly) === true) { - return; - } - editor.getModel().redo(); - } -} - function registerCommand(command: T): T { command.register(); return command; @@ -1881,53 +1838,35 @@ export namespace CoreEditingCommands { } }); - export const Undo: UndoCommand = registerCommand(new UndoCommand({ - id: 'undo', - precondition: EditorContextKeys.writable, - kbOpts: { - weight: CORE_WEIGHT, - kbExpr: EditorContextKeys.textInputFocus, - primary: KeyMod.CtrlCmd | KeyCode.KEY_Z - }, - menuOpts: [{ - menuId: MenuId.MenubarEditMenu, - group: '1_do', - title: nls.localize({ key: 'miUndo', comment: ['&& denotes a mnemonic'] }, "&&Undo"), - order: 1 - }, { - menuId: MenuId.CommandPalette, - group: '', - title: nls.localize('undo', "Undo"), - order: 1 - }] - })); + export const Undo = new class extends EditorOrNativeTextInputCommand { + constructor() { + super(UndoCommand); + } + public runDOMCommand(): void { + document.execCommand('undo'); + } + public runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: any): void { + if (!editor.hasModel() || editor.getOption(EditorOption.readOnly) === true) { + return; + } + editor.getModel().undo(); + } + }(); - export const DefaultUndo: UndoCommand = registerCommand(new UndoCommand({ id: 'default:undo', precondition: EditorContextKeys.writable })); - - export const Redo: RedoCommand = registerCommand(new RedoCommand({ - id: 'redo', - precondition: EditorContextKeys.writable, - kbOpts: { - weight: CORE_WEIGHT, - kbExpr: EditorContextKeys.textInputFocus, - primary: KeyMod.CtrlCmd | KeyCode.KEY_Y, - secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z], - mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z } - }, - menuOpts: [{ - menuId: MenuId.MenubarEditMenu, - group: '1_do', - title: nls.localize({ key: 'miRedo', comment: ['&& denotes a mnemonic'] }, "&&Redo"), - order: 2 - }, { - menuId: MenuId.CommandPalette, - group: '', - title: nls.localize('redo', "Redo"), - order: 1 - }] - })); - - export const DefaultRedo: RedoCommand = registerCommand(new RedoCommand({ id: 'default:redo', precondition: EditorContextKeys.writable })); + export const Redo = new class extends EditorOrNativeTextInputCommand { + constructor() { + super(RedoCommand); + } + public runDOMCommand(): void { + document.execCommand('redo'); + } + public runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: any): void { + if (!editor.hasModel() || editor.getOption(EditorOption.readOnly) === true) { + return; + } + editor.getModel().redo(); + } + }(); } /** @@ -1956,8 +1895,6 @@ class EditorHandlerCommand extends Command { } } -registerCommand(new SelectAllCommand()); - function registerOverwritableCommand(handlerId: string, description?: ICommandHandlerDescription): void { registerCommand(new EditorHandlerCommand('default:' + handlerId, handlerId)); registerCommand(new EditorHandlerCommand(handlerId, handlerId, description)); diff --git a/src/vs/editor/browser/editorExtensions.ts b/src/vs/editor/browser/editorExtensions.ts index faf4f3ebc8d..50a7f678d5a 100644 --- a/src/vs/editor/browser/editorExtensions.ts +++ b/src/vs/editor/browser/editorExtensions.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import * as nls from 'vs/nls'; import { IPosition } from 'vs/base/browser/ui/contextview/contextview'; import { illegalArgument } from 'vs/base/common/errors'; import { URI } from 'vs/base/common/uri'; @@ -17,11 +18,13 @@ import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions'; import { CommandsRegistry, ICommandHandlerDescription } from 'vs/platform/commands/common/commands'; import { ContextKeyExpr, IContextKeyService, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey'; import { IConstructorSignature1, ServicesAccessor as InstantiationServicesAccessor, BrandedService } from 'vs/platform/instantiation/common/instantiation'; -import { IKeybindings, KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; +import { IKeybindings, KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { Registry } from 'vs/platform/registry/common/platform'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { withNullAsUndefined, assertType } from 'vs/base/common/types'; import { ThemeIcon } from 'vs/platform/theme/common/themeService'; +import { IDisposable } from 'vs/base/common/lifecycle'; +import { KeyMod, KeyCode } from 'vs/base/common/keyCodes'; export type ServicesAccessor = InstantiationServicesAccessor; @@ -139,6 +142,66 @@ export abstract class Command { //#endregion Command +//#region MultiplexingCommand + +/** + * Potential override for a command. + * + * @return `true` if the command was successfully run. This stops other overrides from being executed. + */ +export type CommandImplementation = (accessor: ServicesAccessor, args: unknown) => boolean; + +export class MultiCommand extends Command { + + private readonly _implementations: [number, CommandImplementation][] = []; + + /** + * A higher priority gets to be looked at first + */ + public addImplementation(priority: number, implementation: CommandImplementation): IDisposable { + this._implementations.push([priority, implementation]); + this._implementations.sort((a, b) => b[0] - a[0]); + return { + dispose: () => { + for (let i = 0; i < this._implementations.length; i++) { + if (this._implementations[i][1] === implementation) { + this._implementations.splice(i, 1); + return; + } + } + } + }; + } + + public runCommand(accessor: ServicesAccessor, args: any): void | Promise { + for (const impl of this._implementations) { + if (impl[1](accessor, args)) { + return; + } + } + } +} + +//#endregion + +/** + * A command that delegates to another command's implementation. + * + * This lets different commands be registered but share the same implementation + */ +export class ProxyCommand extends Command { + constructor( + private readonly command: Command, + opts: ICommandOptions + ) { + super(opts); + } + + public runCommand(accessor: ServicesAccessor, args: any): void | Promise { + return this.command.runCommand(accessor, args); + } +} + //#region EditorCommand export interface IContributionCommandOptions extends ICommandOptions { @@ -379,8 +442,10 @@ export function registerEditorCommand(editorCommand: T) return editorCommand; } -export function registerEditorAction(ctor: { new(): EditorAction; }): void { - EditorContributionRegistry.INSTANCE.registerEditorAction(new ctor()); +export function registerEditorAction(ctor: { new(): T; }): T { + const action = new ctor(); + EditorContributionRegistry.INSTANCE.registerEditorAction(action); + return action; } export function registerInstantiatedEditorAction(editorAction: EditorAction): void { @@ -475,3 +540,75 @@ class EditorContributionRegistry { } Registry.add(Extensions.EditorCommonContributions, EditorContributionRegistry.INSTANCE); + +function registerCommand(command: T): T { + command.register(); + return command; +} + +export const UndoCommand = registerCommand(new MultiCommand({ + id: 'undo', + precondition: undefined, + kbOpts: { + weight: KeybindingWeight.EditorCore, + primary: KeyMod.CtrlCmd | KeyCode.KEY_Z + }, + menuOpts: [{ + menuId: MenuId.MenubarEditMenu, + group: '1_do', + title: nls.localize({ key: 'miUndo', comment: ['&& denotes a mnemonic'] }, "&&Undo"), + order: 1 + }, { + menuId: MenuId.CommandPalette, + group: '', + title: nls.localize('undo', "Undo"), + order: 1 + }] +})); + +registerCommand(new ProxyCommand(UndoCommand, { id: 'default:undo', precondition: undefined })); + +export const RedoCommand = registerCommand(new MultiCommand({ + id: 'redo', + precondition: undefined, + kbOpts: { + weight: KeybindingWeight.EditorCore, + primary: KeyMod.CtrlCmd | KeyCode.KEY_Y, + secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z], + mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z } + }, + menuOpts: [{ + menuId: MenuId.MenubarEditMenu, + group: '1_do', + title: nls.localize({ key: 'miRedo', comment: ['&& denotes a mnemonic'] }, "&&Redo"), + order: 2 + }, { + menuId: MenuId.CommandPalette, + group: '', + title: nls.localize('redo', "Redo"), + order: 1 + }] +})); + +registerCommand(new ProxyCommand(RedoCommand, { id: 'default:redo', precondition: undefined })); + +export const SelectAllCommand = registerCommand(new MultiCommand({ + id: 'editor.action.selectAll', + precondition: undefined, + kbOpts: { + weight: KeybindingWeight.EditorCore, + kbExpr: null, + primary: KeyMod.CtrlCmd | KeyCode.KEY_A + }, + menuOpts: [{ + menuId: MenuId.MenubarSelectionMenu, + group: '1_basic', + title: nls.localize({ key: 'miSelectAll', comment: ['&& denotes a mnemonic'] }, "&&Select All"), + order: 1 + }, { + menuId: MenuId.CommandPalette, + group: '', + title: nls.localize('selectAll', "Select All"), + order: 1 + }] +})); diff --git a/src/vs/editor/browser/view/viewController.ts b/src/vs/editor/browser/view/viewController.ts index 6fc163d9c36..69880b0133d 100644 --- a/src/vs/editor/browser/view/viewController.ts +++ b/src/vs/editor/browser/view/viewController.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; -import { CoreEditorCommand, CoreNavigationCommands } from 'vs/editor/browser/controller/coreCommands'; +import { CoreNavigationCommands } from 'vs/editor/browser/controller/coreCommands'; import { IEditorMouseEvent, IPartialEditorMouseEvent } from 'vs/editor/browser/editorBrowser'; import { ViewUserInputEvents } from 'vs/editor/browser/view/viewUserInputEvents'; import { Position } from 'vs/editor/common/core/position'; @@ -35,8 +35,6 @@ export interface IMouseDispatchData { } export interface ICommandDelegate { - executeEditorCommand(editorCommand: CoreEditorCommand, args: any): void; - paste(text: string, pasteOnNewLine: boolean, multicursorText: string[] | null, mode: string | null): void; type(text: string): void; replacePreviousChar(text: string, replaceCharCnt: number): void; @@ -64,11 +62,6 @@ export class ViewController { this.commandDelegate = commandDelegate; } - private _execMouseCommand(editorCommand: CoreEditorCommand, args: any): void { - args.source = 'mouse'; - this.commandDelegate.executeEditorCommand(editorCommand, args); - } - public paste(text: string, pasteOnNewLine: boolean, multicursorText: string[] | null, mode: string | null): void { this.commandDelegate.paste(text, pasteOnNewLine, multicursorText, mode); } @@ -94,7 +87,7 @@ export class ViewController { } public setSelection(modelSelection: Selection): void { - this.commandDelegate.executeEditorCommand(CoreNavigationCommands.SetSelection, { + CoreNavigationCommands.SetSelection.runCoreEditorCommand(this.viewModel, { source: 'keyboard', selection: modelSelection }); @@ -214,22 +207,24 @@ export class ViewController { private _usualArgs(viewPosition: Position) { viewPosition = this._validateViewColumn(viewPosition); return { + source: 'mouse', position: this._convertViewToModelPosition(viewPosition), viewPosition: viewPosition }; } public moveTo(viewPosition: Position): void { - this._execMouseCommand(CoreNavigationCommands.MoveTo, this._usualArgs(viewPosition)); + CoreNavigationCommands.MoveTo.runCoreEditorCommand(this.viewModel, this._usualArgs(viewPosition)); } private _moveToSelect(viewPosition: Position): void { - this._execMouseCommand(CoreNavigationCommands.MoveToSelect, this._usualArgs(viewPosition)); + CoreNavigationCommands.MoveToSelect.runCoreEditorCommand(this.viewModel, this._usualArgs(viewPosition)); } private _columnSelect(viewPosition: Position, mouseColumn: number, doColumnSelect: boolean): void { viewPosition = this._validateViewColumn(viewPosition); - this._execMouseCommand(CoreNavigationCommands.ColumnSelect, { + CoreNavigationCommands.ColumnSelect.runCoreEditorCommand(this.viewModel, { + source: 'mouse', position: this._convertViewToModelPosition(viewPosition), viewPosition: viewPosition, mouseColumn: mouseColumn, @@ -239,7 +234,8 @@ export class ViewController { private _createCursor(viewPosition: Position, wholeLine: boolean): void { viewPosition = this._validateViewColumn(viewPosition); - this._execMouseCommand(CoreNavigationCommands.CreateCursor, { + CoreNavigationCommands.CreateCursor.runCoreEditorCommand(this.viewModel, { + source: 'mouse', position: this._convertViewToModelPosition(viewPosition), viewPosition: viewPosition, wholeLine: wholeLine @@ -247,39 +243,39 @@ export class ViewController { } private _lastCursorMoveToSelect(viewPosition: Position): void { - this._execMouseCommand(CoreNavigationCommands.LastCursorMoveToSelect, this._usualArgs(viewPosition)); + CoreNavigationCommands.LastCursorMoveToSelect.runCoreEditorCommand(this.viewModel, this._usualArgs(viewPosition)); } private _wordSelect(viewPosition: Position): void { - this._execMouseCommand(CoreNavigationCommands.WordSelect, this._usualArgs(viewPosition)); + CoreNavigationCommands.WordSelect.runCoreEditorCommand(this.viewModel, this._usualArgs(viewPosition)); } private _wordSelectDrag(viewPosition: Position): void { - this._execMouseCommand(CoreNavigationCommands.WordSelectDrag, this._usualArgs(viewPosition)); + CoreNavigationCommands.WordSelectDrag.runCoreEditorCommand(this.viewModel, this._usualArgs(viewPosition)); } private _lastCursorWordSelect(viewPosition: Position): void { - this._execMouseCommand(CoreNavigationCommands.LastCursorWordSelect, this._usualArgs(viewPosition)); + CoreNavigationCommands.LastCursorWordSelect.runCoreEditorCommand(this.viewModel, this._usualArgs(viewPosition)); } private _lineSelect(viewPosition: Position): void { - this._execMouseCommand(CoreNavigationCommands.LineSelect, this._usualArgs(viewPosition)); + CoreNavigationCommands.LineSelect.runCoreEditorCommand(this.viewModel, this._usualArgs(viewPosition)); } private _lineSelectDrag(viewPosition: Position): void { - this._execMouseCommand(CoreNavigationCommands.LineSelectDrag, this._usualArgs(viewPosition)); + CoreNavigationCommands.LineSelectDrag.runCoreEditorCommand(this.viewModel, this._usualArgs(viewPosition)); } private _lastCursorLineSelect(viewPosition: Position): void { - this._execMouseCommand(CoreNavigationCommands.LastCursorLineSelect, this._usualArgs(viewPosition)); + CoreNavigationCommands.LastCursorLineSelect.runCoreEditorCommand(this.viewModel, this._usualArgs(viewPosition)); } private _lastCursorLineSelectDrag(viewPosition: Position): void { - this._execMouseCommand(CoreNavigationCommands.LastCursorLineSelectDrag, this._usualArgs(viewPosition)); + CoreNavigationCommands.LastCursorLineSelectDrag.runCoreEditorCommand(this.viewModel, this._usualArgs(viewPosition)); } private _selectAll(): void { - this._execMouseCommand(CoreNavigationCommands.SelectAll, {}); + CoreNavigationCommands.SelectAll.runCoreEditorCommand(this.viewModel, { source: 'mouse' }); } // ---------------------- diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index f57ab7693d6..32cbd06f69e 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -15,7 +15,6 @@ import { hash } from 'vs/base/common/hash'; import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle'; import { Schemas } from 'vs/base/common/network'; import { Configuration } from 'vs/editor/browser/config/configuration'; -import { CoreEditorCommand } from 'vs/editor/browser/controller/coreCommands'; import * as editorBrowser from 'vs/editor/browser/editorBrowser'; import { EditorExtensionsRegistry, IEditorContributionDescription } from 'vs/editor/browser/editorExtensions'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; @@ -1552,9 +1551,6 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE let commandDelegate: ICommandDelegate; if (this.isSimpleWidget) { commandDelegate = { - executeEditorCommand: (editorCommand: CoreEditorCommand, args: any): void => { - editorCommand.runCoreEditorCommand(viewModel, args); - }, paste: (text: string, pasteOnNewLine: boolean, multicursorText: string[] | null, mode: string | null) => { this._paste('keyboard', text, pasteOnNewLine, multicursorText, mode); }, @@ -1576,9 +1572,6 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE }; } else { commandDelegate = { - executeEditorCommand: (editorCommand: CoreEditorCommand, args: any): void => { - editorCommand.runCoreEditorCommand(viewModel, args); - }, paste: (text: string, pasteOnNewLine: boolean, multicursorText: string[] | null, mode: string | null) => { const payload: editorCommon.PastePayload = { text, pasteOnNewLine, multicursorText, mode }; this._commandService.executeCommand(editorCommon.Handler.Paste, payload); diff --git a/src/vs/editor/contrib/clipboard/clipboard.ts b/src/vs/editor/contrib/clipboard/clipboard.ts index 4ad6007754a..0f685415d4b 100644 --- a/src/vs/editor/contrib/clipboard/clipboard.ts +++ b/src/vs/editor/contrib/clipboard/clipboard.ts @@ -9,7 +9,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import * as platform from 'vs/base/common/platform'; import { CopyOptions } from 'vs/editor/browser/controller/textAreaInput'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { EditorAction, IActionOptions, ICommandKeybindingsOptions, registerEditorAction } from 'vs/editor/browser/editorExtensions'; +import { EditorAction, registerEditorAction, Command, MultiCommand } from 'vs/editor/browser/editorExtensions'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { MenuId } from 'vs/platform/actions/common/actions'; @@ -28,171 +28,111 @@ const supportsCopyWithSyntaxHighlighting = (supportsCopy && !browser.isEdge); // privileges to actually perform the action const supportsPaste = (platform.isNative || (!browser.isChrome && document.queryCommandSupported('paste'))); -type ExecCommand = 'cut' | 'copy' | 'paste'; - -abstract class ExecCommandAction extends EditorAction { - - private readonly browserCommand: ExecCommand; - - constructor(browserCommand: ExecCommand, opts: IActionOptions) { - super(opts); - this.browserCommand = browserCommand; - } - - public runCommand(accessor: ServicesAccessor, args: any): void { - let focusedEditor = accessor.get(ICodeEditorService).getFocusedCodeEditor(); - // Only if editor text focus (i.e. not if editor has widget focus). - if (focusedEditor && focusedEditor.hasTextFocus()) { - focusedEditor.trigger('keyboard', this.id, args); - return; - } - - document.execCommand(this.browserCommand); - } - - public run(accessor: ServicesAccessor, editor: ICodeEditor): void { - editor.focus(); - document.execCommand(this.browserCommand); - } +function registerCommand(command: T): T { + command.register(); + return command; } -class ExecCommandCutAction extends ExecCommandAction { - - constructor() { - let kbOpts: ICommandKeybindingsOptions | undefined = { +export const CutAction = supportsCut ? registerCommand(new MultiCommand({ + id: 'editor.action.clipboardCutAction', + precondition: undefined, + kbOpts: ( + // Do not bind cut keybindings in the browser, + // since browsers do that for us and it avoids security prompts + platform.isNative ? { kbExpr: EditorContextKeys.textInputFocus, primary: KeyMod.CtrlCmd | KeyCode.KEY_X, win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_X, secondary: [KeyMod.Shift | KeyCode.Delete] }, weight: KeybindingWeight.EditorContrib - }; - // Do not bind cut keybindings in the browser, + } : undefined + ), + menuOpts: [{ + menuId: MenuId.MenubarEditMenu, + group: '2_ccp', + title: nls.localize({ key: 'miCut', comment: ['&& denotes a mnemonic'] }, "Cu&&t"), + order: 1 + }, { + menuId: MenuId.EditorContext, + group: CLIPBOARD_CONTEXT_MENU_GROUP, + title: nls.localize('actions.clipboard.cutLabel', "Cut"), + when: EditorContextKeys.writable, + order: 1, + }, { + menuId: MenuId.CommandPalette, + group: '', + title: nls.localize('actions.clipboard.cutLabel', "Cut"), + order: 1 + }] +})) : undefined; + +export const CopyAction = supportsCopy ? registerCommand(new MultiCommand({ + id: 'editor.action.clipboardCopyAction', + precondition: undefined, + kbOpts: ( + // Do not bind copy keybindings in the browser, // since browsers do that for us and it avoids security prompts - if (!platform.isNative) { - kbOpts = undefined; - } - super('cut', { - id: 'editor.action.clipboardCutAction', - label: nls.localize('actions.clipboard.cutLabel', "Cut"), - alias: 'Cut', - precondition: EditorContextKeys.writable, - kbOpts: kbOpts, - contextMenuOpts: { - group: CLIPBOARD_CONTEXT_MENU_GROUP, - order: 1 - }, - menuOpts: { - menuId: MenuId.MenubarEditMenu, - group: '2_ccp', - title: nls.localize({ key: 'miCut', comment: ['&& denotes a mnemonic'] }, "Cu&&t"), - order: 1 - } - }); - } - - public run(accessor: ServicesAccessor, editor: ICodeEditor): void { - if (!editor.hasModel()) { - return; - } - - const emptySelectionClipboard = editor.getOption(EditorOption.emptySelectionClipboard); - - if (!emptySelectionClipboard && editor.getSelection().isEmpty()) { - return; - } - - super.run(accessor, editor); - } -} - -class ExecCommandCopyAction extends ExecCommandAction { - - constructor() { - let kbOpts: ICommandKeybindingsOptions | undefined = { + platform.isNative ? { kbExpr: EditorContextKeys.textInputFocus, primary: KeyMod.CtrlCmd | KeyCode.KEY_C, win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_C, secondary: [KeyMod.CtrlCmd | KeyCode.Insert] }, weight: KeybindingWeight.EditorContrib - }; - // Do not bind copy keybindings in the browser, + } : undefined + ), + menuOpts: [{ + menuId: MenuId.MenubarEditMenu, + group: '2_ccp', + title: nls.localize({ key: 'miCopy', comment: ['&& denotes a mnemonic'] }, "&&Copy"), + order: 2 + }, { + menuId: MenuId.EditorContext, + group: CLIPBOARD_CONTEXT_MENU_GROUP, + title: nls.localize('actions.clipboard.copyLabel', "Copy"), + order: 2, + }, { + menuId: MenuId.CommandPalette, + group: '', + title: nls.localize('actions.clipboard.copyLabel', "Copy"), + order: 1 + }] +})) : undefined; + +export const PasteAction = supportsPaste ? registerCommand(new MultiCommand({ + id: 'editor.action.clipboardPasteAction', + precondition: undefined, + kbOpts: ( + // Do not bind paste keybindings in the browser, // since browsers do that for us and it avoids security prompts - if (!platform.isNative) { - kbOpts = undefined; - } - - super('copy', { - id: 'editor.action.clipboardCopyAction', - label: nls.localize('actions.clipboard.copyLabel', "Copy"), - alias: 'Copy', - precondition: undefined, - kbOpts: kbOpts, - contextMenuOpts: { - group: CLIPBOARD_CONTEXT_MENU_GROUP, - order: 2 - }, - menuOpts: { - menuId: MenuId.MenubarEditMenu, - group: '2_ccp', - title: nls.localize({ key: 'miCopy', comment: ['&& denotes a mnemonic'] }, "&&Copy"), - order: 2 - } - }); - } - - public run(accessor: ServicesAccessor, editor: ICodeEditor): void { - if (!editor.hasModel()) { - return; - } - - const emptySelectionClipboard = editor.getOption(EditorOption.emptySelectionClipboard); - - if (!emptySelectionClipboard && editor.getSelection().isEmpty()) { - return; - } - - super.run(accessor, editor); - } -} - -class ExecCommandPasteAction extends ExecCommandAction { - - constructor() { - let kbOpts: ICommandKeybindingsOptions | undefined = { + platform.isNative ? { kbExpr: EditorContextKeys.textInputFocus, primary: KeyMod.CtrlCmd | KeyCode.KEY_V, win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_V, secondary: [KeyMod.Shift | KeyCode.Insert] }, linux: { primary: KeyMod.CtrlCmd | KeyCode.KEY_V, secondary: [KeyMod.Shift | KeyCode.Insert] }, weight: KeybindingWeight.EditorContrib - }; - // Do not bind paste keybindings in the browser, - // since browsers do that for us and it avoids security prompts - if (!platform.isNative) { - kbOpts = undefined; - } + } : undefined + ), + menuOpts: [{ + menuId: MenuId.MenubarEditMenu, + group: '2_ccp', + title: nls.localize({ key: 'miPaste', comment: ['&& denotes a mnemonic'] }, "&&Paste"), + order: 3 + }, { + menuId: MenuId.EditorContext, + group: CLIPBOARD_CONTEXT_MENU_GROUP, + title: nls.localize('actions.clipboard.pasteLabel', "Paste"), + when: EditorContextKeys.writable, + order: 3, + }, { + menuId: MenuId.CommandPalette, + group: '', + title: nls.localize('actions.clipboard.pasteLabel', "Paste"), + order: 1 + }] +})) : undefined; - super('paste', { - id: 'editor.action.clipboardPasteAction', - label: nls.localize('actions.clipboard.pasteLabel', "Paste"), - alias: 'Paste', - precondition: EditorContextKeys.writable, - kbOpts: kbOpts, - contextMenuOpts: { - group: CLIPBOARD_CONTEXT_MENU_GROUP, - order: 3 - }, - menuOpts: { - menuId: MenuId.MenubarEditMenu, - group: '2_ccp', - title: nls.localize({ key: 'miPaste', comment: ['&& denotes a mnemonic'] }, "&&Paste"), - order: 3 - } - }); - } -} - -class ExecCommandCopyWithSyntaxHighlightingAction extends ExecCommandAction { +class ExecCommandCopyWithSyntaxHighlightingAction extends EditorAction { constructor() { - super('copy', { + super({ id: 'editor.action.clipboardCopyWithSyntaxHighlightingAction', label: nls.localize('actions.clipboard.copyWithSyntaxHighlightingLabel', "Copy With Syntax Highlighting"), alias: 'Copy With Syntax Highlighting', @@ -217,20 +157,48 @@ class ExecCommandCopyWithSyntaxHighlightingAction extends ExecCommandAction { } CopyOptions.forceCopyWithSyntaxHighlighting = true; - super.run(accessor, editor); + editor.focus(); + document.execCommand('copy'); CopyOptions.forceCopyWithSyntaxHighlighting = false; } } -if (supportsCut) { - registerEditorAction(ExecCommandCutAction); -} -if (supportsCopy) { - registerEditorAction(ExecCommandCopyAction); -} -if (supportsPaste) { - registerEditorAction(ExecCommandPasteAction); +function registerExecCommandImpl(target: MultiCommand | undefined, browserCommand: 'cut' | 'copy' | 'paste'): void { + if (!target) { + return; + } + + // 1. handle case when focus is in editor. + target.addImplementation(10000, (accessor: ServicesAccessor, args: any) => { + // Only if editor text focus (i.e. not if editor has widget focus). + const focusedEditor = accessor.get(ICodeEditorService).getFocusedCodeEditor(); + if (focusedEditor && focusedEditor.hasTextFocus()) { + if (browserCommand === 'cut' || browserCommand === 'copy') { + // Do not execute if there is no selection and empty selection clipboard is off + const emptySelectionClipboard = focusedEditor.getOption(EditorOption.emptySelectionClipboard); + const selection = focusedEditor.getSelection(); + if (selection && selection.isEmpty() && !emptySelectionClipboard) { + return true; + } + } + document.execCommand(browserCommand); + return true; + } + return false; + }); + + // 2. (default) handle case when focus is somewhere else. + target.addImplementation(0, (accessor: ServicesAccessor, args: any) => { + // Only if editor text focus (i.e. not if editor has widget focus). + document.execCommand(browserCommand); + return true; + }); } + +registerExecCommandImpl(CutAction, 'cut'); +registerExecCommandImpl(CopyAction, 'copy'); +registerExecCommandImpl(PasteAction, 'paste'); + if (supportsCopyWithSyntaxHighlighting) { registerEditorAction(ExecCommandCopyWithSyntaxHighlightingAction); } diff --git a/src/vs/editor/test/browser/controller/inputRecorder.html b/src/vs/editor/test/browser/controller/inputRecorder.html index 3f538b8a04f..65d8a39c59a 100644 --- a/src/vs/editor/test/browser/controller/inputRecorder.html +++ b/src/vs/editor/test/browser/controller/inputRecorder.html @@ -31,14 +31,14 @@ var RECORDED_EVENTS = []; var input = document.getElementById('input'); -var blackListedProps = [ +var blockedProperties = [ 'currentTarget', 'path', 'srcElement', 'target', 'view' ]; -blackListedProps = blackListedProps.concat([ +blockedProperties = blockedProperties.concat([ 'AT_TARGET', 'BLUR', 'BUBBLING_PHASE', @@ -68,7 +68,7 @@ blackListedProps = blackListedProps.concat([ function toSerializable(e) { var r = {}; for (var k in e) { - if (blackListedProps.indexOf(k) >= 0) { + if (blockedProperties.indexOf(k) >= 0) { continue; } if (typeof e[k] === 'function') { @@ -112,4 +112,4 @@ document.getElementById('stop').onclick = function() { - \ No newline at end of file + diff --git a/src/vs/platform/extensions/browser/builtinExtensionsScannerService.ts b/src/vs/platform/extensions/browser/builtinExtensionsScannerService.ts new file mode 100644 index 00000000000..74a0c367750 --- /dev/null +++ b/src/vs/platform/extensions/browser/builtinExtensionsScannerService.ts @@ -0,0 +1,44 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { IBuiltinExtensionsScannerService, IScannedExtension, ExtensionType } from 'vs/platform/extensions/common/extensions'; +import { isWeb } from 'vs/base/common/platform'; +import { URI } from 'vs/base/common/uri'; + +export class BuiltinExtensionsScannerService implements IBuiltinExtensionsScannerService { + + declare readonly _serviceBrand: undefined; + + private readonly builtinExtensions: IScannedExtension[] = []; + + constructor( + ) { + if (isWeb) { + // Find builtin extensions by checking for DOM + const builtinExtensionsElement = document.getElementById('vscode-workbench-builtin-extensions'); + const builtinExtensionsElementAttribute = builtinExtensionsElement ? builtinExtensionsElement.getAttribute('data-settings') : undefined; + if (builtinExtensionsElementAttribute) { + try { + const builtinExtensions: IScannedExtension[] = JSON.parse(builtinExtensionsElementAttribute); + this.builtinExtensions = builtinExtensions.map(e => { + location: URI.revive(e.location), + type: ExtensionType.System, + packageJSON: e.packageJSON, + packageNLSUrl: URI.revive(e.packageNLSUrl), + readmeUrl: URI.revive(e.readmeUrl), + changelogUrl: URI.revive(e.changelogUrl), + }); + } catch (error) { /* ignore error*/ } + } + } + } + + async scanBuiltinExtensions(): Promise { + if (isWeb) { + return this.builtinExtensions; + } + throw new Error('not supported'); + } +} diff --git a/src/vs/platform/extensions/common/extensions.ts b/src/vs/platform/extensions/common/extensions.ts index ce044f65b41..70d0d6de1f1 100644 --- a/src/vs/platform/extensions/common/extensions.ts +++ b/src/vs/platform/extensions/common/extensions.ts @@ -6,6 +6,7 @@ import * as strings from 'vs/base/common/strings'; import { ILocalization } from 'vs/platform/localizations/common/localizations'; import { URI } from 'vs/base/common/uri'; +import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; export const MANIFEST_CACHE_FOLDER = 'CachedExtensions'; export const USER_MANIFEST_CACHE_FILE = 'user'; @@ -246,3 +247,18 @@ export interface IExtensionDescription extends IExtensionManifest { export function isLanguagePackExtension(manifest: IExtensionManifest): boolean { return manifest.contributes && manifest.contributes.localizations ? manifest.contributes.localizations.length > 0 : false; } + +export interface IScannedExtension { + readonly location: URI; + readonly type: ExtensionType; + readonly packageJSON: IExtensionManifest + readonly packageNLSUrl?: URI; + readonly readmeUrl?: URI; + readonly changelogUrl?: URI; +} + +export const IBuiltinExtensionsScannerService = createDecorator('IBuiltinExtensionsScannerService'); +export interface IBuiltinExtensionsScannerService { + readonly _serviceBrand: undefined; + scanBuiltinExtensions(): Promise; +} diff --git a/src/vs/platform/launch/electron-main/launchMainService.ts b/src/vs/platform/launch/electron-main/launchMainService.ts index 233f1690c98..40a2cf28940 100644 --- a/src/vs/platform/launch/electron-main/launchMainService.ts +++ b/src/vs/platform/launch/electron-main/launchMainService.ts @@ -156,6 +156,8 @@ export class LaunchMainService implements ILaunchMainService { else { const lastActive = this.windowsMainService.getLastActiveWindow(); if (lastActive) { + // Force focus the app before requesting window focus + app.focus({ steal: true }); lastActive.focus(); usedWindows = [lastActive]; diff --git a/src/vs/platform/log/common/logIpc.ts b/src/vs/platform/log/common/logIpc.ts index c8f7dd559a6..4c92e8d88af 100644 --- a/src/vs/platform/log/common/logIpc.ts +++ b/src/vs/platform/log/common/logIpc.ts @@ -75,14 +75,14 @@ export class LoggerChannelClient { export class FollowerLogService extends DelegatedLogService implements ILogService { declare readonly _serviceBrand: undefined; - constructor(private master: LoggerChannelClient, logService: ILogService) { + constructor(private parent: LoggerChannelClient, logService: ILogService) { super(logService); - this._register(master.onDidChangeLogLevel(level => logService.setLevel(level))); + this._register(parent.onDidChangeLogLevel(level => logService.setLevel(level))); } setLevel(level: LogLevel): void { super.setLevel(level); - this.master.setLevel(level); + this.parent.setLevel(level); } } diff --git a/src/vs/platform/storage/browser/storageService.ts b/src/vs/platform/storage/browser/storageService.ts index d3e4a216ea2..07275bb2b17 100644 --- a/src/vs/platform/storage/browser/storageService.ts +++ b/src/vs/platform/storage/browser/storageService.ts @@ -63,17 +63,11 @@ export class BrowserStorageService extends Disposable implements IStorageService // Workspace Storage this.workspaceStorageFile = joinPath(stateRoot, `${payload.id}.json`); + this.workspaceStorageDatabase = this._register(new FileStorageDatabase(this.workspaceStorageFile, false /* do not watch for external changes */, this.fileService)); this.workspaceStorage = this._register(new Storage(this.workspaceStorageDatabase)); this._register(this.workspaceStorage.onDidChangeStorage(key => this._onDidChangeStorage.fire({ key, scope: StorageScope.WORKSPACE }))); - const firstOpen = this.workspaceStorage.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN); - if (firstOpen === undefined) { - this.workspaceStorage.set(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, !(await this.fileService.exists(this.workspaceStorageFile))); - } else if (firstOpen) { - this.workspaceStorage.set(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, false); - } - // Global Storage this.globalStorageFile = joinPath(stateRoot, 'global.json'); this.globalStorageDatabase = this._register(new FileStorageDatabase(this.globalStorageFile, true /* watch for external changes */, this.fileService)); @@ -86,6 +80,15 @@ export class BrowserStorageService extends Disposable implements IStorageService this.globalStorage.init() ]); + // Check to see if this is the first time we are "opening" this workspace + const firstOpen = this.workspaceStorage.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN); + if (firstOpen === undefined) { + // NOTE@eamodio We can't reliably check to see if a workspace was added before this setting was introduced, so just pretend it is the first time + this.workspaceStorage.set(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, true); + } else if (firstOpen) { + this.workspaceStorage.set(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, false); + } + // In the browser we do not have support for long running unload sequences. As such, // we cannot ask for saving state in that moment, because that would result in a // long running operation. diff --git a/src/vs/platform/storage/node/storageService.ts b/src/vs/platform/storage/node/storageService.ts index d22e9595486..6e8f1d5f04b 100644 --- a/src/vs/platform/storage/node/storageService.ts +++ b/src/vs/platform/storage/node/storageService.ts @@ -105,6 +105,7 @@ export class NativeStorageService extends Disposable implements IStorageService ); await workspaceStorage.init(); + // Check to see if this is the first time we are "opening" this workspace const firstOpen = workspaceStorage.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN); if (firstOpen === undefined) { workspaceStorage.set(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, !result.wasCreated); diff --git a/src/vs/platform/userDataSync/common/userDataAutoSyncService.ts b/src/vs/platform/userDataSync/common/userDataAutoSyncService.ts index be2da97b550..ef35fc2b34c 100644 --- a/src/vs/platform/userDataSync/common/userDataAutoSyncService.ts +++ b/src/vs/platform/userDataSync/common/userDataAutoSyncService.ts @@ -81,6 +81,12 @@ export class UserDataAutoSyncService extends UserDataAutoSyncEnablementService i private readonly _onError: Emitter = this._register(new Emitter()); readonly onError: Event = this._onError.event; + private readonly _onTurnOnSync: Emitter = this._register(new Emitter()); + readonly onTurnOnSync: Event = this._onTurnOnSync.event; + + private readonly _onDidTurnOnSync: Emitter = this._register(new Emitter()); + readonly onDidTurnOnSync: Event = this._onDidTurnOnSync.event; + constructor( @IUserDataSyncStoreService private readonly userDataSyncStoreService: IUserDataSyncStoreService, @IUserDataSyncResourceEnablementService private readonly userDataSyncResourceEnablementService: IUserDataSyncResourceEnablementService, @@ -140,15 +146,23 @@ export class UserDataAutoSyncService extends UserDataAutoSyncEnablementService i } async turnOn(pullFirst: boolean): Promise { - this.stopDisableMachineEventually(); + this._onTurnOnSync.fire(); - if (pullFirst) { - await this.userDataSyncService.pull(); - } else { - await this.userDataSyncService.sync(); + try { + this.stopDisableMachineEventually(); + + if (pullFirst) { + await this.userDataSyncService.pull(); + } else { + await this.userDataSyncService.sync(); + } + + this.setEnablement(true); + this._onDidTurnOnSync.fire(undefined); + } catch (error) { + this._onDidTurnOnSync.fire(error); + throw error; } - - this.setEnablement(true); } async turnOff(everywhere: boolean, softTurnOffOnError?: boolean, donotRemoveMachine?: boolean): Promise { diff --git a/src/vs/platform/userDataSync/common/userDataSync.ts b/src/vs/platform/userDataSync/common/userDataSync.ts index a79be906630..82ac0b7c177 100644 --- a/src/vs/platform/userDataSync/common/userDataSync.ts +++ b/src/vs/platform/userDataSync/common/userDataSync.ts @@ -357,6 +357,7 @@ export interface IUserDataSyncService { readonly status: SyncStatus; readonly onDidChangeStatus: Event; + readonly onSynchronizeResource: Event; readonly conflicts: SyncResourceConflicts[]; readonly onDidChangeConflicts: Event; @@ -390,6 +391,8 @@ export interface IUserDataSyncService { export const IUserDataAutoSyncService = createDecorator('IUserDataAutoSyncService'); export interface IUserDataAutoSyncService { _serviceBrand: any; + readonly onTurnOnSync: Event + readonly onDidTurnOnSync: Event readonly onError: Event; readonly onDidChangeEnablement: Event; isEnabled(): boolean; diff --git a/src/vs/platform/userDataSync/common/userDataSyncIpc.ts b/src/vs/platform/userDataSync/common/userDataSyncIpc.ts index 2df27100016..33a87aa165c 100644 --- a/src/vs/platform/userDataSync/common/userDataSyncIpc.ts +++ b/src/vs/platform/userDataSync/common/userDataSyncIpc.ts @@ -22,6 +22,7 @@ export class UserDataSyncChannel implements IServerChannel { listen(_: unknown, event: string): Event { switch (event) { case 'onDidChangeStatus': return this.service.onDidChangeStatus; + case 'onSynchronizeResource': return this.service.onSynchronizeResource; case 'onDidChangeConflicts': return this.service.onDidChangeConflicts; case 'onDidChangeLocal': return this.service.onDidChangeLocal; case 'onDidChangeLastSyncTime': return this.service.onDidChangeLastSyncTime; @@ -68,6 +69,8 @@ export class UserDataAutoSyncChannel implements IServerChannel { listen(_: unknown, event: string): Event { switch (event) { + case 'onTurnOnSync': return this.service.onTurnOnSync; + case 'onDidTurnOnSync': return this.service.onDidTurnOnSync; case 'onError': return this.service.onError; } throw new Error(`Event not found: ${event}`); diff --git a/src/vs/platform/userDataSync/common/userDataSyncService.ts b/src/vs/platform/userDataSync/common/userDataSyncService.ts index a1e9c9592c9..2fadc715911 100644 --- a/src/vs/platform/userDataSync/common/userDataSyncService.ts +++ b/src/vs/platform/userDataSync/common/userDataSyncService.ts @@ -39,6 +39,9 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ private _onDidChangeStatus: Emitter = this._register(new Emitter()); readonly onDidChangeStatus: Event = this._onDidChangeStatus.event; + private _onSynchronizeResource: Emitter = this._register(new Emitter()); + readonly onSynchronizeResource: Event = this._onSynchronizeResource.event; + readonly onDidChangeLocal: Event; private _conflicts: SyncResourceConflicts[] = []; @@ -91,6 +94,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ try { for (const synchroniser of this.synchronisers) { try { + this._onSynchronizeResource.fire(synchroniser.resource); await synchroniser.pull(); } catch (e) { this.handleSynchronizerError(e, synchroniser.resource); @@ -175,6 +179,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ return; } try { + this._onSynchronizeResource.fire(synchroniser.resource); await synchroniser.sync(manifest, syncHeaders); } catch (e) { this.handleSynchronizerError(e, synchroniser.resource); diff --git a/src/vs/workbench/api/browser/mainThreadWebview.ts b/src/vs/workbench/api/browser/mainThreadWebview.ts index 0240c478525..758aa349107 100644 --- a/src/vs/workbench/api/browser/mainThreadWebview.ts +++ b/src/vs/workbench/api/browser/mainThreadWebview.ts @@ -141,7 +141,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma this._register(_editorService.onDidActiveEditorChange(() => { const activeInput = this._editorService.activeEditor; - if (activeInput instanceof DiffEditorInput && activeInput.master instanceof WebviewInput && activeInput.details instanceof WebviewInput) { + if (activeInput instanceof DiffEditorInput && activeInput.primary instanceof WebviewInput && activeInput.secondary instanceof WebviewInput) { this.registerWebviewFromDiffEditorListeners(activeInput); } @@ -468,22 +468,22 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma } private registerWebviewFromDiffEditorListeners(diffEditorInput: DiffEditorInput): void { - const master = diffEditorInput.master as WebviewInput; - const details = diffEditorInput.details as WebviewInput; + const primary = diffEditorInput.primary as WebviewInput; + const secondary = diffEditorInput.secondary as WebviewInput; - if (this._webviewFromDiffEditorHandles.has(master.id) || this._webviewFromDiffEditorHandles.has(details.id)) { + if (this._webviewFromDiffEditorHandles.has(primary.id) || this._webviewFromDiffEditorHandles.has(secondary.id)) { return; } - this._webviewFromDiffEditorHandles.add(master.id); - this._webviewFromDiffEditorHandles.add(details.id); + this._webviewFromDiffEditorHandles.add(primary.id); + this._webviewFromDiffEditorHandles.add(secondary.id); const disposables = new DisposableStore(); - disposables.add(master.webview.onDidFocus(() => this.updateWebviewViewStates(master))); - disposables.add(details.webview.onDidFocus(() => this.updateWebviewViewStates(details))); + disposables.add(primary.webview.onDidFocus(() => this.updateWebviewViewStates(primary))); + disposables.add(secondary.webview.onDidFocus(() => this.updateWebviewViewStates(secondary))); disposables.add(diffEditorInput.onDispose(() => { - this._webviewFromDiffEditorHandles.delete(master.id); - this._webviewFromDiffEditorHandles.delete(details.id); + this._webviewFromDiffEditorHandles.delete(primary.id); + this._webviewFromDiffEditorHandles.delete(secondary.id); dispose(disposables); })); } @@ -515,8 +515,8 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma for (const group of this._editorGroupService.groups) { for (const input of group.editors) { if (input instanceof DiffEditorInput) { - updateViewStatesForInput(group, input, input.master); - updateViewStatesForInput(group, input, input.details); + updateViewStatesForInput(group, input, input.primary); + updateViewStatesForInput(group, input, input.secondary); } else { updateViewStatesForInput(group, input, input); } diff --git a/src/vs/workbench/browser/actions/quickAccessActions.ts b/src/vs/workbench/browser/actions/quickAccessActions.ts index 0295a2580ff..ca9637c09cf 100644 --- a/src/vs/workbench/browser/actions/quickAccessActions.ts +++ b/src/vs/workbench/browser/actions/quickAccessActions.ts @@ -138,7 +138,7 @@ CommandsRegistry.registerCommand({ handler: async function (accessor: ServicesAccessor, prefix: unknown) { const quickInputService = accessor.get(IQuickInputService); - quickInputService.quickAccess.show(typeof prefix === 'string' ? prefix : undefined); + quickInputService.quickAccess.show(typeof prefix === 'string' ? prefix : undefined, { preserveValue: typeof prefix === 'string' /* preserve as is if provided */ }); }, description: { description: `Quick access`, diff --git a/src/vs/workbench/browser/dnd.ts b/src/vs/workbench/browser/dnd.ts index 53fcf64114d..bb66b64254b 100644 --- a/src/vs/workbench/browser/dnd.ts +++ b/src/vs/workbench/browser/dnd.ts @@ -5,7 +5,7 @@ import { hasWorkspaceFileExtension, IWorkspaceFolderCreationData, IRecentFile, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces'; import { normalize } from 'vs/base/common/path'; -import { basename } from 'vs/base/common/resources'; +import { basename, extUri } from 'vs/base/common/resources'; import { IFileService } from 'vs/platform/files/common/files'; import { IWindowOpenable } from 'vs/platform/windows/common/windows'; import { URI } from 'vs/base/common/uri'; @@ -357,7 +357,7 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources: for (const textEditorControl of textEditorControls) { if (isCodeEditor(textEditorControl)) { const model = textEditorControl.getModel(); - if (model?.uri?.toString() === file.resource.toString()) { + if (extUri.isEqual(model?.uri, file.resource)) { return withNullAsUndefined(textEditorControl.saveViewState()); } } diff --git a/src/vs/workbench/browser/labels.ts b/src/vs/workbench/browser/labels.ts index 570118ed8b7..328f6324128 100644 --- a/src/vs/workbench/browser/labels.ts +++ b/src/vs/workbench/browser/labels.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { URI } from 'vs/base/common/uri'; -import { dirname, isEqual, basenameOrAuthority } from 'vs/base/common/resources'; +import { dirname, isEqual, basenameOrAuthority, extUri } from 'vs/base/common/resources'; import { IconLabel, IIconLabelValueOptions, IIconLabelCreationOptions } from 'vs/base/browser/ui/iconLabel/iconLabel'; import { IModeService } from 'vs/editor/common/services/modeService'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; @@ -24,7 +24,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { withNullAsUndefined } from 'vs/base/common/types'; export interface IResourceLabelProps { - resource?: URI | { master?: URI, detail?: URI }; + resource?: URI | { primary?: URI, secondary?: URI }; name?: string | string[]; description?: string; } @@ -38,7 +38,7 @@ function toResource(props: IResourceLabelProps | undefined): URI | undefined { return props.resource; } - return props.resource.master; + return props.resource.primary; } export interface IResourceLabelOptions extends IIconLabelValueOptions { @@ -307,7 +307,7 @@ class ResourceLabelWidget extends IconLabel { return; // only update if resource exists } - if (model.uri.toString() === resource.toString()) { + if (extUri.isEqual(model.uri, resource)) { if (this.lastKnownDetectedModeId !== model.getModeId()) { this.render(true); // update if the language id of the model has changed from our last known state } @@ -379,9 +379,9 @@ class ResourceLabelWidget extends IconLabel { setResource(label: IResourceLabelProps, options: IResourceLabelOptions = Object.create(null)): void { const resource = toResource(label); - const isMasterDetail = label?.resource && !URI.isUri(label.resource); + const isSideBySideEditor = label?.resource && !URI.isUri(label.resource); - if (!options.forceLabel && !isMasterDetail && resource?.scheme === Schemas.untitled) { + if (!options.forceLabel && !isSideBySideEditor && resource?.scheme === Schemas.untitled) { // Untitled labels are very dynamic because they may change // whenever the content changes (unless a path is associated). // As such we always ask the actual editor for it's name and @@ -390,7 +390,7 @@ class ResourceLabelWidget extends IconLabel { // we assume that the client does not want to display them // and as such do not override. // - // We do not touch the label if it represents a master-detail + // We do not touch the label if it represents a primary-secondary // because in that case we expect it to carry a proper label // and description. const untitledModel = this.textFileService.untitled.get(resource); diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index c9d20c205bf..0662dfcd2bc 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -568,7 +568,8 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi return; } - const firstOpen = storageService.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE); + // The `firstRun` flag check is a safety-net hack for Codespaces, until we can verify the first open fix + const firstOpen = (storageService.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE) || (defaultLayout as { firstRun: boolean })?.firstRun); if (!firstOpen) { return; } @@ -790,7 +791,8 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi private getInitialFilesToOpen(): { filesToOpenOrCreate?: IPath[], filesToDiff?: IPath[] } | undefined { const defaultLayout = this.environmentService.options?.defaultLayout; - if (defaultLayout?.editors?.length && this.storageService.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE)) { + // The `firstRun` flag check is a safety-net hack for Codespaces, until we can verify the first open fix + if (defaultLayout?.editors?.length && (this.storageService.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE) || (defaultLayout as { firstRun: boolean })?.firstRun)) { this._openedDefaultEditors = true; return { diff --git a/src/vs/workbench/browser/parts/editor/binaryDiffEditor.ts b/src/vs/workbench/browser/parts/editor/binaryDiffEditor.ts index 964c8852ac5..9d285cea910 100644 --- a/src/vs/workbench/browser/parts/editor/binaryDiffEditor.ts +++ b/src/vs/workbench/browser/parts/editor/binaryDiffEditor.ts @@ -29,11 +29,11 @@ export class BinaryResourceDiffEditor extends SideBySideEditor { } getMetadata(): string | undefined { - const master = this.masterEditorPane; - const details = this.detailsEditorPane; + const primary = this.primaryEditorPane; + const secondary = this.secondaryEditorPane; - if (master instanceof BaseBinaryResourceEditor && details instanceof BaseBinaryResourceEditor) { - return nls.localize('metadataDiff', "{0} ↔ {1}", details.getMetadata(), master.getMetadata()); + if (primary instanceof BaseBinaryResourceEditor && secondary instanceof BaseBinaryResourceEditor) { + return nls.localize('metadataDiff', "{0} ↔ {1}", secondary.getMetadata(), primary.getMetadata()); } return undefined; diff --git a/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts b/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts index 6e7ff0f164d..d69abfe14e9 100644 --- a/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts +++ b/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts @@ -234,7 +234,7 @@ export class BreadcrumbsControl { this._breadcrumbsDisposables.clear(); // honor diff editors and such - const uri = toResource(this._editorGroup.activeEditor, { supportSideBySide: SideBySideEditor.MASTER }); + const uri = toResource(this._editorGroup.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }); if (!uri || !this._fileService.canHandleResource(uri)) { // cleanup and return when there is no input or when diff --git a/src/vs/workbench/browser/parts/editor/editor.contribution.ts b/src/vs/workbench/browser/parts/editor/editor.contribution.ts index ca50f4eca24..165ff789e23 100644 --- a/src/vs/workbench/browser/parts/editor/editor.contribution.ts +++ b/src/vs/workbench/browser/parts/editor/editor.contribution.ts @@ -173,28 +173,28 @@ interface ISerializedSideBySideEditorInput { name: string; description: string | undefined; - detailsSerialized: string; - masterSerialized: string; + primarySerialized: string; + secondarySerialized: string; - detailsTypeId: string; - masterTypeId: string; + primaryTypeId: string; + secondaryTypeId: string; } export abstract class AbstractSideBySideEditorInputFactory implements IEditorInputFactory { - private getInputFactories(detailsId: string, masterId: string): [IEditorInputFactory | undefined, IEditorInputFactory | undefined] { + private getInputFactories(secondaryId: string, primaryId: string): [IEditorInputFactory | undefined, IEditorInputFactory | undefined] { const registry = Registry.as(EditorInputExtensions.EditorInputFactories); - return [registry.getEditorInputFactory(detailsId), registry.getEditorInputFactory(masterId)]; + return [registry.getEditorInputFactory(secondaryId), registry.getEditorInputFactory(primaryId)]; } canSerialize(editorInput: EditorInput): boolean { const input = editorInput as SideBySideEditorInput | DiffEditorInput; - if (input.details && input.master) { - const [detailsInputFactory, masterInputFactory] = this.getInputFactories(input.details.getTypeId(), input.master.getTypeId()); + if (input.primary && input.secondary) { + const [secondaryInputFactory, primaryInputFactory] = this.getInputFactories(input.secondary.getTypeId(), input.primary.getTypeId()); - return !!(detailsInputFactory?.canSerialize(input.details) && masterInputFactory?.canSerialize(input.master)); + return !!(secondaryInputFactory?.canSerialize(input.secondary) && primaryInputFactory?.canSerialize(input.primary)); } return false; @@ -203,20 +203,20 @@ export abstract class AbstractSideBySideEditorInputFactory implements IEditorInp serialize(editorInput: EditorInput): string | undefined { const input = editorInput as SideBySideEditorInput | DiffEditorInput; - if (input.details && input.master) { - const [detailsInputFactory, masterInputFactory] = this.getInputFactories(input.details.getTypeId(), input.master.getTypeId()); - if (detailsInputFactory && masterInputFactory) { - const detailsSerialized = detailsInputFactory.serialize(input.details); - const masterSerialized = masterInputFactory.serialize(input.master); + if (input.primary && input.secondary) { + const [secondaryInputFactory, primaryInputFactory] = this.getInputFactories(input.secondary.getTypeId(), input.primary.getTypeId()); + if (primaryInputFactory && secondaryInputFactory) { + const primarySerialized = primaryInputFactory.serialize(input.primary); + const secondarySerialized = secondaryInputFactory.serialize(input.secondary); - if (detailsSerialized && masterSerialized) { + if (primarySerialized && secondarySerialized) { const serializedEditorInput: ISerializedSideBySideEditorInput = { name: input.getName(), description: input.getDescription(), - detailsSerialized, - masterSerialized, - detailsTypeId: input.details.getTypeId(), - masterTypeId: input.master.getTypeId() + primarySerialized: primarySerialized, + secondarySerialized: secondarySerialized, + primaryTypeId: input.primary.getTypeId(), + secondaryTypeId: input.secondary.getTypeId() }; return JSON.stringify(serializedEditorInput); @@ -230,33 +230,33 @@ export abstract class AbstractSideBySideEditorInputFactory implements IEditorInp deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput | undefined { const deserialized: ISerializedSideBySideEditorInput = JSON.parse(serializedEditorInput); - const [detailsInputFactory, masterInputFactory] = this.getInputFactories(deserialized.detailsTypeId, deserialized.masterTypeId); - if (detailsInputFactory && masterInputFactory) { - const detailsInput = detailsInputFactory.deserialize(instantiationService, deserialized.detailsSerialized); - const masterInput = masterInputFactory.deserialize(instantiationService, deserialized.masterSerialized); + const [secondaryInputFactory, primaryInputFactory] = this.getInputFactories(deserialized.secondaryTypeId, deserialized.primaryTypeId); + if (primaryInputFactory && secondaryInputFactory) { + const primaryInput = primaryInputFactory.deserialize(instantiationService, deserialized.primarySerialized); + const secondaryInput = secondaryInputFactory.deserialize(instantiationService, deserialized.secondarySerialized); - if (detailsInput && masterInput) { - return this.createEditorInput(deserialized.name, deserialized.description, detailsInput, masterInput); + if (primaryInput && secondaryInput) { + return this.createEditorInput(deserialized.name, deserialized.description, secondaryInput, primaryInput); } } return undefined; } - protected abstract createEditorInput(name: string, description: string | undefined, detailsInput: EditorInput, masterInput: EditorInput): EditorInput; + protected abstract createEditorInput(name: string, description: string | undefined, secondaryInput: EditorInput, primaryInput: EditorInput): EditorInput; } class SideBySideEditorInputFactory extends AbstractSideBySideEditorInputFactory { - protected createEditorInput(name: string, description: string | undefined, detailsInput: EditorInput, masterInput: EditorInput): EditorInput { - return new SideBySideEditorInput(name, description, detailsInput, masterInput); + protected createEditorInput(name: string, description: string | undefined, secondaryInput: EditorInput, primaryInput: EditorInput): EditorInput { + return new SideBySideEditorInput(name, description, secondaryInput, primaryInput); } } class DiffEditorInputFactory extends AbstractSideBySideEditorInputFactory { - protected createEditorInput(name: string, description: string | undefined, detailsInput: EditorInput, masterInput: EditorInput): EditorInput { - return new DiffEditorInput(name, description, detailsInput, masterInput); + protected createEditorInput(name: string, description: string | undefined, secondaryInput: EditorInput, primaryInput: EditorInput): EditorInput { + return new DiffEditorInput(name, description, secondaryInput, primaryInput); } } diff --git a/src/vs/workbench/browser/parts/editor/editorActions.ts b/src/vs/workbench/browser/parts/editor/editorActions.ts index 6600e795804..683f49fc110 100644 --- a/src/vs/workbench/browser/parts/editor/editorActions.ts +++ b/src/vs/workbench/browser/parts/editor/editorActions.ts @@ -581,7 +581,7 @@ abstract class BaseCloseAllAction extends Action { else { let name: string; if (editor instanceof SideBySideEditorInput) { - name = editor.master.getName(); // prefer shorter names by using master's name in this case + name = editor.primary.getName(); // prefer shorter names by using primary's name in this case } else { name = editor.getName(); } diff --git a/src/vs/workbench/browser/parts/editor/editorGroupView.ts b/src/vs/workbench/browser/parts/editor/editorGroupView.ts index 600a7985ca0..dcf07d6ebaf 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupView.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupView.ts @@ -527,7 +527,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView { // Include both sides of side by side editors when being closed if (editor instanceof SideBySideEditorInput) { - editorsToClose.push(editor.master, editor.details); + editorsToClose.push(editor.primary, editor.secondary); } // For each editor to close, we call dispose() to free up any resources. @@ -537,7 +537,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView { for (const editor of editorsToClose) { if (!this.accessor.groups.some(groupView => groupView.group.contains(editor, { strictEquals: true, // only if this input is not shared across editor groups - supportSideBySide: true // include side by side editor master & details + supportSideBySide: true // include side by side editor primary & secondary }))) { editor.dispose(); } @@ -1359,8 +1359,8 @@ export class EditorGroupView extends Themable implements IEditorGroupView { return false; // editor must be dirty and not saving } - if (editor instanceof SideBySideEditorInput && this._group.contains(editor.master)) { - return false; // master-side of editor is still opened somewhere else + if (editor instanceof SideBySideEditorInput && this._group.contains(editor.primary)) { + return false; // primary-side of editor is still opened somewhere else } // Note: we explicitly decide to ask for confirm if closing a normal editor even @@ -1378,8 +1378,8 @@ export class EditorGroupView extends Themable implements IEditorGroupView { return true; // exact editor still opened } - if (editor instanceof SideBySideEditorInput && otherGroup.contains(editor.master)) { - return true; // master side of side by side editor still opened + if (editor instanceof SideBySideEditorInput && otherGroup.contains(editor.primary)) { + return true; // primary side of side by side editor still opened } return false; @@ -1404,7 +1404,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView { let name: string; if (editor instanceof SideBySideEditorInput) { - name = editor.master.getName(); // prefer shorter names by using master's name in this case + name = editor.primary.getName(); // prefer shorter names by using primary's name in this case } else { name = editor.getName(); } diff --git a/src/vs/workbench/browser/parts/editor/editorQuickAccess.ts b/src/vs/workbench/browser/parts/editor/editorQuickAccess.ts index 60e46cc5c02..231efdd147a 100644 --- a/src/vs/workbench/browser/parts/editor/editorQuickAccess.ts +++ b/src/vs/workbench/browser/parts/editor/editorQuickAccess.ts @@ -137,7 +137,7 @@ export abstract class BaseEditorQuickAccessProvider extends PickerQuickAccessPro } return this.doGetEditors().map(({ editor, groupId }): IEditorQuickPickItem => { - const resource = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }); + const resource = toResource(editor, { supportSideBySide: SideBySideEditor.PRIMARY }); const isDirty = editor.isDirty() && !editor.isSaving(); const description = editor.getDescription(); const nameAndDescription = description ? `${editor.getName()} ${description}` : editor.getName(); diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index d6f0950099d..b3d0cab0c11 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -54,22 +54,22 @@ import { STATUS_BAR_PROMINENT_ITEM_BACKGROUND, STATUS_BAR_PROMINENT_ITEM_FOREGRO import { themeColorFromId } from 'vs/platform/theme/common/themeService'; class SideBySideEditorEncodingSupport implements IEncodingSupport { - constructor(private master: IEncodingSupport, private details: IEncodingSupport) { } + constructor(private primary: IEncodingSupport, private secondary: IEncodingSupport) { } getEncoding(): string | undefined { - return this.master.getEncoding(); // always report from modified (right hand) side + return this.primary.getEncoding(); // always report from modified (right hand) side } setEncoding(encoding: string, mode: EncodingMode): void { - [this.master, this.details].forEach(editor => editor.setEncoding(encoding, mode)); + [this.primary, this.secondary].forEach(editor => editor.setEncoding(encoding, mode)); } } class SideBySideEditorModeSupport implements IModeSupport { - constructor(private master: IModeSupport, private details: IModeSupport) { } + constructor(private primary: IModeSupport, private secondary: IModeSupport) { } setMode(mode: string): void { - [this.master, this.details].forEach(editor => editor.setMode(mode)); + [this.primary, this.secondary].forEach(editor => editor.setMode(mode)); } } @@ -82,14 +82,14 @@ function toEditorWithEncodingSupport(input: IEditorInput): IEncodingSupport | nu // Side by Side (diff) Editor if (input instanceof SideBySideEditorInput) { - const masterEncodingSupport = toEditorWithEncodingSupport(input.master); - const detailsEncodingSupport = toEditorWithEncodingSupport(input.details); + const primaryEncodingSupport = toEditorWithEncodingSupport(input.primary); + const secondaryEncodingSupport = toEditorWithEncodingSupport(input.secondary); - if (masterEncodingSupport && detailsEncodingSupport) { - return new SideBySideEditorEncodingSupport(masterEncodingSupport, detailsEncodingSupport); + if (primaryEncodingSupport && secondaryEncodingSupport) { + return new SideBySideEditorEncodingSupport(primaryEncodingSupport, secondaryEncodingSupport); } - return masterEncodingSupport; + return primaryEncodingSupport; } // File or Resource Editor @@ -111,14 +111,14 @@ function toEditorWithModeSupport(input: IEditorInput): IModeSupport | null { // Side by Side (diff) Editor if (input instanceof SideBySideEditorInput) { - const masterModeSupport = toEditorWithModeSupport(input.master); - const detailsModeSupport = toEditorWithModeSupport(input.details); + const primaryModeSupport = toEditorWithModeSupport(input.primary); + const secondaryModeSupport = toEditorWithModeSupport(input.secondary); - if (masterModeSupport && detailsModeSupport) { - return new SideBySideEditorModeSupport(masterModeSupport, detailsModeSupport); + if (primaryModeSupport && secondaryModeSupport) { + return new SideBySideEditorModeSupport(primaryModeSupport, secondaryModeSupport); } - return masterModeSupport; + return primaryModeSupport; } // File or Resource Editor @@ -685,14 +685,14 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution { else if (activeEditorPane instanceof BaseBinaryResourceEditor || activeEditorPane instanceof BinaryResourceDiffEditor) { const binaryEditors: BaseBinaryResourceEditor[] = []; if (activeEditorPane instanceof BinaryResourceDiffEditor) { - const details = activeEditorPane.getDetailsEditorPane(); - if (details instanceof BaseBinaryResourceEditor) { - binaryEditors.push(details); + const primary = activeEditorPane.getPrimaryEditorPane(); + if (primary instanceof BaseBinaryResourceEditor) { + binaryEditors.push(primary); } - const master = activeEditorPane.getMasterEditorPane(); - if (master instanceof BaseBinaryResourceEditor) { - binaryEditors.push(master); + const secondary = activeEditorPane.getSecondaryEditorPane(); + if (secondary instanceof BaseBinaryResourceEditor) { + binaryEditors.push(secondary); } } else { binaryEditors.push(activeEditorPane); @@ -871,7 +871,7 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution { private onResourceEncodingChange(resource: URI): void { const activeEditorPane = this.editorService.activeEditorPane; if (activeEditorPane) { - const activeResource = toResource(activeEditorPane.input, { supportSideBySide: SideBySideEditor.MASTER }); + const activeResource = toResource(activeEditorPane.input, { supportSideBySide: SideBySideEditor.PRIMARY }); if (activeResource && isEqual(activeResource, resource)) { const activeCodeEditor = withNullAsUndefined(getCodeEditor(activeEditorPane.getControl())); @@ -1064,7 +1064,7 @@ export class ChangeModeAction extends Action { } const textModel = activeTextEditorControl.getModel(); - const resource = this.editorService.activeEditor ? toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.MASTER }) : null; + const resource = this.editorService.activeEditor ? toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }) : null; let hasLanguageSupport = !!resource; if (resource?.scheme === Schemas.untitled && !this.textFileService.untitled.get(resource)?.hasAssociatedFilePath) { @@ -1161,7 +1161,7 @@ export class ChangeModeAction extends Action { let languageSelection: ILanguageSelection | undefined; if (pick === autoDetectMode) { if (textModel) { - const resource = toResource(activeEditor, { supportSideBySide: SideBySideEditor.MASTER }); + const resource = toResource(activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }); if (resource) { languageSelection = this.modeService.createByFilepathOrFirstLine(resource, textModel.getLineContent(1)); } @@ -1356,7 +1356,7 @@ export class ChangeEncodingAction extends Action { await timeout(50); // quick input is sensitive to being opened so soon after another - const resource = toResource(activeEditorPane.input, { supportSideBySide: SideBySideEditor.MASTER }); + const resource = toResource(activeEditorPane.input, { supportSideBySide: SideBySideEditor.PRIMARY }); if (!resource || (!this.fileService.canHandleResource(resource) && resource.scheme !== Schemas.untitled)) { return; // encoding detection only possible for resources the file service can handle or that are untitled } diff --git a/src/vs/workbench/browser/parts/editor/editorsObserver.ts b/src/vs/workbench/browser/parts/editor/editorsObserver.ts index 4573dbdeb1a..a14a7fdc9c0 100644 --- a/src/vs/workbench/browser/parts/editor/editorsObserver.ts +++ b/src/vs/workbench/browser/parts/editor/editorsObserver.ts @@ -185,7 +185,7 @@ export class EditorsObserver extends Disposable { } private updateEditorResourcesMap(editor: IEditorInput, add: boolean): void { - const resource = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }); + const resource = toResource(editor, { supportSideBySide: SideBySideEditor.PRIMARY }); if (!resource) { return; // require a resource } diff --git a/src/vs/workbench/browser/parts/editor/sideBySideEditor.ts b/src/vs/workbench/browser/parts/editor/sideBySideEditor.ts index fd57b26ca33..aff171a997f 100644 --- a/src/vs/workbench/browser/parts/editor/sideBySideEditor.ts +++ b/src/vs/workbench/browser/parts/editor/sideBySideEditor.ts @@ -22,17 +22,16 @@ import { assertIsDefined } from 'vs/base/common/types'; export class SideBySideEditor extends BaseEditor { static readonly ID: string = 'workbench.editor.sidebysideEditor'; - static MASTER: SideBySideEditor | undefined; - get minimumMasterWidth() { return this.masterEditorPane ? this.masterEditorPane.minimumWidth : 0; } - get maximumMasterWidth() { return this.masterEditorPane ? this.masterEditorPane.maximumWidth : Number.POSITIVE_INFINITY; } - get minimumMasterHeight() { return this.masterEditorPane ? this.masterEditorPane.minimumHeight : 0; } - get maximumMasterHeight() { return this.masterEditorPane ? this.masterEditorPane.maximumHeight : Number.POSITIVE_INFINITY; } + private get minimumPrimaryWidth() { return this.primaryEditorPane ? this.primaryEditorPane.minimumWidth : 0; } + private get maximumPrimaryWidth() { return this.primaryEditorPane ? this.primaryEditorPane.maximumWidth : Number.POSITIVE_INFINITY; } + private get minimumPrimaryHeight() { return this.primaryEditorPane ? this.primaryEditorPane.minimumHeight : 0; } + private get maximumPrimaryHeight() { return this.primaryEditorPane ? this.primaryEditorPane.maximumHeight : Number.POSITIVE_INFINITY; } - get minimumDetailsWidth() { return this.detailsEditorPane ? this.detailsEditorPane.minimumWidth : 0; } - get maximumDetailsWidth() { return this.detailsEditorPane ? this.detailsEditorPane.maximumWidth : Number.POSITIVE_INFINITY; } - get minimumDetailsHeight() { return this.detailsEditorPane ? this.detailsEditorPane.minimumHeight : 0; } - get maximumDetailsHeight() { return this.detailsEditorPane ? this.detailsEditorPane.maximumHeight : Number.POSITIVE_INFINITY; } + private get minimumSecondaryWidth() { return this.secondaryEditorPane ? this.secondaryEditorPane.minimumWidth : 0; } + private get maximumSecondaryWidth() { return this.secondaryEditorPane ? this.secondaryEditorPane.maximumWidth : Number.POSITIVE_INFINITY; } + private get minimumSecondaryHeight() { return this.secondaryEditorPane ? this.secondaryEditorPane.minimumHeight : 0; } + private get maximumSecondaryHeight() { return this.secondaryEditorPane ? this.secondaryEditorPane.maximumHeight : Number.POSITIVE_INFINITY; } // these setters need to exist because this extends from BaseEditor set minimumWidth(value: number) { /* noop */ } @@ -40,16 +39,16 @@ export class SideBySideEditor extends BaseEditor { set minimumHeight(value: number) { /* noop */ } set maximumHeight(value: number) { /* noop */ } - get minimumWidth() { return this.minimumMasterWidth + this.minimumDetailsWidth; } - get maximumWidth() { return this.maximumMasterWidth + this.maximumDetailsWidth; } - get minimumHeight() { return this.minimumMasterHeight + this.minimumDetailsHeight; } - get maximumHeight() { return this.maximumMasterHeight + this.maximumDetailsHeight; } + get minimumWidth() { return this.minimumPrimaryWidth + this.minimumSecondaryWidth; } + get maximumWidth() { return this.maximumPrimaryWidth + this.maximumSecondaryWidth; } + get minimumHeight() { return this.minimumPrimaryHeight + this.minimumSecondaryHeight; } + get maximumHeight() { return this.maximumPrimaryHeight + this.maximumSecondaryHeight; } - protected masterEditorPane?: BaseEditor; - protected detailsEditorPane?: BaseEditor; + protected primaryEditorPane?: BaseEditor; + protected secondaryEditorPane?: BaseEditor; - private masterEditorContainer: HTMLElement | undefined; - private detailsEditorContainer: HTMLElement | undefined; + private primaryEditorContainer: HTMLElement | undefined; + private secondaryEditorContainer: HTMLElement | undefined; private splitview: SplitView | undefined; private dimension: DOM.Dimension = new DOM.Dimension(0, 0); @@ -74,19 +73,19 @@ export class SideBySideEditor extends BaseEditor { const splitview = this.splitview = this._register(new SplitView(parent, { orientation: Orientation.HORIZONTAL })); this._register(this.splitview.onDidSashReset(() => splitview.distributeViewSizes())); - this.detailsEditorContainer = DOM.$('.details-editor-container'); + this.secondaryEditorContainer = DOM.$('.secondary-editor-container'); this.splitview.addView({ - element: this.detailsEditorContainer, - layout: size => this.detailsEditorPane && this.detailsEditorPane.layout(new DOM.Dimension(size, this.dimension.height)), + element: this.secondaryEditorContainer, + layout: size => this.secondaryEditorPane && this.secondaryEditorPane.layout(new DOM.Dimension(size, this.dimension.height)), minimumSize: 220, maximumSize: Number.POSITIVE_INFINITY, onDidChange: Event.None }, Sizing.Distribute); - this.masterEditorContainer = DOM.$('.master-editor-container'); + this.primaryEditorContainer = DOM.$('.primary-editor-container'); this.splitview.addView({ - element: this.masterEditorContainer, - layout: size => this.masterEditorPane && this.masterEditorPane.layout(new DOM.Dimension(size, this.dimension.height)), + element: this.primaryEditorContainer, + layout: size => this.primaryEditorPane && this.primaryEditorPane.layout(new DOM.Dimension(size, this.dimension.height)), minimumSize: 220, maximumSize: Number.POSITIVE_INFINITY, onDidChange: Event.None @@ -103,30 +102,30 @@ export class SideBySideEditor extends BaseEditor { } setOptions(options: EditorOptions | undefined): void { - if (this.masterEditorPane) { - this.masterEditorPane.setOptions(options); + if (this.primaryEditorPane) { + this.primaryEditorPane.setOptions(options); } } protected setEditorVisible(visible: boolean, group: IEditorGroup | undefined): void { - if (this.masterEditorPane) { - this.masterEditorPane.setVisible(visible, group); + if (this.primaryEditorPane) { + this.primaryEditorPane.setVisible(visible, group); } - if (this.detailsEditorPane) { - this.detailsEditorPane.setVisible(visible, group); + if (this.secondaryEditorPane) { + this.secondaryEditorPane.setVisible(visible, group); } super.setEditorVisible(visible, group); } clearInput(): void { - if (this.masterEditorPane) { - this.masterEditorPane.clearInput(); + if (this.primaryEditorPane) { + this.primaryEditorPane.clearInput(); } - if (this.detailsEditorPane) { - this.detailsEditorPane.clearInput(); + if (this.secondaryEditorPane) { + this.secondaryEditorPane.clearInput(); } this.disposeEditors(); @@ -135,8 +134,8 @@ export class SideBySideEditor extends BaseEditor { } focus(): void { - if (this.masterEditorPane) { - this.masterEditorPane.focus(); + if (this.primaryEditorPane) { + this.primaryEditorPane.focus(); } } @@ -148,19 +147,19 @@ export class SideBySideEditor extends BaseEditor { } getControl(): IEditorControl | undefined { - if (this.masterEditorPane) { - return this.masterEditorPane.getControl(); + if (this.primaryEditorPane) { + return this.primaryEditorPane.getControl(); } return undefined; } - getMasterEditorPane(): IEditorPane | undefined { - return this.masterEditorPane; + getPrimaryEditorPane(): IEditorPane | undefined { + return this.primaryEditorPane; } - getDetailsEditorPane(): IEditorPane | undefined { - return this.detailsEditorPane; + getSecondaryEditorPane(): IEditorPane | undefined { + return this.secondaryEditorPane; } private async updateInput(oldInput: SideBySideEditorInput, newInput: SideBySideEditorInput, options: EditorOptions | undefined, token: CancellationToken): Promise { @@ -172,21 +171,21 @@ export class SideBySideEditor extends BaseEditor { return this.setNewInput(newInput, options, token); } - if (!this.detailsEditorPane || !this.masterEditorPane) { + if (!this.secondaryEditorPane || !this.primaryEditorPane) { return; } await Promise.all([ - this.detailsEditorPane.setInput(newInput.details, undefined, token), - this.masterEditorPane.setInput(newInput.master, options, token) + this.secondaryEditorPane.setInput(newInput.secondary, undefined, token), + this.primaryEditorPane.setInput(newInput.primary, options, token) ]); } private setNewInput(newInput: SideBySideEditorInput, options: EditorOptions | undefined, token: CancellationToken): Promise { - const detailsEditor = this.doCreateEditor(newInput.details, assertIsDefined(this.detailsEditorContainer)); - const masterEditor = this.doCreateEditor(newInput.master, assertIsDefined(this.masterEditorContainer)); + const secondaryEditor = this.doCreateEditor(newInput.secondary, assertIsDefined(this.secondaryEditorContainer)); + const primaryEditor = this.doCreateEditor(newInput.primary, assertIsDefined(this.primaryEditorContainer)); - return this.onEditorsCreated(detailsEditor, masterEditor, newInput.details, newInput.master, options, token); + return this.onEditorsCreated(secondaryEditor, primaryEditor, newInput.secondary, newInput.primary, options, token); } private doCreateEditor(editorInput: EditorInput, container: HTMLElement): BaseEditor { @@ -202,48 +201,48 @@ export class SideBySideEditor extends BaseEditor { return editor; } - private async onEditorsCreated(details: BaseEditor, master: BaseEditor, detailsInput: EditorInput, masterInput: EditorInput, options: EditorOptions | undefined, token: CancellationToken): Promise { - this.detailsEditorPane = details; - this.masterEditorPane = master; + private async onEditorsCreated(secondary: BaseEditor, primary: BaseEditor, secondaryInput: EditorInput, primaryInput: EditorInput, options: EditorOptions | undefined, token: CancellationToken): Promise { + this.secondaryEditorPane = secondary; + this.primaryEditorPane = primary; this._onDidSizeConstraintsChange.input = Event.any( - Event.map(details.onDidSizeConstraintsChange, () => undefined), - Event.map(master.onDidSizeConstraintsChange, () => undefined) + Event.map(secondary.onDidSizeConstraintsChange, () => undefined), + Event.map(primary.onDidSizeConstraintsChange, () => undefined) ); this.onDidCreateEditors.fire(undefined); await Promise.all([ - this.detailsEditorPane.setInput(detailsInput, undefined, token), - this.masterEditorPane.setInput(masterInput, options, token)] + this.secondaryEditorPane.setInput(secondaryInput, undefined, token), + this.primaryEditorPane.setInput(primaryInput, options, token)] ); } updateStyles(): void { super.updateStyles(); - if (this.masterEditorContainer) { - this.masterEditorContainer.style.boxShadow = `-6px 0 5px -5px ${this.getColor(scrollbarShadow)}`; + if (this.primaryEditorContainer) { + this.primaryEditorContainer.style.boxShadow = `-6px 0 5px -5px ${this.getColor(scrollbarShadow)}`; } } private disposeEditors(): void { - if (this.detailsEditorPane) { - this.detailsEditorPane.dispose(); - this.detailsEditorPane = undefined; + if (this.secondaryEditorPane) { + this.secondaryEditorPane.dispose(); + this.secondaryEditorPane = undefined; } - if (this.masterEditorPane) { - this.masterEditorPane.dispose(); - this.masterEditorPane = undefined; + if (this.primaryEditorPane) { + this.primaryEditorPane.dispose(); + this.primaryEditorPane = undefined; } - if (this.detailsEditorContainer) { - DOM.clearNode(this.detailsEditorContainer); + if (this.secondaryEditorContainer) { + DOM.clearNode(this.secondaryEditorContainer); } - if (this.masterEditorContainer) { - DOM.clearNode(this.masterEditorContainer); + if (this.primaryEditorContainer) { + DOM.clearNode(this.primaryEditorContainer); } } diff --git a/src/vs/workbench/browser/parts/editor/tabsTitleControl.ts b/src/vs/workbench/browser/parts/editor/tabsTitleControl.ts index fa8861a64fc..203f334180d 100644 --- a/src/vs/workbench/browser/parts/editor/tabsTitleControl.ts +++ b/src/vs/workbench/browser/parts/editor/tabsTitleControl.ts @@ -1087,7 +1087,7 @@ export class TabsTitleControl extends TitleControl { ); // Tests helper - const resource = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }); + const resource = toResource(editor, { supportSideBySide: SideBySideEditor.PRIMARY }); if (resource) { tabContainer.setAttribute('data-resource-name', basenameOrAuthority(resource)); } else { diff --git a/src/vs/workbench/browser/parts/editor/titleControl.ts b/src/vs/workbench/browser/parts/editor/titleControl.ts index 7a6e4137db8..b778ec9d3f2 100644 --- a/src/vs/workbench/browser/parts/editor/titleControl.ts +++ b/src/vs/workbench/browser/parts/editor/titleControl.ts @@ -223,7 +223,7 @@ export abstract class TitleControl extends Themable { this.editorToolBarMenuDisposables.clear(); // Update contexts - this.resourceContext.set(this.group.activeEditor ? withUndefinedAsNull(toResource(this.group.activeEditor, { supportSideBySide: SideBySideEditor.MASTER })) : null); + this.resourceContext.set(this.group.activeEditor ? withUndefinedAsNull(toResource(this.group.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY })) : null); this.editorPinnedContext.set(this.group.activeEditor ? this.group.isPinned(this.group.activeEditor) : false); this.editorStickyContext.set(this.group.activeEditor ? this.group.isSticky(this.group.activeEditor) : false); @@ -298,7 +298,7 @@ export abstract class TitleControl extends Themable { } protected doFillResourceDataTransfers(editor: IEditorInput, e: DragEvent): boolean { - const resource = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }); + const resource = toResource(editor, { supportSideBySide: SideBySideEditor.PRIMARY }); if (!resource) { return false; } @@ -326,7 +326,7 @@ export abstract class TitleControl extends Themable { // Update contexts based on editor picked and remember previous to restore const currentResourceContext = this.resourceContext.get(); - this.resourceContext.set(withUndefinedAsNull(toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }))); + this.resourceContext.set(withUndefinedAsNull(toResource(editor, { supportSideBySide: SideBySideEditor.PRIMARY }))); const currentPinnedContext = !!this.editorPinnedContext.get(); this.editorPinnedContext.set(this.group.isPinned(editor)); const currentStickyContext = !!this.editorStickyContext.get(); diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index 22eb36afbc7..9c02c267018 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -271,7 +271,7 @@ export class TitlebarPart extends Part implements ITitleService { if (this.contextService.getWorkbenchState() === WorkbenchState.FOLDER) { folder = workspace.folders[0]; } else { - const resource = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }); + const resource = toResource(editor, { supportSideBySide: SideBySideEditor.PRIMARY }); if (resource) { folder = this.contextService.getWorkspaceFolder(resource); } diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 90ef4e06337..16d38a9a18f 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -649,10 +649,16 @@ export interface IModeSupport { export interface IFileEditorInput extends IEditorInput, IEncodingSupport, IModeSupport { /** - * Gets the resource this editor is about. + * Gets the resource this file input is about. */ readonly resource: URI; + /** + * Gets the label of the editor. In most cases this will + * be identical to the resource. + */ + readonly label: URI; + /** * Sets the preferred label to use for this file input. */ @@ -680,7 +686,7 @@ export interface IFileEditorInput extends IEditorInput, IEncodingSupport, IModeS } /** - * Side by side editor inputs that have a master and details side. + * Side by side editor inputs that have a primary and secondary side. */ export class SideBySideEditorInput extends EditorInput { @@ -689,8 +695,8 @@ export class SideBySideEditorInput extends EditorInput { constructor( protected readonly name: string | undefined, private readonly description: string | undefined, - private readonly _details: EditorInput, - private readonly _master: EditorInput + private readonly _secondary: EditorInput, + private readonly _primary: EditorInput ) { super(); @@ -699,36 +705,36 @@ export class SideBySideEditorInput extends EditorInput { private registerListeners(): void { - // When the details or master input gets disposed, dispose this diff editor input - const onceDetailsDisposed = Event.once(this.details.onDispose); - this._register(onceDetailsDisposed(() => { + // When the primary or secondary input gets disposed, dispose this diff editor input + const onceSecondaryDisposed = Event.once(this.secondary.onDispose); + this._register(onceSecondaryDisposed(() => { if (!this.isDisposed()) { this.dispose(); } })); - const onceMasterDisposed = Event.once(this.master.onDispose); - this._register(onceMasterDisposed(() => { + const oncePrimaryDisposed = Event.once(this.primary.onDispose); + this._register(oncePrimaryDisposed(() => { if (!this.isDisposed()) { this.dispose(); } })); - // Reemit some events from the master side to the outside - this._register(this.master.onDidChangeDirty(() => this._onDidChangeDirty.fire())); - this._register(this.master.onDidChangeLabel(() => this._onDidChangeLabel.fire())); + // Reemit some events from the primary side to the outside + this._register(this.primary.onDidChangeDirty(() => this._onDidChangeDirty.fire())); + this._register(this.primary.onDidChangeLabel(() => this._onDidChangeLabel.fire())); } get resource(): URI | undefined { return undefined; } - get master(): EditorInput { - return this._master; + get primary(): EditorInput { + return this._primary; } - get details(): EditorInput { - return this._details; + get secondary(): EditorInput { + return this._secondary; } getTypeId(): string { @@ -737,7 +743,7 @@ export class SideBySideEditorInput extends EditorInput { getName(): string { if (!this.name) { - return localize('sideBySideLabels', "{0} - {1}", this._details.getName(), this._master.getName()); + return localize('sideBySideLabels', "{0} - {1}", this._secondary.getName(), this._primary.getName()); } return this.name; @@ -748,50 +754,46 @@ export class SideBySideEditorInput extends EditorInput { } isReadonly(): boolean { - return this.master.isReadonly(); + return this.primary.isReadonly(); } isUntitled(): boolean { - return this.master.isUntitled(); + return this.primary.isUntitled(); } isDirty(): boolean { - return this.master.isDirty(); + return this.primary.isDirty(); } isSaving(): boolean { - return this.master.isSaving(); + return this.primary.isSaving(); } save(group: GroupIdentifier, options?: ISaveOptions): Promise { - return this.master.save(group, options); + return this.primary.save(group, options); } saveAs(group: GroupIdentifier, options?: ISaveOptions): Promise { - return this.master.saveAs(group, options); + return this.primary.saveAs(group, options); } revert(group: GroupIdentifier, options?: IRevertOptions): Promise { - return this.master.revert(group, options); + return this.primary.revert(group, options); } getTelemetryDescriptor(): { [key: string]: unknown } { - const descriptor = this.master.getTelemetryDescriptor(); + const descriptor = this.primary.getTelemetryDescriptor(); return Object.assign(descriptor, super.getTelemetryDescriptor()); } matches(otherInput: unknown): boolean { - if (super.matches(otherInput) === true) { + if (otherInput === this) { return true; } - if (otherInput) { - if (!(otherInput instanceof SideBySideEditorInput)) { - return false; - } - - return this.details.matches(otherInput.details) && this.master.matches(otherInput.master); + if (otherInput instanceof SideBySideEditorInput) { + return this.primary.matches(otherInput.primary) && this.secondary.matches(otherInput.secondary); } return false; @@ -1210,8 +1212,8 @@ export interface IEditorPartOptionsChangeEvent { } export enum SideBySideEditor { - MASTER = 1, - DETAILS = 2, + PRIMARY = 1, + SECONDARY = 2, BOTH = 3 } @@ -1221,9 +1223,9 @@ export interface IResourceOptions { } export function toResource(editor: IEditorInput | undefined | null): URI | undefined; -export function toResource(editor: IEditorInput | undefined | null, options: IResourceOptions & { supportSideBySide?: SideBySideEditor.MASTER | SideBySideEditor.DETAILS }): URI | undefined; -export function toResource(editor: IEditorInput | undefined | null, options: IResourceOptions & { supportSideBySide: SideBySideEditor.BOTH }): URI | { master?: URI, detail?: URI } | undefined; -export function toResource(editor: IEditorInput | undefined | null, options?: IResourceOptions): URI | { master?: URI, detail?: URI } | undefined { +export function toResource(editor: IEditorInput | undefined | null, options: IResourceOptions & { supportSideBySide?: SideBySideEditor.PRIMARY | SideBySideEditor.SECONDARY }): URI | undefined; +export function toResource(editor: IEditorInput | undefined | null, options: IResourceOptions & { supportSideBySide: SideBySideEditor.BOTH }): URI | { primary?: URI, secondary?: URI } | undefined; +export function toResource(editor: IEditorInput | undefined | null, options?: IResourceOptions): URI | { primary?: URI, secondary?: URI } | undefined { if (!editor) { return undefined; } @@ -1231,12 +1233,12 @@ export function toResource(editor: IEditorInput | undefined | null, options?: IR if (options?.supportSideBySide && editor instanceof SideBySideEditorInput) { if (options?.supportSideBySide === SideBySideEditor.BOTH) { return { - master: toResource(editor.master, { filterByScheme: options.filterByScheme }), - detail: toResource(editor.details, { filterByScheme: options.filterByScheme }) + primary: toResource(editor.primary, { filterByScheme: options.filterByScheme }), + secondary: toResource(editor.secondary, { filterByScheme: options.filterByScheme }) }; } - editor = options.supportSideBySide === SideBySideEditor.MASTER ? editor.master : editor.details; + editor = options.supportSideBySide === SideBySideEditor.PRIMARY ? editor.primary : editor.secondary; } const resource = editor.resource; diff --git a/src/vs/workbench/common/editor/editorGroup.ts b/src/vs/workbench/common/editor/editorGroup.ts index fba31f878ee..99d46391837 100644 --- a/src/vs/workbench/common/editor/editorGroup.ts +++ b/src/vs/workbench/common/editor/editorGroup.ts @@ -696,7 +696,7 @@ export class EditorGroup extends Disposable { } if (options?.supportSideBySide && editor instanceof SideBySideEditorInput) { - if (this.matches(editor.master, candidate, options?.strictEquals) || this.matches(editor.details, candidate, options?.strictEquals)) { + if (this.matches(editor.primary, candidate, options?.strictEquals) || this.matches(editor.secondary, candidate, options?.strictEquals)) { return true; } } diff --git a/src/vs/workbench/common/editor/resourceEditorInput.ts b/src/vs/workbench/common/editor/resourceEditorInput.ts index 5d0cf51c87b..d9006712fcf 100644 --- a/src/vs/workbench/common/editor/resourceEditorInput.ts +++ b/src/vs/workbench/common/editor/resourceEditorInput.ts @@ -15,6 +15,7 @@ import { IFileService } from 'vs/platform/files/common/files'; import { ILabelService } from 'vs/platform/label/common/label'; import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService'; import { AbstractTextResourceEditorInput } from 'vs/workbench/common/editor/textResourceEditorInput'; +import { extUri } from 'vs/base/common/resources'; /** * A read-only text editor input whos contents are made of the provided resource that points to an existing @@ -109,13 +110,12 @@ export class ResourceEditorInput extends AbstractTextResourceEditorInput impleme } matches(otherInput: unknown): boolean { - if (super.matches(otherInput) === true) { + if (otherInput === this) { return true; } - // Compare by properties if (otherInput instanceof ResourceEditorInput) { - return otherInput.resource.toString() === this.resource.toString(); + return extUri.isEqual(otherInput.resource, this.resource); } return false; diff --git a/src/vs/workbench/common/editor/textResourceEditorInput.ts b/src/vs/workbench/common/editor/textResourceEditorInput.ts index 82f04d7aebc..ad427fbf461 100644 --- a/src/vs/workbench/common/editor/textResourceEditorInput.ts +++ b/src/vs/workbench/common/editor/textResourceEditorInput.ts @@ -22,7 +22,8 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput { private static readonly MEMOIZER = createMemoizer(); - private label: URI; + private _label: URI; + get label(): URI { return this._label; } constructor( public readonly resource: URI, @@ -36,7 +37,7 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput { ) { super(); - this.label = preferredLabel || resource; + this._label = preferredLabel || resource; this.registerListeners(); } @@ -50,7 +51,7 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput { } private onLabelEvent(scheme: string): void { - if (scheme === this.label.scheme) { + if (scheme === this._label.scheme) { this.updateLabel(); } } @@ -65,15 +66,15 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput { } setLabel(label: URI): void { - if (!extUri.isEqual(label, this.label)) { - this.label = label; + if (!extUri.isEqual(label, this._label)) { + this._label = label; this.updateLabel(); } } getLabel(): URI { - return this.label; + return this._label; } getName(): string { @@ -82,7 +83,7 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput { @AbstractTextResourceEditorInput.MEMOIZER private get basename(): string { - return this.labelService.getUriBasenameLabel(this.label); + return this.labelService.getUriBasenameLabel(this._label); } getDescription(verbosity: Verbosity = Verbosity.MEDIUM): string | undefined { @@ -99,17 +100,17 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput { @AbstractTextResourceEditorInput.MEMOIZER private get shortDescription(): string { - return this.labelService.getUriBasenameLabel(dirname(this.label)); + return this.labelService.getUriBasenameLabel(dirname(this._label)); } @AbstractTextResourceEditorInput.MEMOIZER private get mediumDescription(): string { - return this.labelService.getUriLabel(dirname(this.label), { relative: true }); + return this.labelService.getUriLabel(dirname(this._label), { relative: true }); } @AbstractTextResourceEditorInput.MEMOIZER private get longDescription(): string { - return this.labelService.getUriLabel(dirname(this.label)); + return this.labelService.getUriLabel(dirname(this._label)); } @AbstractTextResourceEditorInput.MEMOIZER @@ -119,12 +120,12 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput { @AbstractTextResourceEditorInput.MEMOIZER private get mediumTitle(): string { - return this.labelService.getUriLabel(this.label, { relative: true }); + return this.labelService.getUriLabel(this._label, { relative: true }); } @AbstractTextResourceEditorInput.MEMOIZER private get longTitle(): string { - return this.labelService.getUriLabel(this.label); + return this.labelService.getUriLabel(this._label); } getTitle(verbosity: Verbosity): string { @@ -163,7 +164,7 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput { return false; } - async save(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise { + save(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise { return this.doSave(group, options, false); } @@ -185,7 +186,12 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput { return undefined; // save cancelled } - return this.editorService.createEditorInput({ resource: target }); + // If the target is a different resource, return with a new editor input + if (!extUri.isEqual(target, this.resource)) { + return this.editorService.createEditorInput({ resource: target }); + } + + return this; } async revert(group: GroupIdentifier, options?: IRevertOptions): Promise { diff --git a/src/vs/workbench/contrib/customEditor/browser/commands.ts b/src/vs/workbench/contrib/customEditor/browser/commands.ts deleted file mode 100644 index d96619b257a..00000000000 --- a/src/vs/workbench/contrib/customEditor/browser/commands.ts +++ /dev/null @@ -1,68 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; -import { Command } from 'vs/editor/browser/editorExtensions'; -import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; -import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys'; -import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; -import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; -import { CustomEditorInput } from 'vs/workbench/contrib/customEditor/browser/customEditorInput'; -import { CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE } from 'vs/workbench/contrib/customEditor/common/customEditor'; -import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; - - -(new class UndoCustomEditorCommand extends Command { - public static readonly ID = 'editor.action.customEditor.undo'; - - constructor() { - super({ - id: UndoCustomEditorCommand.ID, - precondition: ContextKeyExpr.and( - CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE, - ContextKeyExpr.not(InputFocusedContextKey)), - kbOpts: { - primary: KeyMod.CtrlCmd | KeyCode.KEY_Z, - weight: KeybindingWeight.EditorContrib - } - }); - } - - public runCommand(accessor: ServicesAccessor): void { - const editorService = accessor.get(IEditorService); - const activeInput = editorService.activeEditorPane?.input; - if (activeInput instanceof CustomEditorInput) { - activeInput.undo(); - } - } -}).register(); - -(new class RedoWebviewEditorCommand extends Command { - public static readonly ID = 'editor.action.customEditor.redo'; - - constructor() { - super({ - id: RedoWebviewEditorCommand.ID, - precondition: ContextKeyExpr.and( - CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE, - ContextKeyExpr.not(InputFocusedContextKey)), - kbOpts: { - primary: KeyMod.CtrlCmd | KeyCode.KEY_Y, - secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z], - mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z }, - weight: KeybindingWeight.EditorContrib - } - }); - } - - public runCommand(accessor: ServicesAccessor): void { - const editorService = accessor.get(IEditorService); - const activeInput = editorService.activeEditorPane?.input; - if (activeInput instanceof CustomEditorInput) { - activeInput.redo(); - } - } -}).register(); - diff --git a/src/vs/workbench/contrib/customEditor/browser/customEditor.contribution.ts b/src/vs/workbench/contrib/customEditor/browser/customEditor.contribution.ts index 4189d2899a7..25069373665 100644 --- a/src/vs/workbench/contrib/customEditor/browser/customEditor.contribution.ts +++ b/src/vs/workbench/contrib/customEditor/browser/customEditor.contribution.ts @@ -14,7 +14,6 @@ import { Extensions as EditorInputExtensions, IEditorInputFactoryRegistry } from import { CustomEditorInputFactory } from 'vs/workbench/contrib/customEditor/browser/customEditorInputFactory'; import { ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor'; import { WebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewEditor'; -import './commands'; import { CustomEditorInput } from './customEditorInput'; import { CustomEditorContribution, CustomEditorService } from './customEditors'; diff --git a/src/vs/workbench/contrib/customEditor/browser/customEditors.ts b/src/vs/workbench/contrib/customEditor/browser/customEditors.ts index 984b6c6a777..afec917d62d 100644 --- a/src/vs/workbench/contrib/customEditor/browser/customEditors.ts +++ b/src/vs/workbench/contrib/customEditor/browser/customEditors.ts @@ -66,7 +66,6 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ this._focusedCustomEditorIsEditable = CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE.bindTo(contextKeyService); this._webviewHasOwnEditFunctions = webviewHasOwnEditFunctionsContext.bindTo(contextKeyService); - this._contributedEditors = this._register(new ContributedCustomEditors(storageService)); this._register(this._contributedEditors.onChange(() => { this.updateContexts(); diff --git a/src/vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler.ts b/src/vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler.ts index 869a4900104..f2d566a910a 100644 --- a/src/vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler.ts +++ b/src/vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler.ts @@ -5,7 +5,7 @@ import * as nls from 'vs/nls'; import { toErrorMessage } from 'vs/base/common/errorMessage'; -import { basename } from 'vs/base/common/resources'; +import { basename, extUri } from 'vs/base/common/resources'; import { Action, IAction } from 'vs/base/common/actions'; import { URI } from 'vs/base/common/uri'; import { FileOperationError, FileOperationResult } from 'vs/platform/files/common/files'; @@ -115,7 +115,7 @@ export class TextFileSaveErrorHandler extends Disposable implements ISaveErrorHa if (fileOperationError.fileOperationResult === FileOperationResult.FILE_MODIFIED_SINCE) { // If the user tried to save from the opened conflict editor, show its message again - if (this.activeConflictResolutionResource && this.activeConflictResolutionResource.toString() === model.resource.toString()) { + if (this.activeConflictResolutionResource && extUri.isEqual(this.activeConflictResolutionResource, model.resource)) { if (this.storageService.getBoolean(LEARN_MORE_DIRTY_WRITE_IGNORE_KEY, StorageScope.GLOBAL)) { return; // return if this message is ignored } diff --git a/src/vs/workbench/contrib/files/browser/fileActions.ts b/src/vs/workbench/contrib/files/browser/fileActions.ts index 2f8728a6743..1ef66d58ce7 100644 --- a/src/vs/workbench/contrib/files/browser/fileActions.ts +++ b/src/vs/workbench/contrib/files/browser/fileActions.ts @@ -633,7 +633,7 @@ export class ShowActiveFileInExplorer extends Action { } async run(): Promise { - const resource = toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.MASTER }); + const resource = toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }); if (resource) { this.commandService.executeCommand(REVEAL_IN_EXPLORER_COMMAND_ID, resource); } else { @@ -701,7 +701,7 @@ export class ShowOpenedFileInNewWindow extends Action { } async run(): Promise { - const fileResource = toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.MASTER }); + const fileResource = toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }); if (fileResource) { if (this.fileService.canHandleResource(fileResource)) { this.hostService.openWindow([{ fileUri: fileResource }], { forceNewWindow: true }); @@ -813,7 +813,7 @@ export class CompareWithClipboardAction extends Action { } async run(): Promise { - const resource = toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.MASTER }); + const resource = toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }); const scheme = `clipboardCompare${CompareWithClipboardAction.SCHEME_COUNTER++}`; if (resource && (this.fileService.canHandleResource(resource) || resource.scheme === Schemas.untitled)) { if (!this.registrationDisposal) { diff --git a/src/vs/workbench/contrib/files/browser/fileCommands.ts b/src/vs/workbench/contrib/files/browser/fileCommands.ts index fbaf2c5f161..0bc5c56d2e7 100644 --- a/src/vs/workbench/contrib/files/browser/fileCommands.ts +++ b/src/vs/workbench/contrib/files/browser/fileCommands.ts @@ -178,7 +178,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ // Dispose once no more diff editor is opened with the scheme if (registerEditorListener) { providerDisposables.push(editorService.onDidVisibleEditorsChange(() => { - if (!editorService.editors.some(editor => !!toResource(editor, { supportSideBySide: SideBySideEditor.DETAILS, filterByScheme: COMPARE_WITH_SAVED_SCHEMA }))) { + if (!editorService.editors.some(editor => !!toResource(editor, { supportSideBySide: SideBySideEditor.SECONDARY, filterByScheme: COMPARE_WITH_SAVED_SCHEMA }))) { providerDisposables = dispose(providerDisposables); } })); @@ -356,8 +356,8 @@ async function saveSelectedEditors(accessor: ServicesAccessor, options?: ISaveEd // We only allow this when saving, not for "Save As". // See also https://github.com/microsoft/vscode/issues/4180 if (activeGroup.activeEditor instanceof SideBySideEditorInput && !options?.saveAs) { - editors.push({ groupId: activeGroup.id, editor: activeGroup.activeEditor.master }); - editors.push({ groupId: activeGroup.id, editor: activeGroup.activeEditor.details }); + editors.push({ groupId: activeGroup.id, editor: activeGroup.activeEditor.primary }); + editors.push({ groupId: activeGroup.id, editor: activeGroup.activeEditor.secondary }); } else { editors.push({ groupId: activeGroup.id, editor: activeGroup.activeEditor }); } @@ -380,7 +380,7 @@ async function saveSelectedEditors(accessor: ServicesAccessor, options?: ISaveEd const resource = focusedCodeEditor.getModel()?.uri; // Check that the resource of the model was not saved already - if (resource && !editors.some(({ editor }) => isEqual(toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }), resource))) { + if (resource && !editors.some(({ editor }) => isEqual(toResource(editor, { supportSideBySide: SideBySideEditor.PRIMARY }), resource))) { const model = textFileService.files.get(resource); if (!model?.isReadonly()) { await textFileService.save(resource, options); diff --git a/src/vs/workbench/contrib/files/browser/files.ts b/src/vs/workbench/contrib/files/browser/files.ts index 1274f2b97d5..ac012e62fc4 100644 --- a/src/vs/workbench/contrib/files/browser/files.ts +++ b/src/vs/workbench/contrib/files/browser/files.ts @@ -50,7 +50,7 @@ export function getResourceForCommand(resource: URI | object | undefined, listSe return focus.getResource(); } - return editorService.activeEditor ? toResource(editorService.activeEditor, { supportSideBySide: SideBySideEditor.MASTER }) : undefined; + return editorService.activeEditor ? toResource(editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }) : undefined; } export function getMultiSelectedResources(resource: URI | object | undefined, listService: IListService, editorService: IEditorService, explorerService: IExplorerService): Array { diff --git a/src/vs/workbench/contrib/files/browser/views/explorerView.ts b/src/vs/workbench/contrib/files/browser/views/explorerView.ts index d85e781b2d6..66d94162794 100644 --- a/src/vs/workbench/contrib/files/browser/views/explorerView.ts +++ b/src/vs/workbench/contrib/files/browser/views/explorerView.ts @@ -668,7 +668,7 @@ export class ExplorerView extends ViewPane { } // check for files - return withNullAsUndefined(toResource(input, { supportSideBySide: SideBySideEditor.MASTER })); + return withNullAsUndefined(toResource(input, { supportSideBySide: SideBySideEditor.PRIMARY })); } public async selectResource(resource: URI | undefined, reveal = this.autoReveal, retry = 0): Promise { diff --git a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts index b9f7585c466..aaf749555d4 100644 --- a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts +++ b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts @@ -314,12 +314,12 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements } matches(otherInput: unknown): boolean { - if (super.matches(otherInput) === true) { + if (otherInput === this) { return true; } - if (otherInput) { - return otherInput instanceof FileEditorInput && otherInput.resource.toString() === this.resource.toString(); + if (otherInput instanceof FileEditorInput) { + return extUri.isEqual(otherInput.resource, this.resource); } return false; diff --git a/src/vs/workbench/contrib/files/common/files.ts b/src/vs/workbench/contrib/files/common/files.ts index 74fcfeb9f25..3fe4953a5c6 100644 --- a/src/vs/workbench/contrib/files/common/files.ts +++ b/src/vs/workbench/contrib/files/common/files.ts @@ -251,6 +251,6 @@ export class OpenEditor implements IEditorIdentifier { } getResource(): URI | undefined { - return toResource(this.editor, { supportSideBySide: SideBySideEditor.MASTER }); + return toResource(this.editor, { supportSideBySide: SideBySideEditor.PRIMARY }); } } diff --git a/src/vs/workbench/contrib/hover/browser/hoverService.ts b/src/vs/workbench/contrib/hover/browser/hoverService.ts deleted file mode 100644 index 1278220a0c5..00000000000 --- a/src/vs/workbench/contrib/hover/browser/hoverService.ts +++ /dev/null @@ -1,75 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { IHoverService, IHoverOptions } from 'vs/workbench/contrib/hover/browser/hover'; -import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { HoverWidget } from 'vs/workbench/contrib/hover/browser/hoverWidget'; -import { IContextViewProvider, IDelegate } from 'vs/base/browser/ui/contextview/contextview'; - -export class HoverService implements IHoverService { - declare readonly _serviceBrand: undefined; - - private _currentHoverOptions: IHoverOptions | undefined; - - constructor( - @IInstantiationService private readonly _instantiationService: IInstantiationService, - @IContextViewService private readonly _contextViewService: IContextViewService - ) { - } - - showHover(options: IHoverOptions, focus?: boolean): void { - if (this._currentHoverOptions === options) { - return; - } - this._currentHoverOptions = options; - - const hover = this._instantiationService.createInstance(HoverWidget, options); - hover.onDispose(() => this._currentHoverOptions = undefined); - const provider = this._contextViewService as IContextViewProvider; - provider.showContextView(new HoverContextViewDelegate(hover, focus)); - hover.onRequestLayout(() => provider.layout()); - } - - hideHover(): void { - if (!this._currentHoverOptions) { - return; - } - this._currentHoverOptions = undefined; - this._contextViewService.hideContextView(); - } -} - -class HoverContextViewDelegate implements IDelegate { - - get anchorPosition() { - return this._hover.anchor; - } - - constructor( - private readonly _hover: HoverWidget, - private readonly _focus: boolean = false - ) { - } - - render(container: HTMLElement) { - this._hover.render(container); - if (this._focus) { - this._hover.focus(); - } - return this._hover; - } - - getAnchor() { - return { - x: this._hover.x, - y: this._hover.y - }; - } - - layout() { - this._hover.layout(); - } -} diff --git a/src/vs/workbench/contrib/notebook/electron-browser/notebook.contribution.ts b/src/vs/workbench/contrib/notebook/electron-browser/notebook.contribution.ts index 9c6734c9afe..d0e8f6b32f5 100644 --- a/src/vs/workbench/contrib/notebook/electron-browser/notebook.contribution.ts +++ b/src/vs/workbench/contrib/notebook/electron-browser/notebook.contribution.ts @@ -4,40 +4,56 @@ *--------------------------------------------------------------------------------------------*/ import { isMacintosh } from 'vs/base/common/platform'; -import { registerAction2 } from 'vs/platform/actions/common/actions'; -import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; -import * as webviewCommands from 'vs/workbench/contrib/webview/electron-browser/webviewCommands'; -import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEditor'; +import { CopyAction, CutAction, PasteAction } from 'vs/editor/contrib/clipboard/clipboard'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; +import { getActiveNotebookEditor } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions'; import { ElectronWebviewBasedWebview } from 'vs/workbench/contrib/webview/electron-browser/webviewElement'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { getActiveNotebookEditor } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions'; - -function getActiveElectronBasedWebviewDelegate(accessor: ServicesAccessor): ElectronWebviewBasedWebview | undefined { +import { UndoCommand, RedoCommand } from 'vs/editor/browser/editorExtensions'; +function getFocusedElectronBasedWebviewDelegate(accessor: ServicesAccessor): ElectronWebviewBasedWebview | undefined { const editorService = accessor.get(IEditorService); const editor = getActiveNotebookEditor(editorService); + if (!editor?.hasFocus()) { + return; + } const webview = editor?.getInnerWebview(); - if (webview && webview instanceof ElectronWebviewBasedWebview) { return webview; } - return; } -function registerNotebookCommands(editorId: string): void { - const contextKeyExpr = ContextKeyExpr.and(ContextKeyExpr.equals('activeEditor', editorId), ContextKeyExpr.not('editorFocus') /* https://github.com/Microsoft/vscode/issues/58668 */)!; - - // These commands are only needed on MacOS where we have to disable the menu bar commands - if (isMacintosh) { - registerAction2(class extends webviewCommands.CopyWebviewEditorCommand { constructor() { super(contextKeyExpr, getActiveElectronBasedWebviewDelegate); } }); - registerAction2(class extends webviewCommands.PasteWebviewEditorCommand { constructor() { super(contextKeyExpr, getActiveElectronBasedWebviewDelegate); } }); - registerAction2(class extends webviewCommands.CutWebviewEditorCommand { constructor() { super(contextKeyExpr, getActiveElectronBasedWebviewDelegate); } }); - registerAction2(class extends webviewCommands.UndoWebviewEditorCommand { constructor() { super(contextKeyExpr, getActiveElectronBasedWebviewDelegate); } }); - registerAction2(class extends webviewCommands.RedoWebviewEditorCommand { constructor() { super(contextKeyExpr, getActiveElectronBasedWebviewDelegate); } }); +if (isMacintosh) { + function withWebview(accessor: ServicesAccessor, f: (webviewe: ElectronWebviewBasedWebview) => void) { + const webview = getFocusedElectronBasedWebviewDelegate(accessor); + if (webview) { + f(webview); + return true; + } + return false; } -} -registerNotebookCommands(NotebookEditor.ID); + const PRIORITY = 100; + + UndoCommand.addImplementation(PRIORITY, accessor => { + return withWebview(accessor, webview => webview.undo()); + }); + + RedoCommand.addImplementation(PRIORITY, accessor => { + return withWebview(accessor, webview => webview.redo()); + }); + + CopyAction?.addImplementation(PRIORITY, accessor => { + return withWebview(accessor, webview => webview.copy()); + }); + + PasteAction?.addImplementation(PRIORITY, accessor => { + return withWebview(accessor, webview => webview.paste()); + }); + + CutAction?.addImplementation(PRIORITY, accessor => { + return withWebview(accessor, webview => webview.cut()); + }); +} diff --git a/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts b/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts index 68d03cbb441..5bfbe8133ab 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts @@ -93,8 +93,8 @@ Registry.as(EditorExtensions.Editors).registerEditor( // Register Preferences Editor Input Factory class PreferencesEditorInputFactory extends AbstractSideBySideEditorInputFactory { - protected createEditorInput(name: string, description: string | undefined, detailsInput: EditorInput, masterInput: EditorInput): EditorInput { - return new PreferencesEditorInput(name, description, detailsInput, masterInput); + protected createEditorInput(name: string, description: string | undefined, secondaryInput: EditorInput, primaryInput: EditorInput): EditorInput { + return new PreferencesEditorInput(name, description, secondaryInput, primaryInput); } } diff --git a/src/vs/workbench/contrib/preferences/browser/preferencesEditor.ts b/src/vs/workbench/contrib/preferences/browser/preferencesEditor.ts index 6b866bfa1c9..9ace126eef3 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferencesEditor.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferencesEditor.ts @@ -206,7 +206,7 @@ export class PreferencesEditor extends BaseEditor { } private updateInput(newInput: PreferencesEditorInput, options: EditorOptions | undefined, token: CancellationToken): Promise { - return this.sideBySidePreferencesWidget.setInput(newInput.details, newInput.master, options, token).then(({ defaultPreferencesRenderer, editablePreferencesRenderer }) => { + return this.sideBySidePreferencesWidget.setInput(newInput.secondary, newInput.primary, options, token).then(({ defaultPreferencesRenderer, editablePreferencesRenderer }) => { if (token.isCancellationRequested) { return; } diff --git a/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts b/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts index 4292cab7ccb..da898adea82 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts @@ -651,7 +651,7 @@ class EditSettingRenderer extends Disposable { private readonly _onUpdateSetting: Emitter<{ key: string, value: any, source: IIndexedSetting }> = new Emitter<{ key: string, value: any, source: IIndexedSetting }>(); readonly onUpdateSetting: Event<{ key: string, value: any, source: IIndexedSetting }> = this._onUpdateSetting.event; - constructor(private editor: ICodeEditor, private masterSettingsModel: ISettingsEditorModel, + constructor(private editor: ICodeEditor, private primarySettingsModel: ISettingsEditorModel, private settingHighlighter: SettingHighlighter, @IInstantiationService private readonly instantiationService: IInstantiationService, @IContextMenuService private readonly contextMenuService: IContextMenuService @@ -683,7 +683,7 @@ class EditSettingRenderer extends Disposable { } private isDefaultSettings(): boolean { - return this.masterSettingsModel instanceof DefaultSettingsEditorModel; + return this.primarySettingsModel instanceof DefaultSettingsEditorModel; } private onConfigurationChanged(): void { @@ -769,7 +769,7 @@ class EditSettingRenderer extends Disposable { return true; } if (configurationNode.type === 'boolean' || configurationNode.enum) { - if ((this.masterSettingsModel).configurationTarget !== ConfigurationTarget.WORKSPACE_FOLDER) { + if ((this.primarySettingsModel).configurationTarget !== ConfigurationTarget.WORKSPACE_FOLDER) { return true; } if (configurationNode.scope === ConfigurationScope.RESOURCE || configurationNode.scope === ConfigurationScope.LANGUAGE_OVERRIDABLE) { diff --git a/src/vs/workbench/contrib/scm/browser/repositoryPane.ts b/src/vs/workbench/contrib/scm/browser/repositoryPane.ts index 8fa07b9a010..4209db7b980 100644 --- a/src/vs/workbench/contrib/scm/browser/repositoryPane.ts +++ b/src/vs/workbench/contrib/scm/browser/repositoryPane.ts @@ -667,7 +667,7 @@ class ViewModel { return; } - const uri = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }); + const uri = toResource(editor, { supportSideBySide: SideBySideEditor.PRIMARY }); if (!uri) { return; diff --git a/src/vs/workbench/contrib/search/common/search.ts b/src/vs/workbench/contrib/search/common/search.ts index b63a4223a13..54a624656d2 100644 --- a/src/vs/workbench/contrib/search/common/search.ts +++ b/src/vs/workbench/contrib/search/common/search.ts @@ -96,7 +96,7 @@ export function getOutOfWorkspaceEditorResources(accessor: ServicesAccessor): UR const fileService = accessor.get(IFileService); const resources = editorService.editors - .map(editor => toResource(editor, { supportSideBySide: SideBySideEditor.MASTER })) + .map(editor => toResource(editor, { supportSideBySide: SideBySideEditor.PRIMARY })) .filter(resource => !!resource && !contextService.isInsideWorkspace(resource) && fileService.canHandleResource(resource)); return resources as URI[]; diff --git a/src/vs/workbench/contrib/terminal/browser/widgets/environmentVariableInfoWidget.ts b/src/vs/workbench/contrib/terminal/browser/widgets/environmentVariableInfoWidget.ts index be7027f563f..3bd49844533 100644 --- a/src/vs/workbench/contrib/terminal/browser/widgets/environmentVariableInfoWidget.ts +++ b/src/vs/workbench/contrib/terminal/browser/widgets/environmentVariableInfoWidget.ts @@ -11,7 +11,7 @@ import { RunOnceScheduler } from 'vs/base/common/async'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import * as dom from 'vs/base/browser/dom'; import { IDisposable } from 'vs/base/common/lifecycle'; -import { IHoverService, IHoverOptions } from 'vs/workbench/contrib/hover/browser/hover'; +import { IHoverService, IHoverOptions } from 'vs/workbench/services/hover/browser/hover'; export class EnvironmentVariableInfoWidget extends Widget implements ITerminalWidget { readonly id = 'env-var-info'; diff --git a/src/vs/workbench/contrib/terminal/browser/widgets/terminalHoverWidget.ts b/src/vs/workbench/contrib/terminal/browser/widgets/terminalHoverWidget.ts index 460f320761e..121573ea0f5 100644 --- a/src/vs/workbench/contrib/terminal/browser/widgets/terminalHoverWidget.ts +++ b/src/vs/workbench/contrib/terminal/browser/widgets/terminalHoverWidget.ts @@ -9,7 +9,7 @@ import { Widget } from 'vs/base/browser/ui/widget'; import { ITerminalWidget } from 'vs/workbench/contrib/terminal/browser/widgets/widgets'; import * as dom from 'vs/base/browser/dom'; import { IViewportRange } from 'xterm'; -import { IHoverTarget, IHoverService } from 'vs/workbench/contrib/hover/browser/hover'; +import { IHoverTarget, IHoverService } from 'vs/workbench/services/hover/browser/hover'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; import { editorHoverHighlight } from 'vs/platform/theme/common/colorRegistry'; diff --git a/src/vs/workbench/contrib/timeline/browser/timelinePane.ts b/src/vs/workbench/contrib/timeline/browser/timelinePane.ts index 9edb19c78cb..9eb51448f22 100644 --- a/src/vs/workbench/contrib/timeline/browser/timelinePane.ts +++ b/src/vs/workbench/contrib/timeline/browser/timelinePane.ts @@ -347,7 +347,7 @@ export class TimelinePane extends ViewPane { const editor = this.editorService.activeEditor; if (editor) { - uri = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }); + uri = toResource(editor, { supportSideBySide: SideBySideEditor.PRIMARY }); } if ((uri?.toString(true) === this.uri?.toString(true) && uri !== undefined) || diff --git a/src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts b/src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts index 2ad3de14e65..f29590ead7d 100644 --- a/src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts +++ b/src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts @@ -143,6 +143,8 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo this._register(userDataSyncService.onDidChangeConflicts(() => this.onDidChangeConflicts(this.userDataSyncService.conflicts))); this._register(userDataSyncService.onSyncErrors(errors => this.onSynchronizerErrors(errors))); this._register(userDataAutoSyncService.onError(error => this.onAutoSyncError(error))); + this._register(userDataAutoSyncService.onTurnOnSync(() => this.turningOnSync = true)); + this._register(userDataAutoSyncService.onDidTurnOnSync(() => this.turningOnSync = false)); this.registerActions(); this.registerViews(); @@ -176,7 +178,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo // close stale conflicts editor previews if (conflictsEditorInputs.length) { conflictsEditorInputs.forEach(input => { - if (!conflicts.some(({ local }) => isEqual(local, input.master.resource))) { + if (!conflicts.some(({ local }) => isEqual(local, input.primary.resource))) { input.dispose(); } }); @@ -338,7 +340,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo return; } const resource = source === SyncResource.Settings ? this.workbenchEnvironmentService.settingsResource : this.workbenchEnvironmentService.keybindingsResource; - if (isEqual(resource, toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.MASTER }))) { + if (isEqual(resource, toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }))) { // Do not show notification if the file in error is active return; } @@ -402,7 +404,6 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo } private async turnOn(): Promise { - this.turningOnSync = true; try { if (!this.storageService.getBoolean('sync.donotAskPreviewConfirmation', StorageScope.GLOBAL, false)) { if (!await this.askForConfirmation()) { @@ -438,8 +439,6 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo } } this.notificationService.error(localize('turn on failed', "Error while starting Sync: {0}", toErrorMessage(e))); - } finally { - this.turningOnSync = false; } } @@ -591,14 +590,14 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo private getConflictsEditorInputs(syncResource: SyncResource): DiffEditorInput[] { return this.editorService.editors.filter(input => { - const resource = input instanceof DiffEditorInput ? input.master.resource : input.resource; + const resource = input instanceof DiffEditorInput ? input.primary.resource : input.resource; return resource && getSyncResourceFromLocalPreview(resource!, this.workbenchEnvironmentService) === syncResource; }) as DiffEditorInput[]; } private getAllConflictsEditorInputs(): IEditorInput[] { return this.editorService.editors.filter(input => { - const resource = input instanceof DiffEditorInput ? input.master.resource : input.resource; + const resource = input instanceof DiffEditorInput ? input.primary.resource : input.resource; return resource && getSyncResourceFromLocalPreview(resource!, this.workbenchEnvironmentService) !== undefined; }); } diff --git a/src/vs/workbench/contrib/userDataSync/electron-browser/userDataAutoSyncService.ts b/src/vs/workbench/contrib/userDataSync/electron-browser/userDataAutoSyncService.ts index fb778ec18af..bf841f93119 100644 --- a/src/vs/workbench/contrib/userDataSync/electron-browser/userDataAutoSyncService.ts +++ b/src/vs/workbench/contrib/userDataSync/electron-browser/userDataAutoSyncService.ts @@ -18,6 +18,8 @@ export class UserDataAutoSyncService extends UserDataAutoSyncEnablementService i declare readonly _serviceBrand: undefined; private readonly channel: IChannel; + get onTurnOnSync(): Event { return this.channel.listen('onTurnOnSync'); } + get onDidTurnOnSync(): Event { return Event.map(this.channel.listen('onDidTurnOnSync'), e => e ? UserDataSyncError.toUserDataSyncError(e) : undefined); } get onError(): Event { return Event.map(this.channel.listen('onError'), e => UserDataSyncError.toUserDataSyncError(e)); } constructor( diff --git a/src/vs/workbench/contrib/webview/browser/webviewCommands.ts b/src/vs/workbench/contrib/webview/browser/webviewCommands.ts index 9f949d73926..3ed7a1964cb 100644 --- a/src/vs/workbench/contrib/webview/browser/webviewCommands.ts +++ b/src/vs/workbench/contrib/webview/browser/webviewCommands.ts @@ -32,7 +32,7 @@ export class ShowWebViewEditorFindWidgetAction extends Action2 { } public run(accessor: ServicesAccessor): void { - getActiveWebviewEditor(accessor)?.showFind(); + getFocusedWebviewEditor(accessor)?.showFind(); } } @@ -53,7 +53,7 @@ export class HideWebViewEditorFindCommand extends Action2 { } public run(accessor: ServicesAccessor): void { - getActiveWebviewEditor(accessor)?.hideFind(); + getFocusedWebviewEditor(accessor)?.hideFind(); } } @@ -74,7 +74,7 @@ export class WebViewEditorFindNextCommand extends Action2 { } public run(accessor: ServicesAccessor): void { - getActiveWebviewEditor(accessor)?.runFindAction(false); + getFocusedWebviewEditor(accessor)?.runFindAction(false); } } @@ -95,7 +95,7 @@ export class WebViewEditorFindPreviousCommand extends Action2 { } public run(accessor: ServicesAccessor): void { - getActiveWebviewEditor(accessor)?.runFindAction(true); + getFocusedWebviewEditor(accessor)?.runFindAction(true); } } @@ -117,7 +117,7 @@ export class SelectAllWebviewEditorCommand extends Action2 { } public run(accessor: ServicesAccessor): void { - getActiveWebviewEditor(accessor)?.selectAll(); + getFocusedWebviewEditor(accessor)?.selectAll(); } } @@ -142,8 +142,8 @@ export class ReloadWebviewAction extends Action { } } -export function getActiveWebviewEditor(accessor: ServicesAccessor): Webview | undefined { +export function getFocusedWebviewEditor(accessor: ServicesAccessor): Webview | undefined { const editorService = accessor.get(IEditorService); - const activeEditor = editorService.activeEditor; + const activeEditor = editorService.activeEditorPane; return activeEditor instanceof WebviewInput ? activeEditor.webview : undefined; } diff --git a/src/vs/workbench/contrib/webview/electron-browser/webview.contribution.ts b/src/vs/workbench/contrib/webview/electron-browser/webview.contribution.ts index ed4ad60e2ed..56d95808d70 100644 --- a/src/vs/workbench/contrib/webview/electron-browser/webview.contribution.ts +++ b/src/vs/workbench/contrib/webview/electron-browser/webview.contribution.ts @@ -4,15 +4,18 @@ *--------------------------------------------------------------------------------------------*/ import { isMacintosh } from 'vs/base/common/platform'; -import { SyncActionDescriptor, registerAction2 } from 'vs/platform/actions/common/actions'; -import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; +import { CopyAction, CutAction, PasteAction } from 'vs/editor/contrib/clipboard/clipboard'; +import { SyncActionDescriptor } from 'vs/platform/actions/common/actions'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; +import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { Registry } from 'vs/platform/registry/common/platform'; import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions'; -import { IWebviewService, webviewDeveloperCategory } from 'vs/workbench/contrib/webview/browser/webview'; -import { WebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewEditor'; +import { IWebviewService, webviewDeveloperCategory, WebviewOverlay } from 'vs/workbench/contrib/webview/browser/webview'; +import { getFocusedWebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewCommands'; import * as webviewCommands from 'vs/workbench/contrib/webview/electron-browser/webviewCommands'; +import { ElectronWebviewBasedWebview } from 'vs/workbench/contrib/webview/electron-browser/webviewElement'; import { ElectronWebviewService } from 'vs/workbench/contrib/webview/electron-browser/webviewService'; +import { UndoCommand, RedoCommand } from 'vs/editor/browser/editorExtensions'; registerSingleton(IWebviewService, ElectronWebviewService, true); @@ -23,17 +26,53 @@ actionRegistry.registerWorkbenchAction( webviewCommands.OpenWebviewDeveloperToolsAction.ALIAS, webviewDeveloperCategory); -function registerWebViewCommands(editorId: string): void { - const contextKeyExpr = ContextKeyExpr.and(ContextKeyExpr.equals('activeEditor', editorId), ContextKeyExpr.not('editorFocus') /* https://github.com/Microsoft/vscode/issues/58668 */)!; +if (isMacintosh) { + function getActiveElectronBasedWebview(accessor: ServicesAccessor): ElectronWebviewBasedWebview | undefined { + const webview = getFocusedWebviewEditor(accessor); + if (!webview) { + return undefined; + } - // These commands are only needed on MacOS where we have to disable the menu bar commands - if (isMacintosh) { - registerAction2(class extends webviewCommands.CopyWebviewEditorCommand { constructor() { super(contextKeyExpr); } }); - registerAction2(class extends webviewCommands.PasteWebviewEditorCommand { constructor() { super(contextKeyExpr); } }); - registerAction2(class extends webviewCommands.CutWebviewEditorCommand { constructor() { super(contextKeyExpr); } }); - registerAction2(class extends webviewCommands.UndoWebviewEditorCommand { constructor() { super(contextKeyExpr); } }); - registerAction2(class extends webviewCommands.RedoWebviewEditorCommand { constructor() { super(contextKeyExpr); } }); + if (webview instanceof ElectronWebviewBasedWebview) { + return webview; + } else if ('getInnerWebview' in (webview as WebviewOverlay)) { + const innerWebview = (webview as WebviewOverlay).getInnerWebview(); + if (innerWebview instanceof ElectronWebviewBasedWebview) { + return innerWebview; + } + } + + return undefined; } -} -registerWebViewCommands(WebviewEditor.ID); + function withWebview(accessor: ServicesAccessor, f: (webviewe: ElectronWebviewBasedWebview) => void) { + const webview = getActiveElectronBasedWebview(accessor); + if (webview) { + f(webview); + return true; + } + return false; + } + + const PRIORITY = 100; + + UndoCommand.addImplementation(PRIORITY, accessor => { + return withWebview(accessor, webview => webview.undo()); + }); + + RedoCommand.addImplementation(PRIORITY, accessor => { + return withWebview(accessor, webview => webview.redo()); + }); + + CopyAction?.addImplementation(PRIORITY, accessor => { + return withWebview(accessor, webview => webview.copy()); + }); + + PasteAction?.addImplementation(PRIORITY, accessor => { + return withWebview(accessor, webview => webview.paste()); + }); + + CutAction?.addImplementation(PRIORITY, accessor => { + return withWebview(accessor, webview => webview.cut()); + }); +} diff --git a/src/vs/workbench/contrib/webview/electron-browser/webviewCommands.ts b/src/vs/workbench/contrib/webview/electron-browser/webviewCommands.ts index 1486280626c..08ccb9be4d8 100644 --- a/src/vs/workbench/contrib/webview/electron-browser/webviewCommands.ts +++ b/src/vs/workbench/contrib/webview/electron-browser/webviewCommands.ts @@ -5,16 +5,7 @@ import { WebviewTag } from 'electron'; import { Action } from 'vs/base/common/actions'; -import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; -import { ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import * as nls from 'vs/nls'; -import { Action2 } from 'vs/platform/actions/common/actions'; -import { ContextKeyExpr, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey'; -import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys'; -import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; -import { WebviewOverlay, webviewHasOwnEditFunctionsContextKey } from 'vs/workbench/contrib/webview/browser/webview'; -import { getActiveWebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewCommands'; -import { ElectronWebviewBasedWebview } from 'vs/workbench/contrib/webview/electron-browser/webviewElement'; export class OpenWebviewDeveloperToolsAction extends Action { static readonly ID = 'workbench.action.webview.openDeveloperTools'; @@ -37,128 +28,3 @@ export class OpenWebviewDeveloperToolsAction extends Action { return true; } } - -export class CopyWebviewEditorCommand extends Action2 { - public static readonly ID = 'editor.action.webvieweditor.copy'; - public static readonly LABEL = nls.localize('editor.action.webvieweditor.copy', "Copy2"); - - constructor(contextKeyExpr: ContextKeyExpression, readonly getActiveElectronBasedWebviewDelegate: (accessor: ServicesAccessor) => ElectronWebviewBasedWebview | undefined = getActiveElectronBasedWebview) { - super({ - id: CopyWebviewEditorCommand.ID, - title: CopyWebviewEditorCommand.LABEL, - keybinding: { - when: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)), - primary: KeyMod.CtrlCmd | KeyCode.KEY_C, - weight: KeybindingWeight.EditorContrib - } - }); - } - - public run(accessor: ServicesAccessor): void { - this.getActiveElectronBasedWebviewDelegate(accessor)?.copy(); - } -} - -export class PasteWebviewEditorCommand extends Action2 { - public static readonly ID = 'editor.action.webvieweditor.paste'; - public static readonly LABEL = nls.localize('editor.action.webvieweditor.paste', 'Paste'); - - constructor(contextKeyExpr: ContextKeyExpression, readonly getActiveElectronBasedWebviewDelegate: (accessor: ServicesAccessor) => ElectronWebviewBasedWebview | undefined = getActiveElectronBasedWebview) { - super({ - id: PasteWebviewEditorCommand.ID, - title: PasteWebviewEditorCommand.LABEL, - keybinding: { - when: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)), - primary: KeyMod.CtrlCmd | KeyCode.KEY_V, - weight: KeybindingWeight.EditorContrib - } - }); - } - - public run(accessor: ServicesAccessor): void { - this.getActiveElectronBasedWebviewDelegate(accessor)?.paste(); - } -} - -export class CutWebviewEditorCommand extends Action2 { - public static readonly ID = 'editor.action.webvieweditor.cut'; - public static readonly LABEL = nls.localize('editor.action.webvieweditor.cut', 'Cut'); - - constructor(contextKeyExpr: ContextKeyExpression, readonly getActiveElectronBasedWebviewDelegate: (accessor: ServicesAccessor) => ElectronWebviewBasedWebview | undefined = getActiveElectronBasedWebview) { - super({ - id: CutWebviewEditorCommand.ID, - title: CutWebviewEditorCommand.LABEL, - keybinding: { - when: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)), - primary: KeyMod.CtrlCmd | KeyCode.KEY_X, - weight: KeybindingWeight.EditorContrib - } - }); - } - - public run(accessor: ServicesAccessor): void { - this.getActiveElectronBasedWebviewDelegate(accessor)?.cut(); - } -} - -export class UndoWebviewEditorCommand extends Action2 { - public static readonly ID = 'editor.action.webvieweditor.undo'; - public static readonly LABEL = nls.localize('editor.action.webvieweditor.undo', "Undo"); - - constructor(contextKeyExpr: ContextKeyExpression, readonly getActiveElectronBasedWebviewDelegate: (accessor: ServicesAccessor) => ElectronWebviewBasedWebview | undefined = getActiveElectronBasedWebview) { - super({ - id: UndoWebviewEditorCommand.ID, - title: UndoWebviewEditorCommand.LABEL, - keybinding: { - when: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey), ContextKeyExpr.not(webviewHasOwnEditFunctionsContextKey)), - primary: KeyMod.CtrlCmd | KeyCode.KEY_Z, - weight: KeybindingWeight.EditorContrib - } - }); - } - - public run(accessor: ServicesAccessor): void { - this.getActiveElectronBasedWebviewDelegate(accessor)?.undo(); - } -} - -export class RedoWebviewEditorCommand extends Action2 { - public static readonly ID = 'editor.action.webvieweditor.redo'; - public static readonly LABEL = nls.localize('editor.action.webvieweditor.redo', "Redo"); - - constructor(contextKeyExpr: ContextKeyExpression, readonly getActiveElectronBasedWebviewDelegate: (accessor: ServicesAccessor) => ElectronWebviewBasedWebview | undefined = getActiveElectronBasedWebview) { - super({ - id: RedoWebviewEditorCommand.ID, - title: RedoWebviewEditorCommand.LABEL, - keybinding: { - when: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey), ContextKeyExpr.not(webviewHasOwnEditFunctionsContextKey)), - primary: KeyMod.CtrlCmd | KeyCode.KEY_Y, - secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z], - mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z }, - weight: KeybindingWeight.EditorContrib - } - }); - } - - public run(accessor: ServicesAccessor): void { - this.getActiveElectronBasedWebviewDelegate(accessor)?.redo(); - } -} - -function getActiveElectronBasedWebview(accessor: ServicesAccessor): ElectronWebviewBasedWebview | undefined { - const webview = getActiveWebviewEditor(accessor); - if (!webview) { - return undefined; - } - - if (webview instanceof ElectronWebviewBasedWebview) { - return webview; - } else if ('getInnerWebview' in (webview as WebviewOverlay)) { - const innerWebview = (webview as WebviewOverlay).getInnerWebview(); - if (innerWebview instanceof ElectronWebviewBasedWebview) { - return innerWebview; - } - } - - return undefined; -} diff --git a/src/vs/workbench/electron-browser/window.ts b/src/vs/workbench/electron-browser/window.ts index cbd9955eb0c..faad0d1cea1 100644 --- a/src/vs/workbench/electron-browser/window.ts +++ b/src/vs/workbench/electron-browser/window.ts @@ -138,7 +138,7 @@ export class NativeWindow extends Disposable { if (request.from === 'touchbar') { const activeEditor = this.editorService.activeEditor; if (activeEditor) { - const resource = toResource(activeEditor, { supportSideBySide: SideBySideEditor.MASTER }); + const resource = toResource(activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }); if (resource) { args.push(resource); } @@ -250,7 +250,7 @@ export class NativeWindow extends Disposable { // macOS OS integration if (isMacintosh) { this._register(this.editorService.onDidActiveEditorChange(() => { - const file = toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.MASTER, filterByScheme: Schemas.file }); + const file = toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY, filterByScheme: Schemas.file }); // Represented Filename this.updateRepresentedFilename(file?.fsPath); diff --git a/src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts b/src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts index 4cf2dddfdfb..15f0c38bb70 100644 --- a/src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts +++ b/src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts @@ -25,6 +25,7 @@ import { coalesce } from 'vs/base/common/arrays'; import { trim } from 'vs/base/common/strings'; import { IModeService } from 'vs/editor/common/services/modeService'; import { ILabelService } from 'vs/platform/label/common/label'; +import { isWindows } from 'vs/base/common/platform'; export abstract class AbstractFileDialogService implements IFileDialogService { @@ -254,7 +255,7 @@ export abstract class AbstractFileDialogService implements IFileDialogService { const options: ISaveDialogOptions = { defaultUri, title: nls.localize('saveAsTitle', "Save As"), - availableFileSystems, + availableFileSystems }; interface IFilter { name: string; extensions: string[]; } @@ -282,8 +283,12 @@ export abstract class AbstractFileDialogService implements IFileDialogService { // We have no matching filter, e.g. because the language // is unknown. We still add the extension to the list of // filters though so that it can be picked - // (https://github.com/microsoft/vscode/issues/96283) - if (!matchingFilter && ext) { + // (https://github.com/microsoft/vscode/issues/96283) but + // only on Windows where this is an issue. Adding this to + // macOS would result in the following bugs: + // https://github.com/microsoft/vscode/issues/100614 and + // https://github.com/microsoft/vscode/issues/100241 + if (isWindows && !matchingFilter && ext) { matchingFilter = { name: trim(ext, '.').toUpperCase(), extensions: [trim(ext, '.')] }; } diff --git a/src/vs/workbench/services/editor/browser/codeEditorService.ts b/src/vs/workbench/services/editor/browser/codeEditorService.ts index b1b93a22314..ad4d75f6caa 100644 --- a/src/vs/workbench/services/editor/browser/codeEditorService.ts +++ b/src/vs/workbench/services/editor/browser/codeEditorService.ts @@ -12,6 +12,7 @@ import { TextEditorOptions } from 'vs/workbench/common/editor'; import { ACTIVE_GROUP, IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; +import { extUri } from 'vs/base/common/resources'; export class CodeEditorService extends CodeEditorServiceImpl { @@ -47,13 +48,13 @@ export class CodeEditorService extends CodeEditorServiceImpl { // side as separate editor. const activeTextEditorControl = this.editorService.activeTextEditorControl; if ( - !sideBySide && // we need the current active group to be the taret - isDiffEditor(activeTextEditorControl) && // we only support this for active text diff editors - input.options && // we need options to apply - input.resource && // we need a request resource to compare with - activeTextEditorControl.getModel() && // we need a target model to compare with - source === activeTextEditorControl.getModifiedEditor() && // we need the source of this request to be the modified side of the diff editor - input.resource.toString() === activeTextEditorControl.getModel()!.modified.uri.toString() // we need the input resources to match with modified side + !sideBySide && // we need the current active group to be the taret + isDiffEditor(activeTextEditorControl) && // we only support this for active text diff editors + input.options && // we need options to apply + input.resource && // we need a request resource to compare with + activeTextEditorControl.getModel() && // we need a target model to compare with + source === activeTextEditorControl.getModifiedEditor() && // we need the source of this request to be the modified side of the diff editor + extUri.isEqual(input.resource, activeTextEditorControl.getModel()!.modified.uri) // we need the input resources to match with modified side ) { const targetEditor = activeTextEditorControl.getModifiedEditor(); diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index a0653ec679a..4cd489bac56 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -185,8 +185,8 @@ export class EditorService extends Disposable implements EditorServiceImpl { for (const editor of this.visibleEditors) { const resources = distinct(coalesce([ - toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }), - toResource(editor, { supportSideBySide: SideBySideEditor.DETAILS }) + toResource(editor, { supportSideBySide: SideBySideEditor.PRIMARY }), + toResource(editor, { supportSideBySide: SideBySideEditor.SECONDARY }) ]), resource => resource.toString()); for (const resource of resources) { @@ -248,7 +248,7 @@ export class EditorService extends Disposable implements EditorServiceImpl { // Determine new resulting target resource let targetResource: URI; - if (source.toString() === resource.toString()) { + if (extUri.isEqual(source, resource)) { targetResource = target; // file got moved } else { const ignoreCase = !this.fileService.hasCapability(resource, FileSystemProviderCapabilities.PathCaseSensitive); @@ -380,8 +380,8 @@ export class EditorService extends Disposable implements EditorServiceImpl { for (const editor of this.editors) { if (options.supportSideBySide && editor instanceof SideBySideEditorInput) { - conditionallyAddEditor(editor.master); - conditionallyAddEditor(editor.details); + conditionallyAddEditor(editor.primary); + conditionallyAddEditor(editor.secondary); } else { conditionallyAddEditor(editor); } @@ -1193,13 +1193,13 @@ export class EditorService extends Disposable implements EditorServiceImpl { return new Promise(resolve => { const listener = this.onDidCloseEditor(async event => { - const detailsResource = toResource(event.editor, { supportSideBySide: SideBySideEditor.DETAILS }); - const masterResource = toResource(event.editor, { supportSideBySide: SideBySideEditor.MASTER }); + const primaryResource = toResource(event.editor, { supportSideBySide: SideBySideEditor.PRIMARY }); + const secondaryResource = toResource(event.editor, { supportSideBySide: SideBySideEditor.SECONDARY }); // Remove from resources to wait for being closed based on the // resources from editors that got closed remainingEditors = remainingEditors.filter(({ resource }) => { - if (this.uriIdentityService.extUri.isEqual(resource, masterResource) || this.uriIdentityService.extUri.isEqual(resource, detailsResource)) { + if (this.uriIdentityService.extUri.isEqual(resource, primaryResource) || this.uriIdentityService.extUri.isEqual(resource, secondaryResource)) { return false; // remove - the closing editor matches this resource } diff --git a/src/vs/workbench/services/editor/test/browser/editorService.test.ts b/src/vs/workbench/services/editor/test/browser/editorService.test.ts index 009cab9fd5a..bec876bc4d3 100644 --- a/src/vs/workbench/services/editor/test/browser/editorService.test.ts +++ b/src/vs/workbench/services/editor/test/browser/editorService.test.ts @@ -377,8 +377,8 @@ suite('EditorService', () => { // Untyped Input (diff) input = service.createEditorInput({ - leftResource: toResource.call(this, '/master.html'), - rightResource: toResource.call(this, '/detail.html') + leftResource: toResource.call(this, '/primary.html'), + rightResource: toResource.call(this, '/secondary.html') }); assert(input instanceof DiffEditorInput); }); @@ -1084,7 +1084,7 @@ suite('EditorService', () => { const editor = await service.openEditor(input1, { pinned: true }); await service.openEditor(input2, { pinned: true }); - const whenClosed = service.whenClosed([input1, input2]); + const whenClosed = service.whenClosed([{ resource: input1.resource }, { resource: input2.resource }]); editor?.group?.closeAllEditors(); diff --git a/src/vs/workbench/services/environment/browser/environmentService.ts b/src/vs/workbench/services/environment/browser/environmentService.ts index b94b266326e..9369ad3a7dc 100644 --- a/src/vs/workbench/services/environment/browser/environmentService.ts +++ b/src/vs/workbench/services/environment/browser/environmentService.ts @@ -62,12 +62,12 @@ export class BrowserEnvironmentConfiguration implements IEnvironmentConfiguratio @memoize get filesToDiff(): IPath[] | undefined { if (this.payload) { - const fileToDiffDetail = this.payload.get('diffFileDetail'); - const fileToDiffMaster = this.payload.get('diffFileMaster'); - if (fileToDiffDetail && fileToDiffMaster) { + const fileToDiffPrimary = this.payload.get('diffFilePrimary'); + const fileToDiffSecondary = this.payload.get('diffFileSecondary'); + if (fileToDiffPrimary && fileToDiffSecondary) { return [ - { fileUri: URI.parse(fileToDiffDetail) }, - { fileUri: URI.parse(fileToDiffMaster) } + { fileUri: URI.parse(fileToDiffSecondary) }, + { fileUri: URI.parse(fileToDiffPrimary) } ]; } } diff --git a/src/vs/workbench/services/extensionManagement/common/extensionManagement.ts b/src/vs/workbench/services/extensionManagement/common/extensionManagement.ts index d245a6341b9..60dedce0946 100644 --- a/src/vs/workbench/services/extensionManagement/common/extensionManagement.ts +++ b/src/vs/workbench/services/extensionManagement/common/extensionManagement.ts @@ -6,7 +6,7 @@ import { Event } from 'vs/base/common/event'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { URI } from 'vs/base/common/uri'; -import { IExtension } from 'vs/platform/extensions/common/extensions'; +import { IExtension, IScannedExtension, ExtensionType } from 'vs/platform/extensions/common/extensions'; import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { IWorkspace, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IStringDictionary } from 'vs/base/common/collections'; @@ -137,3 +137,9 @@ export interface IExtensionRecommendationsService { getIgnoredRecommendations(): ReadonlyArray; onRecommendationChange: Event; } + +export const IWebExtensionsScannerService = createDecorator('IWebExtensionsScannerService'); +export interface IWebExtensionsScannerService { + readonly _serviceBrand: undefined; + scanExtensions(type?: ExtensionType): Promise; +} diff --git a/src/vs/workbench/services/extensionManagement/browser/extensionManagementServerService.ts b/src/vs/workbench/services/extensionManagement/common/extensionManagementServerService.ts similarity index 97% rename from src/vs/workbench/services/extensionManagement/browser/extensionManagementServerService.ts rename to src/vs/workbench/services/extensionManagement/common/extensionManagementServerService.ts index 90d8d385b78..388d6996081 100644 --- a/src/vs/workbench/services/extensionManagement/browser/extensionManagementServerService.ts +++ b/src/vs/workbench/services/extensionManagement/common/extensionManagementServerService.ts @@ -13,7 +13,7 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { ILabelService } from 'vs/platform/label/common/label'; import { isWeb } from 'vs/base/common/platform'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { WebExtensionManagementService } from 'vs/workbench/services/extensionManagement/browser/webExtensionManagementService'; +import { WebExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/webExtensionManagementService'; import { IExtension } from 'vs/platform/extensions/common/extensions'; export class ExtensionManagementServerService implements IExtensionManagementServerService { diff --git a/src/vs/workbench/services/extensionManagement/browser/webExtensionManagementService.ts b/src/vs/workbench/services/extensionManagement/common/webExtensionManagementService.ts similarity index 51% rename from src/vs/workbench/services/extensionManagement/browser/webExtensionManagementService.ts rename to src/vs/workbench/services/extensionManagement/common/webExtensionManagementService.ts index b598c7b60a9..a48110e34da 100644 --- a/src/vs/workbench/services/extensionManagement/browser/webExtensionManagementService.ts +++ b/src/vs/workbench/services/extensionManagement/common/webExtensionManagementService.ts @@ -3,42 +3,15 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { ExtensionType, IExtensionIdentifier, IExtensionManifest, IExtension } from 'vs/platform/extensions/common/extensions'; +import { ExtensionType, IExtensionIdentifier, IExtensionManifest, IScannedExtension } from 'vs/platform/extensions/common/extensions'; import { IExtensionManagementService, ILocalExtension, InstallExtensionEvent, DidInstallExtensionEvent, DidUninstallExtensionEvent, IGalleryExtension, IReportedExtension, IGalleryMetadata } from 'vs/platform/extensionManagement/common/extensionManagement'; import { Event } from 'vs/base/common/event'; import { URI } from 'vs/base/common/uri'; -import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; -import { isWeb } from 'vs/base/common/platform'; - -let builtinExtensions: IExtension[] = []; - -// Web -if (isWeb) { - - // Running out of sources - if (Object.keys(builtinExtensions).length === 0) { - // Find builtin extensions by checking for DOM - const builtinExtensionsElement = document.getElementById('vscode-workbench-builtin-extensions'); - const builtinExtensionsElementAttribute = builtinExtensionsElement ? builtinExtensionsElement.getAttribute('data-settings') : undefined; - if (builtinExtensionsElementAttribute) { - try { - builtinExtensions = JSON.parse(builtinExtensionsElementAttribute); - } catch (error) { /* ignore error*/ } - } - } -} - -// Unknown -else { - throw new Error('Unable to resolve builtin extensions'); -} - -builtinExtensions = builtinExtensions.map(extension => ({ - ...extension, - location: URI.revive(extension.location), - readmeUrl: URI.revive(extension.readmeUrl), - changelogUrl: URI.revive(extension.changelogUrl), -})); +import { IRequestService, isSuccess, asText } from 'vs/platform/request/common/request'; +import { CancellationToken } from 'vs/base/common/cancellation'; +import { localizeManifest } from 'vs/platform/extensionManagement/common/extensionNls'; +import { getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil'; +import { IWebExtensionsScannerService } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; export class WebExtensionManagementService implements IExtensionManagementService { @@ -49,35 +22,39 @@ export class WebExtensionManagementService implements IExtensionManagementServic onUninstallExtension: Event = Event.None; onDidUninstallExtension: Event = Event.None; - private readonly systemExtensions: ILocalExtension[]; - private readonly staticExtensions: ILocalExtension[]; - constructor( - @IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService + @IWebExtensionsScannerService private readonly webExtensionsScannerService: IWebExtensionsScannerService, + @IRequestService private readonly requestService: IRequestService, ) { - this.systemExtensions = builtinExtensions.map(e => ({ ...e, type: ExtensionType.System, isMachineScoped: false, publisherId: null, publisherDisplayName: null })); - const staticExtensions = environmentService.options && Array.isArray(environmentService.options.staticExtensions) ? environmentService.options.staticExtensions : []; - - this.staticExtensions = staticExtensions.map(data => { - type: ExtensionType.User, - identifier: { id: `${data.packageJSON.publisher}.${data.packageJSON.name}` }, - manifest: data.packageJSON, - location: data.extensionLocation, - isMachineScoped: false, - publisherId: null, - publisherDisplayName: null - }); } async getInstalled(type?: ExtensionType): Promise { - const extensions = []; - if (type === undefined || type === ExtensionType.System) { - extensions.push(...this.systemExtensions); + const extensions = await this.webExtensionsScannerService.scanExtensions(type); + return Promise.all(extensions.map(e => this.toLocalExtension(e))); + } + + private async toLocalExtension(scannedExtension: IScannedExtension): Promise { + let manifest = scannedExtension.packageJSON; + if (scannedExtension.packageNLSUrl) { + try { + const context = await this.requestService.request({ type: 'GET', url: scannedExtension.packageNLSUrl.toString() }, CancellationToken.None); + if (isSuccess(context)) { + const content = await asText(context); + if (content) { + manifest = localizeManifest(manifest, JSON.parse(content)); + } + } + } catch (error) { /* ignore */ } } - if (type === undefined || type === ExtensionType.User) { - extensions.push(...this.staticExtensions); - } - return extensions; + return { + type: ExtensionType.System, + identifier: { id: getGalleryExtensionId(manifest.publisher, manifest.name) }, + manifest, + location: scannedExtension.location, + isMachineScoped: false, + publisherId: null, + publisherDisplayName: null + }; } zip(extension: ILocalExtension): Promise { throw new Error('unsupported'); } diff --git a/src/vs/workbench/services/extensionManagement/common/webExtensionsScannerService.ts b/src/vs/workbench/services/extensionManagement/common/webExtensionsScannerService.ts new file mode 100644 index 00000000000..7203814b018 --- /dev/null +++ b/src/vs/workbench/services/extensionManagement/common/webExtensionsScannerService.ts @@ -0,0 +1,46 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { IBuiltinExtensionsScannerService, IScannedExtension, ExtensionType } from 'vs/platform/extensions/common/extensions'; +import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; +import { IWebExtensionsScannerService } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; +import { isWeb } from 'vs/base/common/platform'; +import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; + +export class WebExtensionsScannerService implements IWebExtensionsScannerService { + + declare readonly _serviceBrand: undefined; + + private readonly systemExtensionsPromise: Promise; + private readonly userExtensions: IScannedExtension[]; + + constructor( + @IBuiltinExtensionsScannerService private readonly builtinExtensionsScannerService: IBuiltinExtensionsScannerService, + @IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService + ) { + this.systemExtensionsPromise = isWeb ? this.builtinExtensionsScannerService.scanBuiltinExtensions() : Promise.resolve([]); + const staticExtensions = environmentService.options && Array.isArray(environmentService.options.staticExtensions) ? environmentService.options.staticExtensions : []; + this.userExtensions = staticExtensions.map(data => { + location: data.extensionLocation, + type: ExtensionType.User, + packageJSON: data.packageJSON, + }); + } + + async scanExtensions(type?: ExtensionType): Promise { + const extensions = []; + if (type === undefined || type === ExtensionType.System) { + const systemExtensions = await this.systemExtensionsPromise; + extensions.push(...systemExtensions); + } + if (type === undefined || type === ExtensionType.User) { + extensions.push(...this.userExtensions); + } + return extensions; + } + +} + +registerSingleton(IWebExtensionsScannerService, WebExtensionsScannerService); diff --git a/src/vs/workbench/services/extensions/browser/extensionService.ts b/src/vs/workbench/services/extensions/browser/extensionService.ts index 5a6453f9950..5042393d735 100644 --- a/src/vs/workbench/services/extensions/browser/extensionService.ts +++ b/src/vs/workbench/services/extensions/browser/extensionService.ts @@ -5,15 +5,15 @@ import * as nls from 'vs/nls'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; -import { IWorkbenchExtensionEnablementService, IExtensionManagementServerService } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; +import { IWorkbenchExtensionEnablementService, IWebExtensionsScannerService } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; -import { IExtensionService, IExtensionHost, toExtensionDescription } from 'vs/workbench/services/extensions/common/extensions'; +import { IExtensionService, IExtensionHost } from 'vs/workbench/services/extensions/common/extensions'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { IFileService } from 'vs/platform/files/common/files'; import { IProductService } from 'vs/platform/product/common/productService'; -import { AbstractExtensionService } from 'vs/workbench/services/extensions/common/abstractExtensionService'; +import { AbstractExtensionService, parseScannedExtension } from 'vs/workbench/services/extensions/common/abstractExtensionService'; import { RemoteExtensionHost, IInitDataProvider } from 'vs/workbench/services/extensions/common/remoteExtensionHost'; import { IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment'; import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; @@ -44,7 +44,7 @@ export class ExtensionService extends AbstractExtensionService implements IExten @IRemoteAuthorityResolverService private readonly _remoteAuthorityResolverService: IRemoteAuthorityResolverService, @IRemoteAgentService private readonly _remoteAgentService: IRemoteAgentService, @IConfigurationService private readonly _configService: IConfigurationService, - @IExtensionManagementServerService private readonly _extensionManagementServerService: IExtensionManagementServerService, + @IWebExtensionsScannerService private readonly _webExtensionsScannerService: IWebExtensionsScannerService, ) { super( instantiationService, @@ -104,9 +104,7 @@ export class ExtensionService extends AbstractExtensionService implements IExten // fetch the remote environment let [remoteEnv, localExtensions] = await Promise.all([ this._remoteAgentService.getEnvironment(), - this._extensionManagementServerService.webExtensionManagementServer - ? this._extensionManagementServerService.webExtensionManagementServer.extensionManagementService.getInstalled().then(extensions => extensions.map(toExtensionDescription)) - : Promise.resolve([]) + this._webExtensionsScannerService.scanExtensions().then(extensions => extensions.map(parseScannedExtension)) ]); let result: DeltaExtensionsResult; diff --git a/src/vs/workbench/services/extensions/common/abstractExtensionService.ts b/src/vs/workbench/services/extensions/common/abstractExtensionService.ts index a4da7b242a8..d360eefba90 100644 --- a/src/vs/workbench/services/extensions/common/abstractExtensionService.ts +++ b/src/vs/workbench/services/extensions/common/abstractExtensionService.ts @@ -20,7 +20,7 @@ import { ExtensionMessageCollector, ExtensionPoint, ExtensionsRegistry, IExtensi import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry'; import { ResponsiveState } from 'vs/workbench/services/extensions/common/rpcProtocol'; import { ExtensionHostManager } from 'vs/workbench/services/extensions/common/extensionHostManager'; -import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions'; +import { ExtensionIdentifier, IExtensionDescription, IScannedExtension, ExtensionType } from 'vs/platform/extensions/common/extensions'; import { IFileService } from 'vs/platform/files/common/files'; import { parseExtensionDevOptions } from 'vs/workbench/services/extensions/common/extensionDevOptions'; import { IProductService } from 'vs/platform/product/common/productService'; @@ -29,6 +29,16 @@ import { ExtensionActivationReason } from 'vs/workbench/api/common/extHostExtens const hasOwnProperty = Object.hasOwnProperty; const NO_OP_VOID_PROMISE = Promise.resolve(undefined); +export function parseScannedExtension(extension: IScannedExtension): IExtensionDescription { + return { + identifier: new ExtensionIdentifier(`${extension.packageJSON.publisher}.${extension.packageJSON.name}`), + isBuiltin: extension.type === ExtensionType.System, + isUnderDevelopment: false, + extensionLocation: extension.location, + ...extension.packageJSON, + }; +} + export abstract class AbstractExtensionService extends Disposable implements IExtensionService { public _serviceBrand: undefined; diff --git a/src/vs/workbench/services/extensions/electron-browser/extensionService.ts b/src/vs/workbench/services/extensions/electron-browser/extensionService.ts index a504f6817ae..bee57873c2b 100644 --- a/src/vs/workbench/services/extensions/electron-browser/extensionService.ts +++ b/src/vs/workbench/services/extensions/electron-browser/extensionService.ts @@ -6,12 +6,12 @@ import { LocalProcessExtensionHost } from 'vs/workbench/services/extensions/electron-browser/localProcessExtensionHost'; import { CachedExtensionScanner } from 'vs/workbench/services/extensions/electron-browser/cachedExtensionScanner'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; -import { AbstractExtensionService } from 'vs/workbench/services/extensions/common/abstractExtensionService'; +import { AbstractExtensionService, parseScannedExtension } from 'vs/workbench/services/extensions/common/abstractExtensionService'; import * as nls from 'vs/nls'; import { runWhenIdle } from 'vs/base/common/async'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IExtensionManagementService, IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement'; -import { IWorkbenchExtensionEnablementService, EnablementState, IExtensionManagementServerService } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; +import { IWorkbenchExtensionEnablementService, EnablementState, IWebExtensionsScannerService } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IInitDataProvider, RemoteExtensionHost } from 'vs/workbench/services/extensions/common/remoteExtensionHost'; import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; @@ -23,7 +23,7 @@ import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/ import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IHostService } from 'vs/workbench/services/host/browser/host'; -import { IExtensionService, toExtension, ExtensionHostKind, IExtensionHost, toExtensionDescription } from 'vs/workbench/services/extensions/common/extensions'; +import { IExtensionService, toExtension, ExtensionHostKind, IExtensionHost } from 'vs/workbench/services/extensions/common/extensions'; import { ExtensionHostManager } from 'vs/workbench/services/extensions/common/extensionHostManager'; import { ExtensionIdentifier, IExtension, ExtensionType, IExtensionDescription } from 'vs/platform/extensions/common/extensions'; import { Schemas } from 'vs/base/common/network'; @@ -68,7 +68,7 @@ export class ExtensionService extends AbstractExtensionService implements IExten @IRemoteAuthorityResolverService private readonly _remoteAuthorityResolverService: IRemoteAuthorityResolverService, @IConfigurationService private readonly _configurationService: IConfigurationService, @ILifecycleService private readonly _lifecycleService: ILifecycleService, - @IExtensionManagementServerService private readonly _extensionManagementServerService: IExtensionManagementServerService, + @IWebExtensionsScannerService private readonly _webExtensionsScannerService: IWebExtensionsScannerService, @IElectronService private readonly _electronService: IElectronService, @IHostService private readonly _hostService: IHostService, @IRemoteExplorerService private readonly _remoteExplorerService: IRemoteExplorerService, @@ -447,9 +447,7 @@ export class ExtensionService extends AbstractExtensionService implements IExten const allExtensions = flatten(await Promise.all([ this._extensionScanner.scannedExtensions, - this._extensionManagementServerService.webExtensionManagementServer - ? this._extensionManagementServerService.webExtensionManagementServer.extensionManagementService.getInstalled().then(extensions => extensions.map(toExtensionDescription)) - : Promise.resolve([]) + this._webExtensionsScannerService.scanExtensions().then(extensions => extensions.map(parseScannedExtension)) ])); // enable or disable proposed API per extension diff --git a/src/vs/workbench/services/history/browser/history.ts b/src/vs/workbench/services/history/browser/history.ts index 0d1e2c3f021..0c6e54d1a2f 100644 --- a/src/vs/workbench/services/history/browser/history.ts +++ b/src/vs/workbench/services/history/browser/history.ts @@ -32,6 +32,7 @@ import { addDisposableListener, EventType, EventHelper } from 'vs/base/browser/d import { IWorkspacesService } from 'vs/platform/workspaces/common/workspaces'; import { Schemas } from 'vs/base/common/network'; import { onUnexpectedError } from 'vs/base/common/errors'; +import { extUri } from 'vs/base/common/resources'; /** * Stores the selection & view state of an editor and allows to compare it to other selection states. @@ -577,7 +578,7 @@ export class HistoryService extends Disposable implements IHistoryService { const resourceEditorInputA = arg1 as IResourceEditorInput; const resourceEditorInputB = inputB as IResourceEditorInput; - return resourceEditorInputA && resourceEditorInputB && resourceEditorInputA.resource.toString() === resourceEditorInputB.resource.toString(); + return resourceEditorInputA && resourceEditorInputB && extUri.isEqual(resourceEditorInputA.resource, resourceEditorInputB.resource); } private matchesFile(resource: URI, arg2: IEditorInput | IResourceEditorInput | FileChangesEvent): boolean { @@ -595,12 +596,12 @@ export class HistoryService extends Disposable implements IHistoryService { return false; // make sure to only check this when workbench has restored (for https://github.com/Microsoft/vscode/issues/48275) } - return inputResource.toString() === resource.toString(); + return extUri.isEqual(inputResource, resource); } const resourceEditorInput = arg2 as IResourceEditorInput; - return resourceEditorInput?.resource.toString() === resource.toString(); + return extUri.isEqual(resourceEditorInput?.resource, resource); } //#endregion @@ -632,7 +633,7 @@ export class HistoryService extends Disposable implements IHistoryService { if (URI.isUri(editorResource)) { associatedResources.push(editorResource); } else if (editorResource) { - associatedResources.push(...coalesce([editorResource.master, editorResource.detail])); + associatedResources.push(...coalesce([editorResource.primary, editorResource.secondary])); } // Remove from list of recently closed before... diff --git a/src/vs/workbench/services/host/browser/browserHostService.ts b/src/vs/workbench/services/host/browser/browserHostService.ts index 28dfed02084..d3abef54196 100644 --- a/src/vs/workbench/services/host/browser/browserHostService.ts +++ b/src/vs/workbench/services/host/browser/browserHostService.ts @@ -174,8 +174,8 @@ export class BrowserHostService extends Disposable implements IHostService { // New Window: open into empty window else { const environment = new Map(); - environment.set('diffFileDetail', editors[0].resource.toString()); - environment.set('diffFileMaster', editors[1].resource.toString()); + environment.set('diffFileSecondary', editors[0].resource.toString()); + environment.set('diffFilePrimary', editors[1].resource.toString()); this.workspaceProvider.open(undefined, { payload: Array.from(environment.entries()) }); } diff --git a/src/vs/workbench/contrib/hover/browser/hover.ts b/src/vs/workbench/services/hover/browser/hover.ts similarity index 92% rename from src/vs/workbench/contrib/hover/browser/hover.ts rename to src/vs/workbench/services/hover/browser/hover.ts index aeda610a76e..1602396e2dd 100644 --- a/src/vs/workbench/contrib/hover/browser/hover.ts +++ b/src/vs/workbench/services/hover/browser/hover.ts @@ -66,6 +66,13 @@ export interface IHoverOptions { * be used to open the links using its default options. */ linkHandler?(url: string): void; + + /** + * Whether to hide the hover when the mouse leaves the `target` and enters the actual hover. + * This is false by default and note that it will be ignored if any `actions` are provided such + * that they are accessible. + */ + hideOnHover?: boolean; } export interface IHoverAction { diff --git a/src/vs/workbench/contrib/hover/browser/hover.contribution.ts b/src/vs/workbench/services/hover/browser/hoverService.ts similarity index 55% rename from src/vs/workbench/contrib/hover/browser/hover.contribution.ts rename to src/vs/workbench/services/hover/browser/hoverService.ts index 372c4a9be8b..a025f1ddb70 100644 --- a/src/vs/workbench/contrib/hover/browser/hover.contribution.ts +++ b/src/vs/workbench/services/hover/browser/hoverService.ts @@ -5,10 +5,78 @@ import 'vs/css!./media/hover'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; -import { HoverService } from 'vs/workbench/contrib/hover/browser/hoverService'; -import { IHoverService } from 'vs/workbench/contrib/hover/browser/hover'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; import { editorHoverBackground, editorHoverBorder, textLinkForeground, editorHoverForeground, editorHoverStatusBarBackground, textCodeBlockBackground } from 'vs/platform/theme/common/colorRegistry'; +import { IHoverService, IHoverOptions } from 'vs/workbench/services/hover/browser/hover'; +import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { HoverWidget } from 'vs/workbench/services/hover/browser/hoverWidget'; +import { IContextViewProvider, IDelegate } from 'vs/base/browser/ui/contextview/contextview'; + +export class HoverService implements IHoverService { + declare readonly _serviceBrand: undefined; + + private _currentHoverOptions: IHoverOptions | undefined; + + constructor( + @IInstantiationService private readonly _instantiationService: IInstantiationService, + @IContextViewService private readonly _contextViewService: IContextViewService + ) { + } + + showHover(options: IHoverOptions, focus?: boolean): void { + if (this._currentHoverOptions === options) { + return; + } + this._currentHoverOptions = options; + + const hover = this._instantiationService.createInstance(HoverWidget, options); + hover.onDispose(() => this._currentHoverOptions = undefined); + const provider = this._contextViewService as IContextViewProvider; + provider.showContextView(new HoverContextViewDelegate(hover, focus)); + hover.onRequestLayout(() => provider.layout()); + } + + hideHover(): void { + if (!this._currentHoverOptions) { + return; + } + this._currentHoverOptions = undefined; + this._contextViewService.hideContextView(); + } +} + +class HoverContextViewDelegate implements IDelegate { + + get anchorPosition() { + return this._hover.anchor; + } + + constructor( + private readonly _hover: HoverWidget, + private readonly _focus: boolean = false + ) { + } + + render(container: HTMLElement) { + this._hover.render(container); + if (this._focus) { + this._hover.focus(); + } + return this._hover; + } + + getAnchor() { + return { + x: this._hover.x, + y: this._hover.y + }; + } + + layout() { + this._hover.layout(); + } +} registerSingleton(IHoverService, HoverService, true); diff --git a/src/vs/workbench/contrib/hover/browser/hoverWidget.ts b/src/vs/workbench/services/hover/browser/hoverWidget.ts similarity index 95% rename from src/vs/workbench/contrib/hover/browser/hoverWidget.ts rename to src/vs/workbench/services/hover/browser/hoverWidget.ts index e6926919f90..702e4e5143b 100644 --- a/src/vs/workbench/contrib/hover/browser/hoverWidget.ts +++ b/src/vs/workbench/services/hover/browser/hoverWidget.ts @@ -8,7 +8,7 @@ import { renderMarkdown } from 'vs/base/browser/markdownRenderer'; import { Event, Emitter } from 'vs/base/common/event'; import * as dom from 'vs/base/browser/dom'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; -import { IHoverTarget, IHoverOptions } from 'vs/workbench/contrib/hover/browser/hover'; +import { IHoverTarget, IHoverOptions } from 'vs/workbench/services/hover/browser/hover'; import { KeyCode } from 'vs/base/common/keyCodes'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { EDITOR_FONT_DEFAULTS, IEditorOptions } from 'vs/editor/common/config/editorOptions'; @@ -115,7 +115,11 @@ export class HoverWidget extends Widget { this._hover.containerDomNode.appendChild(statusBarElement); } - this._mouseTracker = new CompositeMouseTracker([this._hover.containerDomNode, ...this._target.targetElements]); + const mouseTrackerTargets = [...this._target.targetElements]; + if (!options.hideOnHover || (options.actions && options.actions.length > 0)) { + mouseTrackerTargets.push(this._hover.containerDomNode); + } + this._mouseTracker = new CompositeMouseTracker(mouseTrackerTargets); this._register(this._mouseTracker.onMouseOut(() => this.dispose())); this._register(this._mouseTracker); } diff --git a/src/vs/workbench/contrib/hover/browser/media/hover.css b/src/vs/workbench/services/hover/browser/media/hover.css similarity index 100% rename from src/vs/workbench/contrib/hover/browser/media/hover.css rename to src/vs/workbench/services/hover/browser/media/hover.css diff --git a/src/vs/workbench/services/preferences/browser/preferencesService.ts b/src/vs/workbench/services/preferences/browser/preferencesService.ts index aaf4fb8720b..e6a180a5c3e 100644 --- a/src/vs/workbench/services/preferences/browser/preferencesService.ts +++ b/src/vs/workbench/services/preferences/browser/preferencesService.ts @@ -210,7 +210,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic } const editorInput = this.getActiveSettingsEditorInput() || this.lastOpenedSettingsInput; - const resource = editorInput ? editorInput.master.resource! : this.userSettingsResource; + const resource = editorInput ? editorInput.primary.resource! : this.userSettingsResource; const target = this.getConfigurationTargetFromSettingsResource(resource); return this.openOrSwitchSettings(target, resource, { query: query }); } @@ -317,7 +317,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic private async openOrSwitchSettings(configurationTarget: ConfigurationTarget, resource: URI, options?: ISettingsEditorOptions, group: IEditorGroup = this.editorGroupService.activeGroup): Promise { const editorInput = this.getActiveSettingsEditorInput(group); if (editorInput) { - const editorInputResource = editorInput.master.resource; + const editorInputResource = editorInput.primary.resource; if (editorInputResource && editorInputResource.fsPath !== resource.fsPath) { return this.doSwitchSettings(configurationTarget, resource, editorInput, group, options); } diff --git a/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts b/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts index 6b351e54cf2..18fee097595 100644 --- a/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts +++ b/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts @@ -29,7 +29,7 @@ export class PreferencesEditorInput extends SideBySideEditorInput { } getTitle(verbosity: Verbosity): string { - return this.master.getTitle(verbosity); + return this.primary.getTitle(verbosity); } } diff --git a/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts b/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts index d11789ec923..c6446cdc798 100644 --- a/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts +++ b/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts @@ -116,7 +116,8 @@ export class RipgrepTextSearchEngine { } /** - * Read the first line of stderr and return an error for display or undefined, based on a whitelist. + * Read the first line of stderr and return an error for display or undefined, based on a list of + * allowed properties. * Ripgrep produces stderr output which is not from a fatal error, and we only want the search to be * "failed" when a fatal error was produced. */ diff --git a/src/vs/workbench/services/search/node/textSearchManager.ts b/src/vs/workbench/services/search/node/textSearchManager.ts index 3433ce35537..84be2f01f98 100644 --- a/src/vs/workbench/services/search/node/textSearchManager.ts +++ b/src/vs/workbench/services/search/node/textSearchManager.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { toCanonicalName } from 'vs/base/node/encoding'; +import { toCanonicalName } from 'vs/workbench/services/textfile/common/encoding'; import * as pfs from 'vs/base/node/pfs'; import { ITextQuery } from 'vs/workbench/services/search/common/search'; import { TextSearchProvider } from 'vs/workbench/services/search/common/searchExtTypes'; diff --git a/src/vs/workbench/services/textfile/browser/browserTextFileService.ts b/src/vs/workbench/services/textfile/browser/browserTextFileService.ts index 0c4da81146a..9c2bfa4f7cf 100644 --- a/src/vs/workbench/services/textfile/browser/browserTextFileService.ts +++ b/src/vs/workbench/services/textfile/browser/browserTextFileService.ts @@ -3,18 +3,22 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { AbstractTextFileService } from 'vs/workbench/services/textfile/browser/textFileService'; -import { ITextFileService, IResourceEncodings, IResourceEncoding, TextFileEditorModelState } from 'vs/workbench/services/textfile/common/textfiles'; +import { AbstractTextFileService, EncodingOracle } from 'vs/workbench/services/textfile/browser/textFileService'; +import { ITextFileService, IResourceEncoding, TextFileEditorModelState } from 'vs/workbench/services/textfile/common/textfiles'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle'; export class BrowserTextFileService extends AbstractTextFileService { - readonly encoding: IResourceEncodings = { - async getPreferredWriteEncoding(): Promise { - return { encoding: 'utf8', hasBOM: false }; + private _browserEncoding: EncodingOracle | undefined; + + get encoding(): EncodingOracle { + if (!this._browserEncoding) { + this._browserEncoding = this._register(this.instantiationService.createInstance(BrowserEncodingOracle)); } - }; + + return this._browserEncoding; + } protected registerListeners(): void { super.registerListeners(); @@ -34,4 +38,18 @@ export class BrowserTextFileService extends AbstractTextFileService { } } +class BrowserEncodingOracle extends EncodingOracle { + async getPreferredWriteEncoding(): Promise { + return { encoding: 'utf8', hasBOM: false }; + } + + async getWriteEncoding(): Promise<{ encoding: string, addBOM: boolean }> { + return { encoding: 'utf8', addBOM: false }; + } + + async getReadEncoding(): Promise { + return 'utf8'; + } +} + registerSingleton(ITextFileService, BrowserTextFileService); diff --git a/src/vs/workbench/services/textfile/browser/textFileService.ts b/src/vs/workbench/services/textfile/browser/textFileService.ts index a27fc9bf049..fabf89c0b32 100644 --- a/src/vs/workbench/services/textfile/browser/textFileService.ts +++ b/src/vs/workbench/services/textfile/browser/textFileService.ts @@ -6,7 +6,7 @@ import * as nls from 'vs/nls'; import { URI } from 'vs/base/common/uri'; import { AsyncEmitter } from 'vs/base/common/event'; -import { ITextFileService, ITextFileStreamContent, ITextFileContent, IResourceEncodings, IReadTextFileOptions, IWriteTextFileOptions, toBufferOrReadable, TextFileOperationError, TextFileOperationResult, ITextFileSaveOptions, ITextFileEditorModelManager, TextFileCreateEvent } from 'vs/workbench/services/textfile/common/textfiles'; +import { ITextFileService, ITextFileStreamContent, ITextFileContent, IResourceEncodings, IReadTextFileOptions, IWriteTextFileOptions, toBufferOrReadable, TextFileOperationError, TextFileOperationResult, ITextFileSaveOptions, ITextFileEditorModelManager, TextFileCreateEvent, IResourceEncoding } from 'vs/workbench/services/textfile/common/textfiles'; import { IRevertOptions, IEncodingSupport } from 'vs/workbench/common/editor'; import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle'; import { IFileService, FileOperationError, FileOperationResult, IFileStatWithMetadata, ICreateFileOptions, FileOperation } from 'vs/platform/files/common/files'; @@ -19,7 +19,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { Schemas } from 'vs/base/common/network'; import { createTextBufferFactoryFromSnapshot, createTextBufferFactoryFromStream } from 'vs/editor/common/model/textModel'; import { IModelService } from 'vs/editor/common/services/modelService'; -import { joinPath, dirname, basename, toLocalResource } from 'vs/base/common/resources'; +import { joinPath, dirname, basename, toLocalResource, extUri, extname, isEqualOrParent } from 'vs/base/common/resources'; import { IDialogService, IFileDialogService, IConfirmation } from 'vs/platform/dialogs/common/dialogs'; import { VSBuffer } from 'vs/base/common/buffer'; import { ITextSnapshot, ITextModel } from 'vs/editor/common/model'; @@ -35,6 +35,10 @@ import { IPathService } from 'vs/workbench/services/path/common/pathService'; import { isValidBasename } from 'vs/base/common/extpath'; import { IWorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService'; import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity'; +import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces'; +import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { UTF8, UTF8_with_bom, UTF16be, UTF16le, encodingExists, UTF8_BOM, detectEncodingByBOMFromBuffer } from 'vs/workbench/services/textfile/common/encoding'; /** * The workbench file service implementation implements the raw file service spec and adds additional methods on top. @@ -54,8 +58,6 @@ export abstract class AbstractTextFileService extends Disposable implements ITex readonly untitled: IUntitledTextEditorModelManager = this.untitledTextEditorService; - abstract get encoding(): IResourceEncodings; - constructor( @IFileService protected readonly fileService: IFileService, @IUntitledTextEditorService private untitledTextEditorService: IUntitledTextEditorService, @@ -86,6 +88,16 @@ export abstract class AbstractTextFileService extends Disposable implements ITex //#region text file read / write / create + private _encoding: EncodingOracle | undefined; + + get encoding(): EncodingOracle { + if (!this._encoding) { + this._encoding = this._register(this.instantiationService.createInstance(EncodingOracle)); + } + + return this._encoding; + } + async read(resource: URI, options?: IReadTextFileOptions): Promise { const content = await this.fileService.readFile(resource, options); @@ -224,7 +236,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex } // Just save if target is same as models own resource - if (source.toString() === target.toString()) { + if (extUri.isEqual(source, target)) { return this.save(source, { ...options, force: true /* force to save, even if not dirty (https://github.com/microsoft/vscode/issues/99619) */ }); } @@ -491,3 +503,150 @@ export abstract class AbstractTextFileService extends Disposable implements ITex //#endregion } + +export interface IEncodingOverride { + parent?: URI; + extension?: string; + encoding: string; +} + +export class EncodingOracle extends Disposable implements IResourceEncodings { + + private _encodingOverrides: IEncodingOverride[]; + protected get encodingOverrides(): IEncodingOverride[] { return this._encodingOverrides; } + protected set encodingOverrides(value: IEncodingOverride[]) { this._encodingOverrides = value; } + + constructor( + @ITextResourceConfigurationService private textResourceConfigurationService: ITextResourceConfigurationService, + @IEnvironmentService private environmentService: IEnvironmentService, + @IWorkspaceContextService private contextService: IWorkspaceContextService, + @IFileService private fileService: IFileService + ) { + super(); + + this._encodingOverrides = this.getDefaultEncodingOverrides(); + + this.registerListeners(); + } + + private registerListeners(): void { + + // Workspace Folder Change + this._register(this.contextService.onDidChangeWorkspaceFolders(() => this.encodingOverrides = this.getDefaultEncodingOverrides())); + } + + private getDefaultEncodingOverrides(): IEncodingOverride[] { + const defaultEncodingOverrides: IEncodingOverride[] = []; + + // Global settings + defaultEncodingOverrides.push({ parent: this.environmentService.userRoamingDataHome, encoding: UTF8 }); + + // Workspace files (via extension and via untitled workspaces location) + defaultEncodingOverrides.push({ extension: WORKSPACE_EXTENSION, encoding: UTF8 }); + defaultEncodingOverrides.push({ parent: this.environmentService.untitledWorkspacesHome, encoding: UTF8 }); + + // Folder Settings + this.contextService.getWorkspace().folders.forEach(folder => { + defaultEncodingOverrides.push({ parent: joinPath(folder.uri, '.vscode'), encoding: UTF8 }); + }); + + return defaultEncodingOverrides; + } + + async getWriteEncoding(resource: URI, options?: IWriteTextFileOptions): Promise<{ encoding: string, addBOM: boolean }> { + const { encoding, hasBOM } = await this.getPreferredWriteEncoding(resource, options ? options.encoding : undefined); + + // Some encodings come with a BOM automatically + if (hasBOM) { + return { encoding, addBOM: true }; + } + + // Ensure that we preserve an existing BOM if found for UTF8 + // unless we are instructed to overwrite the encoding + const overwriteEncoding = options?.overwriteEncoding; + if (!overwriteEncoding && encoding === UTF8) { + try { + const buffer = (await this.fileService.readFile(resource, { length: UTF8_BOM.length })).value; + if (detectEncodingByBOMFromBuffer(buffer, buffer.byteLength) === UTF8_with_bom) { + return { encoding, addBOM: true }; + } + } catch (error) { + // ignore - file might not exist + } + } + + return { encoding, addBOM: false }; + } + + async getPreferredWriteEncoding(resource: URI, preferredEncoding?: string): Promise { + const resourceEncoding = await this.getEncodingForResource(resource, preferredEncoding); + + return { + encoding: resourceEncoding, + hasBOM: resourceEncoding === UTF16be || resourceEncoding === UTF16le || resourceEncoding === UTF8_with_bom // enforce BOM for certain encodings + }; + } + + getReadEncoding(resource: URI, options: IReadTextFileOptions | undefined, detectedEncoding: string | null): Promise { + let preferredEncoding: string | undefined; + + // Encoding passed in as option + if (options?.encoding) { + if (detectedEncoding === UTF8_with_bom && options.encoding === UTF8) { + preferredEncoding = UTF8_with_bom; // indicate the file has BOM if we are to resolve with UTF 8 + } else { + preferredEncoding = options.encoding; // give passed in encoding highest priority + } + } + + // Encoding detected + else if (detectedEncoding) { + preferredEncoding = detectedEncoding; + } + + // Encoding configured + else if (this.textResourceConfigurationService.getValue(resource, 'files.encoding') === UTF8_with_bom) { + preferredEncoding = UTF8; // if we did not detect UTF 8 BOM before, this can only be UTF 8 then + } + + return this.getEncodingForResource(resource, preferredEncoding); + } + + private async getEncodingForResource(resource: URI, preferredEncoding?: string): Promise { + let fileEncoding: string; + + const override = this.getEncodingOverride(resource); + if (override) { + fileEncoding = override; // encoding override always wins + } else if (preferredEncoding) { + fileEncoding = preferredEncoding; // preferred encoding comes second + } else { + fileEncoding = this.textResourceConfigurationService.getValue(resource, 'files.encoding'); // and last we check for settings + } + + if (!fileEncoding || !(await encodingExists(fileEncoding))) { + fileEncoding = UTF8; // the default is UTF 8 + } + + return fileEncoding; + } + + private getEncodingOverride(resource: URI): string | undefined { + if (this.encodingOverrides && this.encodingOverrides.length) { + for (const override of this.encodingOverrides) { + + // check if the resource is child of encoding override path + if (override.parent && isEqualOrParent(resource, override.parent)) { + return override.encoding; + } + + // check if the resource extension is equal to encoding override + if (override.extension && extname(resource) === `.${override.extension}`) { + return override.encoding; + } + } + } + + return undefined; + } +} diff --git a/src/vs/base/node/encoding.ts b/src/vs/workbench/services/textfile/common/encoding.ts similarity index 95% rename from src/vs/base/node/encoding.ts rename to src/vs/workbench/services/textfile/common/encoding.ts index f12d89fa9ae..b65f6a22faf 100644 --- a/src/vs/base/node/encoding.ts +++ b/src/vs/workbench/services/textfile/common/encoding.ts @@ -65,7 +65,7 @@ export function toDecodeStream(source: VSBufferReadableStream, options: IDecodeS // decode and write buffered content const iconv = await import('iconv-lite-umd'); decoder = iconv.getDecoder(toNodeEncoding(detected.encoding)); - const decoded = decoder.write(Buffer.from(VSBuffer.concat(bufferedChunks).buffer)); + const decoded = decoder.write(VSBuffer.concat(bufferedChunks).buffer); target.write(decoded); bufferedChunks.length = 0; @@ -89,7 +89,7 @@ export function toDecodeStream(source: VSBufferReadableStream, options: IDecodeS // if the decoder is ready, we just write directly if (decoder) { - target.write(decoder.write(Buffer.from(chunk.buffer))); + target.write(decoder.write(chunk.buffer)); } // otherwise we need to buffer the data until the stream is ready @@ -234,7 +234,13 @@ const IGNORE_ENCODINGS = ['ascii', 'utf-16', 'utf-32']; async function guessEncodingByBuffer(buffer: VSBuffer): Promise { const jschardet = await import('jschardet'); - const guessed = jschardet.detect(Buffer.from(buffer.slice(0, AUTO_ENCODING_GUESS_MAX_BYTES).buffer)); // ensure to limit buffer for guessing due to https://github.com/aadsm/jschardet/issues/53 + // ensure to limit buffer for guessing due to https://github.com/aadsm/jschardet/issues/53 + const limitedBuffer = buffer.slice(0, AUTO_ENCODING_GUESS_MAX_BYTES); + // override type since jschardet expects Buffer even though can accept Uint8Array + // can be fixed once https://github.com/aadsm/jschardet/pull/58 is merged + const jschardetTypingsWorkaround = limitedBuffer.buffer as any; + + const guessed = jschardet.detect(jschardetTypingsWorkaround); if (!guessed || !guessed.encoding) { return null; } diff --git a/src/vs/workbench/services/textfile/electron-browser/nativeTextFileService.ts b/src/vs/workbench/services/textfile/electron-browser/nativeTextFileService.ts index 63740339ab0..786be97fa43 100644 --- a/src/vs/workbench/services/textfile/electron-browser/nativeTextFileService.ts +++ b/src/vs/workbench/services/textfile/electron-browser/nativeTextFileService.ts @@ -5,7 +5,7 @@ import { localize } from 'vs/nls'; import { AbstractTextFileService } from 'vs/workbench/services/textfile/browser/textFileService'; -import { ITextFileService, ITextFileStreamContent, ITextFileContent, IResourceEncodings, IResourceEncoding, IReadTextFileOptions, IWriteTextFileOptions, stringToSnapshot, TextFileOperationResult, TextFileOperationError } from 'vs/workbench/services/textfile/common/textfiles'; +import { ITextFileService, ITextFileStreamContent, ITextFileContent, IReadTextFileOptions, IWriteTextFileOptions, stringToSnapshot, TextFileOperationResult, TextFileOperationError } from 'vs/workbench/services/textfile/common/textfiles'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { URI } from 'vs/base/common/uri'; import { IFileStatWithMetadata, ICreateFileOptions, FileOperationError, FileOperationResult, IFileStreamContent, IFileService } from 'vs/platform/files/common/files'; @@ -15,12 +15,7 @@ import { join, dirname } from 'vs/base/common/path'; import { isMacintosh } from 'vs/base/common/platform'; import { IProductService } from 'vs/platform/product/common/productService'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/textResourceConfigurationService'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; -import { UTF8, UTF8_with_bom, UTF16be, UTF16le, encodingExists, UTF8_BOM, toDecodeStream, toEncodeReadable, IDecodeStreamResult, detectEncodingByBOMFromBuffer } from 'vs/base/node/encoding'; -import { WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces'; -import { joinPath, extname, isEqualOrParent } from 'vs/base/common/resources'; -import { Disposable } from 'vs/base/common/lifecycle'; -import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { UTF8, UTF8_with_bom, toDecodeStream, toEncodeReadable, IDecodeStreamResult } from 'vs/workbench/services/textfile/common/encoding'; import { bufferToStream, VSBufferReadable } from 'vs/base/common/buffer'; import { createTextBufferFactoryFromStream } from 'vs/editor/common/model/textModel'; import { ITextSnapshot } from 'vs/editor/common/model'; @@ -64,15 +59,6 @@ export class NativeTextFileService extends AbstractTextFileService { super(fileService, untitledTextEditorService, lifecycleService, instantiationService, modelService, environmentService, dialogService, fileDialogService, textResourceConfigurationService, filesConfigurationService, textModelService, codeEditorService, pathService, workingCopyFileService, uriIdentityService); } - private _encoding: EncodingOracle | undefined; - get encoding(): EncodingOracle { - if (!this._encoding) { - this._encoding = this._register(this.instantiationService.createInstance(EncodingOracle)); - } - - return this._encoding; - } - async read(resource: URI, options?: IReadTextFileOptions): Promise { const [bufferStream, decoder] = await this.doRead(resource, { ...options, @@ -292,151 +278,4 @@ export class NativeTextFileService extends AbstractTextFileService { } } -export interface IEncodingOverride { - parent?: URI; - extension?: string; - encoding: string; -} - -export class EncodingOracle extends Disposable implements IResourceEncodings { - - private _encodingOverrides: IEncodingOverride[]; - protected get encodingOverrides(): IEncodingOverride[] { return this._encodingOverrides; } - protected set encodingOverrides(value: IEncodingOverride[]) { this._encodingOverrides = value; } - - constructor( - @ITextResourceConfigurationService private textResourceConfigurationService: ITextResourceConfigurationService, - @IEnvironmentService private environmentService: IEnvironmentService, - @IWorkspaceContextService private contextService: IWorkspaceContextService, - @IFileService private fileService: IFileService - ) { - super(); - - this._encodingOverrides = this.getDefaultEncodingOverrides(); - - this.registerListeners(); - } - - private registerListeners(): void { - - // Workspace Folder Change - this._register(this.contextService.onDidChangeWorkspaceFolders(() => this.encodingOverrides = this.getDefaultEncodingOverrides())); - } - - private getDefaultEncodingOverrides(): IEncodingOverride[] { - const defaultEncodingOverrides: IEncodingOverride[] = []; - - // Global settings - defaultEncodingOverrides.push({ parent: this.environmentService.userRoamingDataHome, encoding: UTF8 }); - - // Workspace files (via extension and via untitled workspaces location) - defaultEncodingOverrides.push({ extension: WORKSPACE_EXTENSION, encoding: UTF8 }); - defaultEncodingOverrides.push({ parent: this.environmentService.untitledWorkspacesHome, encoding: UTF8 }); - - // Folder Settings - this.contextService.getWorkspace().folders.forEach(folder => { - defaultEncodingOverrides.push({ parent: joinPath(folder.uri, '.vscode'), encoding: UTF8 }); - }); - - return defaultEncodingOverrides; - } - - async getWriteEncoding(resource: URI, options?: IWriteTextFileOptions): Promise<{ encoding: string, addBOM: boolean }> { - const { encoding, hasBOM } = await this.getPreferredWriteEncoding(resource, options ? options.encoding : undefined); - - // Some encodings come with a BOM automatically - if (hasBOM) { - return { encoding, addBOM: true }; - } - - // Ensure that we preserve an existing BOM if found for UTF8 - // unless we are instructed to overwrite the encoding - const overwriteEncoding = options?.overwriteEncoding; - if (!overwriteEncoding && encoding === UTF8) { - try { - const buffer = (await this.fileService.readFile(resource, { length: UTF8_BOM.length })).value; - if (detectEncodingByBOMFromBuffer(buffer, buffer.byteLength) === UTF8_with_bom) { - return { encoding, addBOM: true }; - } - } catch (error) { - // ignore - file might not exist - } - } - - return { encoding, addBOM: false }; - } - - async getPreferredWriteEncoding(resource: URI, preferredEncoding?: string): Promise { - const resourceEncoding = await this.getEncodingForResource(resource, preferredEncoding); - - return { - encoding: resourceEncoding, - hasBOM: resourceEncoding === UTF16be || resourceEncoding === UTF16le || resourceEncoding === UTF8_with_bom // enforce BOM for certain encodings - }; - } - - getReadEncoding(resource: URI, options: IReadTextFileOptions | undefined, detectedEncoding: string | null): Promise { - let preferredEncoding: string | undefined; - - // Encoding passed in as option - if (options?.encoding) { - if (detectedEncoding === UTF8_with_bom && options.encoding === UTF8) { - preferredEncoding = UTF8_with_bom; // indicate the file has BOM if we are to resolve with UTF 8 - } else { - preferredEncoding = options.encoding; // give passed in encoding highest priority - } - } - - // Encoding detected - else if (detectedEncoding) { - preferredEncoding = detectedEncoding; - } - - // Encoding configured - else if (this.textResourceConfigurationService.getValue(resource, 'files.encoding') === UTF8_with_bom) { - preferredEncoding = UTF8; // if we did not detect UTF 8 BOM before, this can only be UTF 8 then - } - - return this.getEncodingForResource(resource, preferredEncoding); - } - - private async getEncodingForResource(resource: URI, preferredEncoding?: string): Promise { - let fileEncoding: string; - - const override = this.getEncodingOverride(resource); - if (override) { - fileEncoding = override; // encoding override always wins - } else if (preferredEncoding) { - fileEncoding = preferredEncoding; // preferred encoding comes second - } else { - fileEncoding = this.textResourceConfigurationService.getValue(resource, 'files.encoding'); // and last we check for settings - } - - if (!fileEncoding || !(await encodingExists(fileEncoding))) { - fileEncoding = UTF8; // the default is UTF 8 - } - - return fileEncoding; - } - - private getEncodingOverride(resource: URI): string | undefined { - if (this.encodingOverrides && this.encodingOverrides.length) { - for (const override of this.encodingOverrides) { - - // check if the resource is child of encoding override path - if (override.parent && isEqualOrParent(resource, override.parent)) { - return override.encoding; - } - - // check if the resource extension is equal to encoding override - if (override.extension && extname(resource) === `.${override.extension}`) { - return override.encoding; - } - } - } - - return undefined; - } -} - registerSingleton(ITextFileService, NativeTextFileService); diff --git a/src/vs/workbench/services/textfile/test/electron-browser/textFileService.io.test.ts b/src/vs/workbench/services/textfile/test/electron-browser/textFileService.io.test.ts index 67e5bcc9e29..a5558692e2f 100644 --- a/src/vs/workbench/services/textfile/test/electron-browser/textFileService.io.test.ts +++ b/src/vs/workbench/services/textfile/test/electron-browser/textFileService.io.test.ts @@ -20,12 +20,12 @@ import { DiskFileSystemProvider } from 'vs/platform/files/node/diskFileSystemPro import { generateUuid } from 'vs/base/common/uuid'; import { join, basename } from 'vs/base/common/path'; import { getPathFromAmdModule } from 'vs/base/common/amd'; -import { UTF16be, UTF16le, UTF8_with_bom, UTF8 } from 'vs/base/node/encoding'; +import { UTF16be, UTF16le, UTF8_with_bom, UTF8 } from 'vs/workbench/services/textfile/common/encoding'; import { DefaultEndOfLine, ITextSnapshot } from 'vs/editor/common/model'; import { createTextModel } from 'vs/editor/test/common/editorTestUtils'; import { isWindows } from 'vs/base/common/platform'; import { readFileSync, statSync } from 'fs'; -import { detectEncodingByBOM } from 'vs/base/test/node/encoding/encoding.test'; +import { detectEncodingByBOM } from 'vs/workbench/services/textfile/test/node/encoding/encoding.test'; import { workbenchInstantiationService, TestNativeTextFileServiceWithEncodingOverrides } from 'vs/workbench/test/electron-browser/workbenchTestServices'; suite('Files - TextFileService i/o', function () { diff --git a/src/vs/base/test/node/encoding/encoding.test.ts b/src/vs/workbench/services/textfile/test/node/encoding/encoding.test.ts similarity index 99% rename from src/vs/base/test/node/encoding/encoding.test.ts rename to src/vs/workbench/services/textfile/test/node/encoding/encoding.test.ts index 81cd20c8a8b..f43ea2f2161 100644 --- a/src/vs/base/test/node/encoding/encoding.test.ts +++ b/src/vs/workbench/services/textfile/test/node/encoding/encoding.test.ts @@ -5,7 +5,7 @@ import * as assert from 'assert'; import * as fs from 'fs'; -import * as encoding from 'vs/base/node/encoding'; +import * as encoding from 'vs/workbench/services/textfile/common/encoding'; import * as terminalEncoding from 'vs/base/node/terminalEncoding'; import * as streams from 'vs/base/common/stream'; import * as iconv from 'iconv-lite-umd'; diff --git a/src/vs/base/test/node/encoding/fixtures/empty.txt b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/empty.txt similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/empty.txt rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/empty.txt diff --git a/src/vs/base/test/node/encoding/fixtures/some.cp1252.txt b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.cp1252.txt similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some.cp1252.txt rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.cp1252.txt diff --git a/src/vs/base/test/node/encoding/fixtures/some.css.qwoff b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.css.qwoff similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some.css.qwoff rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.css.qwoff diff --git a/src/vs/base/test/node/encoding/fixtures/some.json.png b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.json.png similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some.json.png rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.json.png diff --git a/src/vs/base/test/node/encoding/fixtures/some.pdf b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.pdf similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some.pdf rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.pdf diff --git a/src/vs/base/test/node/encoding/fixtures/some.png.txt b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.png.txt similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some.png.txt rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.png.txt diff --git a/src/vs/base/test/node/encoding/fixtures/some.qwoff.txt b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.qwoff.txt similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some.qwoff.txt rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.qwoff.txt diff --git a/src/vs/base/test/node/encoding/fixtures/some.shiftjis.txt b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.shiftjis.txt similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some.shiftjis.txt rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.shiftjis.txt diff --git a/src/vs/base/test/node/encoding/fixtures/some.xml.png b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.xml.png similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some.xml.png rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some.xml.png diff --git a/src/vs/base/test/node/encoding/fixtures/some_ansi.css b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some_ansi.css similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some_ansi.css rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some_ansi.css diff --git a/src/vs/base/test/node/encoding/fixtures/some_file.css b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some_file.css similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some_file.css rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some_file.css diff --git a/src/vs/base/test/node/encoding/fixtures/some_utf16be.css b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some_utf16be.css similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some_utf16be.css rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some_utf16be.css diff --git a/src/vs/base/test/node/encoding/fixtures/some_utf16le.css b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some_utf16le.css similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some_utf16le.css rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some_utf16le.css diff --git a/src/vs/base/test/node/encoding/fixtures/some_utf8.css b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/some_utf8.css similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/some_utf8.css rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/some_utf8.css diff --git a/src/vs/base/test/node/encoding/fixtures/utf16_be_nobom.txt b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/utf16_be_nobom.txt similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/utf16_be_nobom.txt rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/utf16_be_nobom.txt diff --git a/src/vs/base/test/node/encoding/fixtures/utf16_le_nobom.txt b/src/vs/workbench/services/textfile/test/node/encoding/fixtures/utf16_le_nobom.txt similarity index 100% rename from src/vs/base/test/node/encoding/fixtures/utf16_le_nobom.txt rename to src/vs/workbench/services/textfile/test/node/encoding/fixtures/utf16_le_nobom.txt diff --git a/src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts b/src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts index 7ecff1fba99..0e61e602a2a 100644 --- a/src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts +++ b/src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts @@ -13,6 +13,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IFileService } from 'vs/platform/files/common/files'; import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService'; +import { extUri } from 'vs/base/common/resources'; /** * An editor input to be used for untitled text buffers. @@ -122,13 +123,12 @@ export class UntitledTextEditorInput extends AbstractTextResourceEditorInput imp } matches(otherInput: unknown): boolean { - if (super.matches(otherInput) === true) { + if (otherInput === this) { return true; } - // Otherwise compare by properties if (otherInput instanceof UntitledTextEditorInput) { - return otherInput.resource.toString() === this.resource.toString(); + return extUri.isEqual(otherInput.resource, this.resource); } return false; diff --git a/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts b/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts index a2b39520076..578c545aa3c 100644 --- a/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts +++ b/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts @@ -6,7 +6,7 @@ import { IUserDataSyncService, IAuthenticationProvider, getUserDataSyncStore, isAuthenticationProvider, IUserDataAutoSyncService } from 'vs/platform/userDataSync/common/userDataSync'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; -import { IUserDataSyncWorkbenchService, IUserDataSyncAccount, AccountStatus, CONTEXT_SYNC_ENABLEMENT, CONTEXT_SYNC_STATE, CONTEXT_ACCOUNT_STATE, SHOW_SYNCED_DATA_COMMAND_ID } from 'vs/workbench/services/userDataSync/common/userDataSync'; +import { IUserDataSyncWorkbenchService, IUserDataSyncAccount, AccountStatus, CONTEXT_SYNC_ENABLEMENT, CONTEXT_SYNC_STATE, CONTEXT_ACCOUNT_STATE, SHOW_SYNCED_DATA_COMMAND_ID, SHOW_SYNC_LOG_COMMAND_ID, getSyncAreaLabel } from 'vs/workbench/services/userDataSync/common/userDataSync'; import { AuthenticationSession, AuthenticationSessionsChangeEvent } from 'vs/editor/common/modes'; import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; import { Emitter, Event } from 'vs/base/common/event'; @@ -28,6 +28,7 @@ import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { Action } from 'vs/base/common/actions'; +import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress'; type UserAccountClassification = { id: { classification: 'EndUserPseudonymizedInformation', purpose: 'BusinessInsight' }; @@ -90,6 +91,7 @@ export class UserDataSyncWorkbenchService extends Disposable implements IUserDat @IExtensionService extensionService: IExtensionService, @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService, @INotificationService private readonly notificationService: INotificationService, + @IProgressService private readonly progressService: IProgressService, @IDialogService private readonly dialogService: IDialogService, @ICommandService private readonly commandService: ICommandService, @IContextKeyService contextKeyService: IContextKeyService, @@ -219,18 +221,34 @@ export class UserDataSyncWorkbenchService extends Disposable implements IUserDat throw new Error(localize('no account', "No account available")); } - const pullFirst = await this.handleFirstTimeSync(); - await this.userDataAutoSyncService.turnOn(pullFirst); - this.notificationService.info(localize('sync turned on', "Preferences sync is turned on")); + const preferencesSyncTitle = localize('preferences sync', "Preferences Sync"); + const title = `${preferencesSyncTitle} [(${localize('details', "details")})](command:${SHOW_SYNC_LOG_COMMAND_ID})`; + await this.progressService.withProgress({ + location: ProgressLocation.Notification, + title, + delay: 500, + }, async (progress) => { + progress.report({ message: localize('turning on', "Turning on...") }); + const pullFirst = await this.isSyncingWithAnotherMachine(); + const disposable = this.userDataSyncService.onSynchronizeResource(resource => + progress.report({ message: localize('syncing resource', "Syncing {0}...", getSyncAreaLabel(resource)) })); + try { + await this.userDataAutoSyncService.turnOn(pullFirst); + } finally { + disposable.dispose(); + } + }); + + this.notificationService.info(localize('sync turned on', "{0} is turned on", title)); } turnoff(everywhere: boolean): Promise { return this.userDataAutoSyncService.turnOff(everywhere); } - private async handleFirstTimeSync(): Promise { - const isFirstTimeSyncingWithAnotherMachine = await this.userDataSyncService.isFirstTimeSyncingWithAnotherMachine(); - if (!isFirstTimeSyncingWithAnotherMachine) { + private async isSyncingWithAnotherMachine(): Promise { + const isSyncingWithAnotherMachine = await this.userDataSyncService.isFirstTimeSyncingWithAnotherMachine(); + if (!isSyncingWithAnotherMachine) { return false; } diff --git a/src/vs/workbench/services/userDataSync/electron-browser/userDataSyncService.ts b/src/vs/workbench/services/userDataSync/electron-browser/userDataSyncService.ts index a562eb0c66f..7f1084593fe 100644 --- a/src/vs/workbench/services/userDataSync/electron-browser/userDataSyncService.ts +++ b/src/vs/workbench/services/userDataSync/electron-browser/userDataSyncService.ts @@ -38,6 +38,8 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ private _onSyncErrors: Emitter<[SyncResource, UserDataSyncError][]> = this._register(new Emitter<[SyncResource, UserDataSyncError][]>()); readonly onSyncErrors: Event<[SyncResource, UserDataSyncError][]> = this._onSyncErrors.event; + get onSynchronizeResource(): Event { return this.channel.listen('onSynchronizeResource'); } + constructor( @ISharedProcessService sharedProcessService: ISharedProcessService ) { diff --git a/src/vs/workbench/test/browser/parts/editor/editor.test.ts b/src/vs/workbench/test/browser/parts/editor/editor.test.ts index e974da14e70..74821dc414f 100644 --- a/src/vs/workbench/test/browser/parts/editor/editor.test.ts +++ b/src/vs/workbench/test/browser/parts/editor/editor.test.ts @@ -34,8 +34,8 @@ suite('Workbench editor', () => { const untitled = instantiationService.createInstance(UntitledTextEditorInput, service.create()); assert.equal(toResource(untitled)!.toString(), untitled.resource.toString()); - assert.equal(toResource(untitled, { supportSideBySide: SideBySideEditor.MASTER })!.toString(), untitled.resource.toString()); - assert.equal(toResource(untitled, { supportSideBySide: SideBySideEditor.DETAILS })!.toString(), untitled.resource.toString()); + assert.equal(toResource(untitled, { supportSideBySide: SideBySideEditor.PRIMARY })!.toString(), untitled.resource.toString()); + assert.equal(toResource(untitled, { supportSideBySide: SideBySideEditor.SECONDARY })!.toString(), untitled.resource.toString()); assert.equal(toResource(untitled, { supportSideBySide: SideBySideEditor.BOTH })!.toString(), untitled.resource.toString()); assert.equal(toResource(untitled, { filterByScheme: Schemas.untitled })!.toString(), untitled.resource.toString()); assert.equal(toResource(untitled, { filterByScheme: [Schemas.file, Schemas.untitled] })!.toString(), untitled.resource.toString()); @@ -44,8 +44,8 @@ suite('Workbench editor', () => { const file = new TestEditorInput(URI.file('/some/path.txt'), 'editorResourceFileTest'); assert.equal(toResource(file)!.toString(), file.resource.toString()); - assert.equal(toResource(file, { supportSideBySide: SideBySideEditor.MASTER })!.toString(), file.resource.toString()); - assert.equal(toResource(file, { supportSideBySide: SideBySideEditor.DETAILS })!.toString(), file.resource.toString()); + assert.equal(toResource(file, { supportSideBySide: SideBySideEditor.PRIMARY })!.toString(), file.resource.toString()); + assert.equal(toResource(file, { supportSideBySide: SideBySideEditor.SECONDARY })!.toString(), file.resource.toString()); assert.equal(toResource(file, { supportSideBySide: SideBySideEditor.BOTH })!.toString(), file.resource.toString()); assert.equal(toResource(file, { filterByScheme: Schemas.file })!.toString(), file.resource.toString()); assert.equal(toResource(file, { filterByScheme: [Schemas.file, Schemas.untitled] })!.toString(), file.resource.toString()); @@ -56,20 +56,20 @@ suite('Workbench editor', () => { assert.ok(!toResource(diffEditorInput)); assert.ok(!toResource(diffEditorInput, { filterByScheme: Schemas.file })); - assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.MASTER })!.toString(), file.resource.toString()); - assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.MASTER, filterByScheme: Schemas.file })!.toString(), file.resource.toString()); - assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.MASTER, filterByScheme: [Schemas.file, Schemas.untitled] })!.toString(), file.resource.toString()); + assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.PRIMARY })!.toString(), file.resource.toString()); + assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.PRIMARY, filterByScheme: Schemas.file })!.toString(), file.resource.toString()); + assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.PRIMARY, filterByScheme: [Schemas.file, Schemas.untitled] })!.toString(), file.resource.toString()); - assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.DETAILS })!.toString(), untitled.resource.toString()); - assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.DETAILS, filterByScheme: Schemas.untitled })!.toString(), untitled.resource.toString()); - assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.DETAILS, filterByScheme: [Schemas.file, Schemas.untitled] })!.toString(), untitled.resource.toString()); + assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.SECONDARY })!.toString(), untitled.resource.toString()); + assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.SECONDARY, filterByScheme: Schemas.untitled })!.toString(), untitled.resource.toString()); + assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.SECONDARY, filterByScheme: [Schemas.file, Schemas.untitled] })!.toString(), untitled.resource.toString()); - assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH }) as { master: URI, detail: URI }).master.toString(), file.resource.toString()); - assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH, filterByScheme: Schemas.file }) as { master: URI, detail: URI }).master.toString(), file.resource.toString()); - assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH, filterByScheme: [Schemas.file, Schemas.untitled] }) as { master: URI, detail: URI }).master.toString(), file.resource.toString()); + assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH }) as { primary: URI, secondary: URI }).primary.toString(), file.resource.toString()); + assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH, filterByScheme: Schemas.file }) as { primary: URI, secondary: URI }).primary.toString(), file.resource.toString()); + assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH, filterByScheme: [Schemas.file, Schemas.untitled] }) as { primary: URI, secondary: URI }).primary.toString(), file.resource.toString()); - assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH }) as { master: URI, detail: URI }).detail.toString(), untitled.resource.toString()); - assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH, filterByScheme: Schemas.untitled }) as { master: URI, detail: URI }).detail.toString(), untitled.resource.toString()); - assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH, filterByScheme: [Schemas.file, Schemas.untitled] }) as { master: URI, detail: URI }).detail.toString(), untitled.resource.toString()); + assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH }) as { primary: URI, secondary: URI }).secondary.toString(), untitled.resource.toString()); + assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH, filterByScheme: Schemas.untitled }) as { primary: URI, secondary: URI }).secondary.toString(), untitled.resource.toString()); + assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH, filterByScheme: [Schemas.file, Schemas.untitled] }) as { primary: URI, secondary: URI }).secondary.toString(), untitled.resource.toString()); }); }); diff --git a/src/vs/workbench/test/browser/parts/editor/editorGroups.test.ts b/src/vs/workbench/test/browser/parts/editor/editorGroups.test.ts index 6f3548866d5..6c41c464c08 100644 --- a/src/vs/workbench/test/browser/parts/editor/editorGroups.test.ts +++ b/src/vs/workbench/test/browser/parts/editor/editorGroups.test.ts @@ -150,6 +150,8 @@ class NonSerializableTestEditorInput extends EditorInput { class TestFileEditorInput extends EditorInput implements IFileEditorInput { + readonly label = this.resource; + constructor(public id: string, public resource: URI) { super(); } diff --git a/src/vs/workbench/test/browser/workbenchTestServices.ts b/src/vs/workbench/test/browser/workbenchTestServices.ts index 7c42ca2d734..48cca5bef2e 100644 --- a/src/vs/workbench/test/browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/browser/workbenchTestServices.ts @@ -1056,6 +1056,9 @@ export function registerTestEditor(id: string, inputs: SyncDescriptor