Skip to content

Commit

Permalink
Merge branch 'main' into joh/vscode-dts
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Nov 11, 2021
2 parents f161c7e + ec5486b commit edb91ac
Show file tree
Hide file tree
Showing 34 changed files with 364 additions and 135 deletions.
2 changes: 1 addition & 1 deletion extensions/emmet/src/abbreviationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function wrapWithAbbreviation(args: any): Promise<boolean> {

const helper = getEmmetHelper();

const operationRanges = editor.selections.sort((a, b) => a.start.compareTo(b.start)).map(selection => {
const operationRanges = Array.from(editor.selections).sort((a, b) => a.start.compareTo(b.start)).map(selection => {
let rangeToReplace: vscode.Range = selection;
// wrap around the node if the selection falls inside its open or close tag
{
Expand Down
12 changes: 5 additions & 7 deletions extensions/emmet/src/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { getHtmlFlatNode, offsetRangeToSelection, validate } from './util';
import { getRootNode } from './parseDocument';
import { HtmlNode as HtmlFlatNode } from 'EmmetFlatNode';

let balanceOutStack: Array<vscode.Selection[]> = [];
let lastBalancedSelections: vscode.Selection[] = [];
let balanceOutStack: Array<readonly vscode.Selection[]> = [];
let lastBalancedSelections: readonly vscode.Selection[] = [];

export function balanceOut() {
balance(true);
Expand All @@ -31,10 +31,8 @@ function balance(out: boolean) {
}

const rangeFn = out ? getRangeToBalanceOut : getRangeToBalanceIn;
let newSelections: vscode.Selection[] = [];
editor.selections.forEach(selection => {
const range = rangeFn(document, rootNode, selection);
newSelections.push(range);
let newSelections: readonly vscode.Selection[] = editor.selections.map(selection => {
return rangeFn(document, rootNode, selection);
});

// check whether we are starting a balance elsewhere
Expand Down Expand Up @@ -122,7 +120,7 @@ function getRangeToBalanceIn(document: vscode.TextDocument, rootNode: HtmlFlatNo
return offsetRangeToSelection(document, firstChild.start, firstChild.end);
}

function areSameSelections(a: vscode.Selection[], b: vscode.Selection[]): boolean {
function areSameSelections(a: readonly vscode.Selection[], b: readonly vscode.Selection[]): boolean {
if (a.length !== b.length) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/emmet/src/mergeLines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function mergeLines() {
}

return editor.edit(editBuilder => {
editor.selections.reverse().forEach(selection => {
Array.from(editor.selections).reverse().forEach(selection => {
const textEdit = getRangesToReplace(editor.document, selection, rootNode);
if (textEdit) {
editBuilder.replace(textEdit.range, textEdit.newText);
Expand Down
2 changes: 1 addition & 1 deletion extensions/emmet/src/removeTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function removeTag() {
return;
}

let finalRangesToRemove = editor.selections.reverse()
let finalRangesToRemove = Array.from(editor.selections).reverse()
.reduce<vscode.Range[]>((prev, selection) =>
prev.concat(getRangesToRemove(editor.document, rootNode, selection)), []);

Expand Down
2 changes: 1 addition & 1 deletion extensions/emmet/src/splitJoinTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function splitJoinTag() {
}

return editor.edit(editBuilder => {
editor.selections.reverse().forEach(selection => {
Array.from(editor.selections).reverse().forEach(selection => {
const documentText = document.getText();
const offset = document.offsetAt(selection.start);
const nodeToUpdate = getHtmlFlatNode(documentText, rootNode, offset, true);
Expand Down
2 changes: 1 addition & 1 deletion extensions/emmet/src/toggleComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function toggleComment(): Thenable<boolean> | undefined {

return editor.edit(editBuilder => {
let allEdits: vscode.TextEdit[][] = [];
editor.selections.reverse().forEach(selection => {
Array.from(editor.selections).reverse().forEach(selection => {
const edits = isStyleSheet(editor.document.languageId) ? toggleCommentStylesheet(editor.document, selection, <Stylesheet>rootNode) : toggleCommentHTML(editor.document, selection, rootNode!);
if (edits.length > 0) {
allEdits.push(edits);
Expand Down
2 changes: 1 addition & 1 deletion extensions/emmet/src/updateImageSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function updateImageSize(): Promise<boolean> | undefined {
}
const editor = window.activeTextEditor;

const allUpdatesPromise = editor.selections.reverse().map(selection => {
const allUpdatesPromise = Array.from(editor.selections).reverse().map(selection => {
const position = selection.isReversed ? selection.active : selection.anchor;
if (!isStyleSheet(editor.document.languageId)) {
return updateImageSizeHTML(editor, position);
Expand Down
2 changes: 1 addition & 1 deletion extensions/emmet/src/updateTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function updateTag(tagName: string | undefined): Promise<boolean |
return;
}

const rangesToUpdate = editor.selections.reverse()
const rangesToUpdate = Array.from(editor.selections).reverse()
.reduce<TagRange[]>((prev, selection) =>
prev.concat(getRangesToUpdate(document, selection, rootNode)), []);
if (!rangesToUpdate.length) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/git/src/staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function applyLineChanges(original: TextDocument, modified: TextDocument,
return result.join('');
}

export function toLineRanges(selections: Selection[], textDocument: TextDocument): Range[] {
export function toLineRanges(selections: readonly Selection[], textDocument: TextDocument): Range[] {
const lineRanges = selections.map(s => {
const startLine = textDocument.lineAt(s.start.line);
const endLine = textDocument.lineAt(s.end.line);
Expand Down
4 changes: 3 additions & 1 deletion extensions/git/src/test/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ suite('git smoke test', function () {
git = ext!.exports.getAPI(1);

if (git.repositories.length === 0) {
await eventToPromise(git.onDidOpenRepository);
const onDidOpenRepository = eventToPromise(git.onDidOpenRepository);
await commands.executeCommand('git.openRepository', cwd);
await onDidOpenRepository;
}

assert.strictEqual(git.repositories.length, 1);
Expand Down
18 changes: 18 additions & 0 deletions extensions/markdown-language-features/preview-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ window.addEventListener('message', async event => {
root.replaceWith(newContent.querySelector('.markdown-body')!);
documentResource = event.data.source;
} else {
// Compare two elements but skip `data-line`
const areEqual = (a: Element, b: Element): boolean => {
if (a.isEqualNode(b)) {
return true;
Expand All @@ -143,6 +144,23 @@ window.addEventListener('message', async event => {
return false;
}

const aAttrs = a.attributes;
const bAttrs = b.attributes;
if (aAttrs.length !== bAttrs.length) {
return false;
}

for (let i = 0; i < aAttrs.length; ++i) {
const aAttr = aAttrs[i];
const bAttr = bAttrs[i];
if (aAttr.name !== bAttr.name) {
return false;
}
if (aAttr.value !== bAttr.value && aAttr.name !== 'data-line') {
return false;
}
}

const aChildren = Array.from(a.children);
const bChildren = Array.from(b.children);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ function workspaceFile(...segments: string[]) {
}

async function getLinksForFile(file: vscode.Uri): Promise<vscode.DocumentLink[]> {
return (await vscode.commands.executeCommand<vscode.DocumentLink[]>('vscode.executeLinkProvider', file))!;
console.log('getting links', file.toString(), Date.now());
const r = (await vscode.commands.executeCommand<vscode.DocumentLink[]>('vscode.executeLinkProvider', file))!;
console.log('got links', file.toString(), Date.now());
return r;
}

suite('Markdown Document links', () => {
suite.skip('Markdown Document links', () => {

setup(async () => {
// the tests make the assumption that link providers are already registered
Expand Down Expand Up @@ -94,7 +97,6 @@ suite('Markdown Document links', () => {
assert.strictEqual(vscode.window.activeTextEditor!.selection.start.line, 1);
});


test('Should navigate to line number within non-md file', async () => {
await withFileContents(testFileA, '[b](sub/foo.txt#L3)');

Expand Down Expand Up @@ -147,15 +149,21 @@ function assertActiveDocumentUri(expectedUri: vscode.Uri) {
}

async function withFileContents(file: vscode.Uri, contents: string): Promise<void> {
console.log('openTextDocument', file.toString(), Date.now());
const document = await vscode.workspace.openTextDocument(file);
console.log('showTextDocument', file.toString(), Date.now());
const editor = await vscode.window.showTextDocument(document);
console.log('editTextDocument', file.toString(), Date.now());
await editor.edit(edit => {
edit.replace(new vscode.Range(0, 0, 1000, 0), contents);
});
console.log('opened done', vscode.window.activeTextEditor?.document.toString(), Date.now());
}

async function executeLink(link: vscode.DocumentLink) {
console.log('executeingLink', link.target?.toString(), Date.now());

const args = JSON.parse(decodeURIComponent(link.target!.query));
await vscode.commands.executeCommand(link.target!.path, args);
console.log('executedLink', vscode.window.activeTextEditor?.document.toString(), Date.now());
}

24 changes: 15 additions & 9 deletions src/bootstrap-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@
async function load(modulePaths, resultCallback, options) {
const isDev = !!safeProcess.env['VSCODE_DEV'];

// Error handler (TODO@sandbox non-sandboxed only)
// Error handler (node.js enabled renderers only)
let showDevtoolsOnError = isDev;
safeProcess.on('uncaughtException', function (/** @type {string | Error} */ error) {
onUnexpectedError(error, showDevtoolsOnError);
});
if (!safeProcess.sandboxed) {
safeProcess.on('uncaughtException', function (/** @type {string | Error} */ error) {
onUnexpectedError(error, showDevtoolsOnError);
});
}

// Await window configuration from preload
const timeout = setTimeout(() => { console.error(`[resolve window config] Could not resolve window configuration within 10 seconds, but will continue to wait...`); }, 10000);
Expand Down Expand Up @@ -83,7 +85,7 @@
developerDeveloperKeybindingsDisposable = registerDeveloperKeybindings(disallowReloadKeybinding);
}

// Enable ASAR support (TODO@sandbox non-sandboxed only)
// Enable ASAR support (node.js enabled renderers only)
if (!safeProcess.sandboxed) {
globalThis.MonacoBootstrap.enableASARSupport(configuration.appRoot);
}
Expand All @@ -100,9 +102,12 @@

window.document.documentElement.setAttribute('lang', locale);

// Replace the patched electron fs with the original node fs for all AMD code (TODO@sandbox non-sandboxed only)
// Define `fs` as `original-fs` to disable ASAR support
// in fs-operations (node.js enabled renderers only)
if (!safeProcess.sandboxed) {
require.define('fs', [], function () { return require.__$__nodeRequire('original-fs'); });
require.define('fs', [], function () {
return require.__$__nodeRequire('original-fs');
});
}

window['MonacoEnvironment'] = {};
Expand Down Expand Up @@ -140,8 +145,9 @@
'tas-client-umd': `${baseNodeModulesPath}/tas-client-umd/lib/tas-client-umd.js`
};

// For priviledged renderers, allow to load built-in and other node.js
// modules via AMD which has a fallback to using node.js `require`
// Allow to load built-in and other node.js modules via AMD
// which has a fallback to using node.js `require`
// (node.js enabled renderers only)
if (!safeProcess.sandboxed) {
loaderConfig.amdModulesPattern = /(^vs\/)|(^vscode-textmate$)|(^vscode-oniguruma$)|(^xterm$)|(^xterm-addon-search$)|(^xterm-addon-unicode11$)|(^xterm-addon-webgl$)|(^iconv-lite-umd$)|(^jschardet$)|(^@vscode\/vscode-languagedetection$)|(^tas-client-umd$)/;
}
Expand Down
3 changes: 0 additions & 3 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
//#region Add support for using node_modules.asar

/**
* TODO@sandbox remove the support for passing in `appRoot` once
* sandbox is fully enabled
*
* @param {string=} appRoot
*/
function enableASARSupport(appRoot) {
Expand Down
3 changes: 2 additions & 1 deletion src/vs/base/browser/ui/menu/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface IMenuBarOptions {
getKeybinding?: (action: IAction) => ResolvedKeybinding | undefined;
alwaysOnMnemonics?: boolean;
compactMode?: Direction;
actionRunner?: IActionRunner;
getCompactMenuActions?: () => IAction[]
}

Expand Down Expand Up @@ -109,7 +110,7 @@ export class MenuBar extends Disposable {

this.menuUpdater = this._register(new RunOnceScheduler(() => this.update(), 200));

this.actionRunner = this._register(new ActionRunner());
this.actionRunner = this.options.actionRunner ?? this._register(new ActionRunner());
this._register(this.actionRunner.onBeforeRun(() => {
this.setUnfocusedState();
}));
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/actions/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class MenuId {
static readonly ExplorerContext = new MenuId('ExplorerContext');
static readonly ExtensionContext = new MenuId('ExtensionContext');
static readonly GlobalActivity = new MenuId('GlobalActivity');
static readonly LayoutControlMenu = new MenuId('LayoutControlMenu');
static readonly MenubarMainMenu = new MenuId('MenubarMainMenu');
static readonly MenubarAppearanceMenu = new MenuId('MenubarAppearanceMenu');
static readonly MenubarDebugMenu = new MenuId('MenubarDebugMenu');
Expand Down
Loading

0 comments on commit edb91ac

Please sign in to comment.