Skip to content

Commit

Permalink
Merge branch 'microsoft:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
malik1u authored Aug 9, 2023
2 parents f735065 + bf9c810 commit 4ff51d9
Show file tree
Hide file tree
Showing 116 changed files with 785 additions and 563 deletions.
6 changes: 3 additions & 3 deletions extensions/markdown-language-features/src/extension.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import * as vscode from 'vscode';
import { MdLanguageClient } from './client/client';
import { CommandManager } from './commandManager';
import { registerMarkdownCommands } from './commands/index';
import { registerPasteSupport } from './languageFeatures/copyFiles/copyPaste';
import { registerLinkPasteSupport } from './languageFeatures/copyFiles/copyPasteLinks';
import { registerPasteSupport } from './languageFeatures/copyFiles/pasteResourceProvider';
import { registerLinkPasteSupport } from './languageFeatures/copyFiles/pasteUrlProvider';
import { registerDiagnosticSupport } from './languageFeatures/diagnostics';
import { registerDropIntoEditorSupport } from './languageFeatures/copyFiles/dropIntoEditor';
import { registerDropIntoEditorSupport } from './languageFeatures/copyFiles/dropResourceProvider';
import { registerFindFileReferenceSupport } from './languageFeatures/fileReferences';
import { registerUpdateLinksOnRename } from './languageFeatures/linkUpdater';
import { ILogger } from './logging';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { createEditForMediaFiles as createEditForMediaFiles, mediaMimes, tryGetUriListSnippet } from './shared';
import { Mime, mediaMimes } from '../../util/mimes';
import { Schemes } from '../../util/schemes';
import { createEditForMediaFiles, tryGetUriListSnippet } from './shared';


class MarkdownImageDropProvider implements vscode.DocumentDropEditProvider {
class ResourceDropProvider implements vscode.DocumentDropEditProvider {

public static readonly id = 'insertLink';

public static readonly dropMimeTypes = [
Mime.textUriList,
...mediaMimes,
];

private readonly _yieldTo = [
{ mimeType: 'text/plain' },
{ extensionId: 'vscode.ipynb', providerId: 'insertAttachment' },
Expand All @@ -36,10 +41,11 @@ class MarkdownImageDropProvider implements vscode.DocumentDropEditProvider {
}

private async _getUriListEdit(document: vscode.TextDocument, dataTransfer: vscode.DataTransfer, token: vscode.CancellationToken): Promise<vscode.DocumentDropEdit | undefined> {
const urlList = await dataTransfer.get('text/uri-list')?.asString();
if (!urlList) {
const urlList = await dataTransfer.get(Mime.textUriList)?.asString();
if (!urlList || token.isCancellationRequested) {
return undefined;
}

const snippet = await tryGetUriListSnippet(document, urlList, token);
if (!snippet) {
return undefined;
Expand All @@ -61,25 +67,19 @@ class MarkdownImageDropProvider implements vscode.DocumentDropEditProvider {
return;
}

const filesEdit = await createEditForMediaFiles(document, dataTransfer, token);
if (!filesEdit) {
const edit = await createEditForMediaFiles(document, dataTransfer, token);
if (!edit) {
return;
}

const edit = new vscode.DocumentDropEdit(filesEdit.snippet);
edit.label = filesEdit.label;
edit.additionalEdit = filesEdit.additionalEdits;
edit.yieldTo = this._yieldTo;
return edit;
const dropEdit = new vscode.DocumentDropEdit(edit.snippet);
dropEdit.label = edit.label;
dropEdit.additionalEdit = edit.additionalEdits;
dropEdit.yieldTo = this._yieldTo;
return dropEdit;
}
}

export function registerDropIntoEditorSupport(selector: vscode.DocumentSelector) {
return vscode.languages.registerDocumentDropEditProvider(selector, new MarkdownImageDropProvider(), {
id: MarkdownImageDropProvider.id,
dropMimeTypes: [
'text/uri-list',
...mediaMimes,
]
});
return vscode.languages.registerDocumentDropEditProvider(selector, new ResourceDropProvider(), ResourceDropProvider);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { Mime, mediaMimes } from '../../util/mimes';
import { Schemes } from '../../util/schemes';
import { createEditForMediaFiles, createEditAddingLinksForUriList, mediaMimes, getPasteUrlAsFormattedLinkSetting, PasteUrlAsFormattedLink } from './shared';
import { PasteUrlAsFormattedLink, createEditAddingLinksForUriList, createEditForMediaFiles, getPasteUrlAsFormattedLinkSetting } from './shared';

class PasteEditProvider implements vscode.DocumentPasteEditProvider {
class PasteResourceEditProvider implements vscode.DocumentPasteEditProvider {

public static readonly id = 'insertLink';

public static readonly pasteMimeTypes = [
Mime.textUriList,
...mediaMimes,
];

private readonly _yieldTo = [
{ mimeType: 'text/plain' },
{ extensionId: 'vscode.ipynb', providerId: 'insertAttachment' },
Expand All @@ -32,19 +38,26 @@ class PasteEditProvider implements vscode.DocumentPasteEditProvider {
return createEdit;
}

const uriEdit = new vscode.DocumentPasteEdit('', '');
const urlList = await dataTransfer.get('text/uri-list')?.asString();
if (!urlList) {
if (token.isCancellationRequested) {
return;
}

return this._getUriListEdit(document, ranges, dataTransfer, token);
}

private async _getUriListEdit(document: vscode.TextDocument, ranges: readonly vscode.Range[], dataTransfer: vscode.DataTransfer, token: vscode.CancellationToken): Promise<vscode.DocumentPasteEdit | undefined> {
const uriList = await dataTransfer.get(Mime.textUriList)?.asString();
if (!uriList || token.isCancellationRequested) {
return;
}

const pasteUrlSetting = getPasteUrlAsFormattedLinkSetting(document);
const pasteEdit = await createEditAddingLinksForUriList(document, ranges, urlList, false, pasteUrlSetting === PasteUrlAsFormattedLink.Smart, token);
const pasteEdit = await createEditAddingLinksForUriList(document, ranges, uriList, false, pasteUrlSetting === PasteUrlAsFormattedLink.Smart, token);
if (!pasteEdit) {
return;
}

uriEdit.label = pasteEdit.label;
const uriEdit = new vscode.DocumentPasteEdit('', pasteEdit.label);
uriEdit.additionalEdit = pasteEdit.additionalEdits;
uriEdit.yieldTo = this._yieldTo;
return uriEdit;
Expand Down Expand Up @@ -73,11 +86,5 @@ class PasteEditProvider implements vscode.DocumentPasteEditProvider {
}

export function registerPasteSupport(selector: vscode.DocumentSelector,) {
return vscode.languages.registerDocumentPasteEditProvider(selector, new PasteEditProvider(), {
id: PasteEditProvider.id,
pasteMimeTypes: [
'text/uri-list',
...mediaMimes,
]
});
return vscode.languages.registerDocumentPasteEditProvider(selector, new PasteResourceEditProvider(), PasteResourceEditProvider);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { Mime } from '../../util/mimes';
import { createEditAddingLinksForUriList, getPasteUrlAsFormattedLinkSetting, PasteUrlAsFormattedLink, validateLink } from './shared';

const textPlainMime = 'text/plain';

class PasteLinkEditProvider implements vscode.DocumentPasteEditProvider {
class PasteUrlEditProvider implements vscode.DocumentPasteEditProvider {

public static readonly id = 'insertMarkdownLink';

public static readonly pasteMimeTypes = [
Mime.textPlain,
];

async provideDocumentPasteEdits(
document: vscode.TextDocument,
ranges: readonly vscode.Range[],
Expand All @@ -23,7 +26,7 @@ class PasteLinkEditProvider implements vscode.DocumentPasteEditProvider {
return;
}

const item = dataTransfer.get(textPlainMime);
const item = dataTransfer.get(Mime.textPlain);
const urlList = await item?.asString();
if (token.isCancellationRequested || !urlList || !validateLink(urlList).isValid) {
return;
Expand All @@ -36,14 +39,11 @@ class PasteLinkEditProvider implements vscode.DocumentPasteEditProvider {

const edit = new vscode.DocumentPasteEdit('', pasteEdit.label);
edit.additionalEdit = pasteEdit.additionalEdits;
edit.yieldTo = pasteEdit.markdownLink ? undefined : [{ mimeType: textPlainMime }];
edit.yieldTo = pasteEdit.markdownLink ? undefined : [{ mimeType: Mime.textPlain }];
return edit;
}
}

export function registerLinkPasteSupport(selector: vscode.DocumentSelector,) {
return vscode.languages.registerDocumentPasteEditProvider(selector, new PasteLinkEditProvider(), {
id: PasteLinkEditProvider.id,
pasteMimeTypes: [textPlainMime]
});
return vscode.languages.registerDocumentPasteEditProvider(selector, new PasteUrlEditProvider(), PasteUrlEditProvider);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import * as path from 'path';
import * as vscode from 'vscode';
import * as URI from 'vscode-uri';
import { Schemes } from '../../util/schemes';
import { NewFilePathGenerator } from './copyFiles';
import { coalesce } from '../../util/arrays';
import { getDocumentDir } from '../../util/document';
import { mediaMimes } from '../../util/mimes';
import { Schemes } from '../../util/schemes';
import { NewFilePathGenerator } from './copyFiles';

enum MediaKind {
Image,
Expand Down Expand Up @@ -49,19 +50,6 @@ export const mediaFileExtensions = new Map<string, MediaKind>([
['wav', MediaKind.Audio],
]);

export const mediaMimes = new Set([
'image/bmp',
'image/gif',
'image/jpeg',
'image/png',
'image/webp',
'video/mp4',
'video/ogg',
'audio/mpeg',
'audio/aac',
'audio/x-wav',
]);

const smartPasteRegexes = [
{ regex: /(\[[^\[\]]*](?:\([^\(\)]*\)|\[[^\[\]]*]))/g }, // In a Markdown link
{ regex: /^```[\s\S]*?```$/gm }, // In a backtick fenced code block
Expand Down
22 changes: 22 additions & 0 deletions extensions/markdown-language-features/src/util/mimes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

export const Mime = {
textUriList: 'text/uri-list',
textPlain: 'text/plain',
} as const;

export const mediaMimes = new Set([
'image/bmp',
'image/gif',
'image/jpeg',
'image/png',
'image/webp',
'video/mp4',
'video/ogg',
'audio/mpeg',
'audio/aac',
'audio/x-wav',
]);
4 changes: 2 additions & 2 deletions extensions/theme-defaults/themes/dark_modern.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"button.border": "#FFFFFF12",
"button.foreground": "#FFFFFF",
"button.hoverBackground": "#026EC1",
"button.secondaryBackground": "#1F1F1F",
"button.secondaryBackground": "#313131",
"button.secondaryForeground": "#CCCCCC",
"button.secondaryHoverBackground": "#2B2B2B",
"button.secondaryHoverBackground": "#3C3C3C",
"chat.slashCommandBackground": "#3E4C56",
"chat.slashCommandForeground": "#7FC3FF",
"checkbox.background": "#313131",
Expand Down
2 changes: 1 addition & 1 deletion extensions/theme-defaults/themes/light_modern.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"button.hoverBackground": "#0258A8",
"button.secondaryBackground": "#E5E5E5",
"button.secondaryForeground": "#3B3B3B",
"button.secondaryHoverBackground": "#CBCBCB",
"button.secondaryHoverBackground": "#CCCCCC",
"chat.slashCommandBackground": "#D2ECFF",
"chat.slashCommandForeground": "#306CA2",
"checkbox.background": "#F8F8F8",
Expand Down
3 changes: 1 addition & 2 deletions src/vs/base/browser/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { KeyCode } from 'vs/base/common/keyCodes';
import { Disposable, DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { FileAccess, RemoteAuthorities, Schemas } from 'vs/base/common/network';
import * as platform from 'vs/base/common/platform';
import { withNullAsUndefined } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';

export function clearNode(node: HTMLElement): void {
Expand Down Expand Up @@ -1284,7 +1283,7 @@ export function triggerUpload(): Promise<FileList | undefined> {

// Resolve once the input event has fired once
event.Event.once(event.Event.fromDOMEventEmitter(input, 'input'))(() => {
resolve(withNullAsUndefined(input.files));
resolve(input.files ?? undefined);
});

input.click();
Expand Down
3 changes: 1 addition & 2 deletions src/vs/base/browser/ui/menu/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { ResolvedKeybinding } from 'vs/base/common/keybindings';
import { Disposable, dispose, IDisposable } from 'vs/base/common/lifecycle';
import { isMacintosh } from 'vs/base/common/platform';
import * as strings from 'vs/base/common/strings';
import { withNullAsUndefined } from 'vs/base/common/types';
import 'vs/css!./menubar';
import * as nls from 'vs/nls';

Expand Down Expand Up @@ -1020,7 +1019,7 @@ export class MenuBar extends Disposable {
getKeyBinding: this.options.getKeybinding,
actionRunner: this.actionRunner,
enableMnemonics: this.options.alwaysOnMnemonics || (this.mnemonicsInUse && this.options.enableMnemonics),
ariaLabel: withNullAsUndefined(customMenu.buttonElement.getAttribute('aria-label')),
ariaLabel: customMenu.buttonElement.getAttribute('aria-label') ?? undefined,
expandDirection: this.isCompact ? this.options.compactMode : Direction.Right,
useEventAsContext: true
};
Expand Down
3 changes: 1 addition & 2 deletions src/vs/base/browser/ui/toolbar/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { ThemeIcon } from 'vs/base/common/themables';
import { EventMultiplexer } from 'vs/base/common/event';
import { ResolvedKeybinding } from 'vs/base/common/keybindings';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { withNullAsUndefined } from 'vs/base/common/types';
import 'vs/css!./toolbar';
import * as nls from 'vs/nls';

Expand Down Expand Up @@ -196,7 +195,7 @@ export class ToolBar extends Disposable {
private getKeybindingLabel(action: IAction): string | undefined {
const key = this.lookupKeybindings ? this.options.getKeyBinding?.(action) : undefined;

return withNullAsUndefined(key?.getLabel());
return key?.getLabel() ?? undefined;
}

private clear(): void {
Expand Down
8 changes: 0 additions & 8 deletions src/vs/base/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,6 @@ export function validateConstraint(arg: unknown, constraint: TypeConstraint | un
}
}

/**
* Converts null to undefined, passes all other values through.
*/
export function withNullAsUndefined<T>(x: T | null): T | undefined {
return x === null ? undefined : x;
}


type AddFirstParameterToFunction<T, TargetFunctionsReturnType, FirstParameter> = T extends (...args: any[]) => TargetFunctionsReturnType ?
// Function: add param to function
(firstArg: FirstParameter, ...args: Parameters<T>) => ReturnType<T> :
Expand Down
3 changes: 1 addition & 2 deletions src/vs/base/parts/contextmenu/electron-main/contextmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

import { BrowserWindow, IpcMainEvent, Menu, MenuItem } from 'electron';
import { validatedIpcMain } from 'vs/base/parts/ipc/electron-main/ipcMain';
import { withNullAsUndefined } from 'vs/base/common/types';
import { CONTEXT_MENU_CHANNEL, CONTEXT_MENU_CLOSE_CHANNEL, IPopupOptions, ISerializableContextMenuItem } from 'vs/base/parts/contextmenu/common/contextmenu';

export function registerContextMenuListener(): void {
validatedIpcMain.on(CONTEXT_MENU_CHANNEL, (event: IpcMainEvent, contextMenuId: number, items: ISerializableContextMenuItem[], onClickChannel: string, options?: IPopupOptions) => {
const menu = createMenu(event, onClickChannel, items);

menu.popup({
window: withNullAsUndefined(BrowserWindow.fromWebContents(event.sender)),
window: BrowserWindow.fromWebContents(event.sender) ?? undefined,
x: options ? options.x : undefined,
y: options ? options.y : undefined,
positioningItem: options ? options.positioningItem : undefined,
Expand Down
3 changes: 1 addition & 2 deletions src/vs/code/electron-main/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { Event } from 'vs/base/common/event';
import { hash } from 'vs/base/common/hash';
import { Disposable } from 'vs/base/common/lifecycle';
import { withNullAsUndefined } from 'vs/base/common/types';
import { generateUuid } from 'vs/base/common/uuid';
import { ICredentialsMainService } from 'vs/platform/credentials/common/credentials';
import { IEncryptionMainService } from 'vs/platform/encryption/common/encryptionService';
Expand Down Expand Up @@ -153,7 +152,7 @@ export class ProxyAuthHandler extends Disposable {
let encryptedSerializedProxyCredentials = this.applicationStorageMainService.get(this.PROXY_CREDENTIALS_SERVICE_KEY + authInfoHash, StorageScope.APPLICATION);
let decryptedSerializedProxyCredentials: string | undefined;
if (!encryptedSerializedProxyCredentials) {
encryptedSerializedProxyCredentials = withNullAsUndefined(await this.credentialsService.getPassword(this.OLD_PROXY_CREDENTIALS_SERVICE_KEY, authInfoHash));
encryptedSerializedProxyCredentials = await this.credentialsService.getPassword(this.OLD_PROXY_CREDENTIALS_SERVICE_KEY, authInfoHash) ?? undefined;
if (encryptedSerializedProxyCredentials) {
// re-encrypt to force new encryption algorithm to apply
decryptedSerializedProxyCredentials = await this.encryptionMainService.decrypt(encryptedSerializedProxyCredentials);
Expand Down
Loading

0 comments on commit 4ff51d9

Please sign in to comment.