feat: 添加vscode编辑器
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
.monaco-editor .accessibilityHelpWidget {
|
||||
padding: 10px;
|
||||
vertical-align: middle;
|
||||
overflow: scroll;
|
||||
}
|
||||
+308
@@ -0,0 +1,308 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
import './accessibilityHelp.css';
|
||||
import * as dom from '../../../../base/browser/dom.js';
|
||||
import { createFastDomNode } from '../../../../base/browser/fastDomNode.js';
|
||||
import { renderFormattedText } from '../../../../base/browser/formattedTextRenderer.js';
|
||||
import { alert } from '../../../../base/browser/ui/aria/aria.js';
|
||||
import { Widget } from '../../../../base/browser/ui/widget.js';
|
||||
import { Disposable } from '../../../../base/common/lifecycle.js';
|
||||
import * as platform from '../../../../base/common/platform.js';
|
||||
import * as strings from '../../../../base/common/strings.js';
|
||||
import { URI } from '../../../../base/common/uri.js';
|
||||
import { EditorAction, EditorCommand, registerEditorAction, registerEditorCommand, registerEditorContribution } from '../../../browser/editorExtensions.js';
|
||||
import { EditorContextKeys } from '../../../common/editorContextKeys.js';
|
||||
import { ToggleTabFocusModeAction } from '../../../contrib/toggleTabFocusMode/browser/toggleTabFocusMode.js';
|
||||
import { IContextKeyService, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
|
||||
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
|
||||
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';
|
||||
import { IOpenerService } from '../../../../platform/opener/common/opener.js';
|
||||
import { contrastBorder, editorWidgetBackground, widgetShadow, editorWidgetForeground } from '../../../../platform/theme/common/colorRegistry.js';
|
||||
import { registerThemingParticipant } from '../../../../platform/theme/common/themeService.js';
|
||||
import { AccessibilityHelpNLS } from '../../../common/standaloneStrings.js';
|
||||
const CONTEXT_ACCESSIBILITY_WIDGET_VISIBLE = new RawContextKey('accessibilityHelpWidgetVisible', false);
|
||||
let AccessibilityHelpController = class AccessibilityHelpController extends Disposable {
|
||||
constructor(editor, instantiationService) {
|
||||
super();
|
||||
this._editor = editor;
|
||||
this._widget = this._register(instantiationService.createInstance(AccessibilityHelpWidget, this._editor));
|
||||
}
|
||||
static get(editor) {
|
||||
return editor.getContribution(AccessibilityHelpController.ID);
|
||||
}
|
||||
show() {
|
||||
this._widget.show();
|
||||
}
|
||||
hide() {
|
||||
this._widget.hide();
|
||||
}
|
||||
};
|
||||
AccessibilityHelpController.ID = 'editor.contrib.accessibilityHelpController';
|
||||
AccessibilityHelpController = __decorate([
|
||||
__param(1, IInstantiationService)
|
||||
], AccessibilityHelpController);
|
||||
function getSelectionLabel(selections, charactersSelected) {
|
||||
if (!selections || selections.length === 0) {
|
||||
return AccessibilityHelpNLS.noSelection;
|
||||
}
|
||||
if (selections.length === 1) {
|
||||
if (charactersSelected) {
|
||||
return strings.format(AccessibilityHelpNLS.singleSelectionRange, selections[0].positionLineNumber, selections[0].positionColumn, charactersSelected);
|
||||
}
|
||||
return strings.format(AccessibilityHelpNLS.singleSelection, selections[0].positionLineNumber, selections[0].positionColumn);
|
||||
}
|
||||
if (charactersSelected) {
|
||||
return strings.format(AccessibilityHelpNLS.multiSelectionRange, selections.length, charactersSelected);
|
||||
}
|
||||
if (selections.length > 0) {
|
||||
return strings.format(AccessibilityHelpNLS.multiSelection, selections.length);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
let AccessibilityHelpWidget = class AccessibilityHelpWidget extends Widget {
|
||||
constructor(editor, _contextKeyService, _keybindingService, _openerService) {
|
||||
super();
|
||||
this._contextKeyService = _contextKeyService;
|
||||
this._keybindingService = _keybindingService;
|
||||
this._openerService = _openerService;
|
||||
this._editor = editor;
|
||||
this._isVisibleKey = CONTEXT_ACCESSIBILITY_WIDGET_VISIBLE.bindTo(this._contextKeyService);
|
||||
this._domNode = createFastDomNode(document.createElement('div'));
|
||||
this._domNode.setClassName('accessibilityHelpWidget');
|
||||
this._domNode.setDisplay('none');
|
||||
this._domNode.setAttribute('role', 'dialog');
|
||||
this._domNode.setAttribute('aria-hidden', 'true');
|
||||
this._contentDomNode = createFastDomNode(document.createElement('div'));
|
||||
this._contentDomNode.setAttribute('role', 'document');
|
||||
this._domNode.appendChild(this._contentDomNode);
|
||||
this._isVisible = false;
|
||||
this._register(this._editor.onDidLayoutChange(() => {
|
||||
if (this._isVisible) {
|
||||
this._layout();
|
||||
}
|
||||
}));
|
||||
// Intentionally not configurable!
|
||||
this._register(dom.addStandardDisposableListener(this._contentDomNode.domNode, 'keydown', (e) => {
|
||||
if (!this._isVisible) {
|
||||
return;
|
||||
}
|
||||
if (e.equals(2048 /* KeyMod.CtrlCmd */ | 35 /* KeyCode.KeyE */)) {
|
||||
alert(AccessibilityHelpNLS.emergencyConfOn);
|
||||
this._editor.updateOptions({
|
||||
accessibilitySupport: 'on'
|
||||
});
|
||||
dom.clearNode(this._contentDomNode.domNode);
|
||||
this._buildContent();
|
||||
this._contentDomNode.domNode.focus();
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
if (e.equals(2048 /* KeyMod.CtrlCmd */ | 38 /* KeyCode.KeyH */)) {
|
||||
alert(AccessibilityHelpNLS.openingDocs);
|
||||
let url = this._editor.getRawOptions().accessibilityHelpUrl;
|
||||
if (typeof url === 'undefined') {
|
||||
url = 'https://go.microsoft.com/fwlink/?linkid=852450';
|
||||
}
|
||||
this._openerService.open(URI.parse(url));
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
}));
|
||||
this.onblur(this._contentDomNode.domNode, () => {
|
||||
this.hide();
|
||||
});
|
||||
this._editor.addOverlayWidget(this);
|
||||
}
|
||||
dispose() {
|
||||
this._editor.removeOverlayWidget(this);
|
||||
super.dispose();
|
||||
}
|
||||
getId() {
|
||||
return AccessibilityHelpWidget.ID;
|
||||
}
|
||||
getDomNode() {
|
||||
return this._domNode.domNode;
|
||||
}
|
||||
getPosition() {
|
||||
return {
|
||||
preference: null
|
||||
};
|
||||
}
|
||||
show() {
|
||||
if (this._isVisible) {
|
||||
return;
|
||||
}
|
||||
this._isVisible = true;
|
||||
this._isVisibleKey.set(true);
|
||||
this._layout();
|
||||
this._domNode.setDisplay('block');
|
||||
this._domNode.setAttribute('aria-hidden', 'false');
|
||||
this._contentDomNode.domNode.tabIndex = 0;
|
||||
this._buildContent();
|
||||
this._contentDomNode.domNode.focus();
|
||||
}
|
||||
_descriptionForCommand(commandId, msg, noKbMsg) {
|
||||
const kb = this._keybindingService.lookupKeybinding(commandId);
|
||||
if (kb) {
|
||||
return strings.format(msg, kb.getAriaLabel());
|
||||
}
|
||||
return strings.format(noKbMsg, commandId);
|
||||
}
|
||||
_buildContent() {
|
||||
const options = this._editor.getOptions();
|
||||
const selections = this._editor.getSelections();
|
||||
let charactersSelected = 0;
|
||||
if (selections) {
|
||||
const model = this._editor.getModel();
|
||||
if (model) {
|
||||
selections.forEach((selection) => {
|
||||
charactersSelected += model.getValueLengthInRange(selection);
|
||||
});
|
||||
}
|
||||
}
|
||||
let text = getSelectionLabel(selections, charactersSelected);
|
||||
if (options.get(56 /* EditorOption.inDiffEditor */)) {
|
||||
if (options.get(83 /* EditorOption.readOnly */)) {
|
||||
text += AccessibilityHelpNLS.readonlyDiffEditor;
|
||||
}
|
||||
else {
|
||||
text += AccessibilityHelpNLS.editableDiffEditor;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (options.get(83 /* EditorOption.readOnly */)) {
|
||||
text += AccessibilityHelpNLS.readonlyEditor;
|
||||
}
|
||||
else {
|
||||
text += AccessibilityHelpNLS.editableEditor;
|
||||
}
|
||||
}
|
||||
const turnOnMessage = (platform.isMacintosh
|
||||
? AccessibilityHelpNLS.changeConfigToOnMac
|
||||
: AccessibilityHelpNLS.changeConfigToOnWinLinux);
|
||||
switch (options.get(2 /* EditorOption.accessibilitySupport */)) {
|
||||
case 0 /* AccessibilitySupport.Unknown */:
|
||||
text += '\n\n - ' + turnOnMessage;
|
||||
break;
|
||||
case 2 /* AccessibilitySupport.Enabled */:
|
||||
text += '\n\n - ' + AccessibilityHelpNLS.auto_on;
|
||||
break;
|
||||
case 1 /* AccessibilitySupport.Disabled */:
|
||||
text += '\n\n - ' + AccessibilityHelpNLS.auto_off;
|
||||
text += ' ' + turnOnMessage;
|
||||
break;
|
||||
}
|
||||
if (options.get(132 /* EditorOption.tabFocusMode */)) {
|
||||
text += '\n\n - ' + this._descriptionForCommand(ToggleTabFocusModeAction.ID, AccessibilityHelpNLS.tabFocusModeOnMsg, AccessibilityHelpNLS.tabFocusModeOnMsgNoKb);
|
||||
}
|
||||
else {
|
||||
text += '\n\n - ' + this._descriptionForCommand(ToggleTabFocusModeAction.ID, AccessibilityHelpNLS.tabFocusModeOffMsg, AccessibilityHelpNLS.tabFocusModeOffMsgNoKb);
|
||||
}
|
||||
const openDocMessage = (platform.isMacintosh
|
||||
? AccessibilityHelpNLS.openDocMac
|
||||
: AccessibilityHelpNLS.openDocWinLinux);
|
||||
text += '\n\n - ' + openDocMessage;
|
||||
text += '\n\n' + AccessibilityHelpNLS.outroMsg;
|
||||
this._contentDomNode.domNode.appendChild(renderFormattedText(text));
|
||||
// Per https://www.w3.org/TR/wai-aria/roles#document, Authors SHOULD provide a title or label for documents
|
||||
this._contentDomNode.domNode.setAttribute('aria-label', text);
|
||||
}
|
||||
hide() {
|
||||
if (!this._isVisible) {
|
||||
return;
|
||||
}
|
||||
this._isVisible = false;
|
||||
this._isVisibleKey.reset();
|
||||
this._domNode.setDisplay('none');
|
||||
this._domNode.setAttribute('aria-hidden', 'true');
|
||||
this._contentDomNode.domNode.tabIndex = -1;
|
||||
dom.clearNode(this._contentDomNode.domNode);
|
||||
this._editor.focus();
|
||||
}
|
||||
_layout() {
|
||||
const editorLayout = this._editor.getLayoutInfo();
|
||||
const w = Math.max(5, Math.min(AccessibilityHelpWidget.WIDTH, editorLayout.width - 40));
|
||||
const h = Math.max(5, Math.min(AccessibilityHelpWidget.HEIGHT, editorLayout.height - 40));
|
||||
this._domNode.setWidth(w);
|
||||
this._domNode.setHeight(h);
|
||||
const top = Math.round((editorLayout.height - h) / 2);
|
||||
this._domNode.setTop(top);
|
||||
const left = Math.round((editorLayout.width - w) / 2);
|
||||
this._domNode.setLeft(left);
|
||||
}
|
||||
};
|
||||
AccessibilityHelpWidget.ID = 'editor.contrib.accessibilityHelpWidget';
|
||||
AccessibilityHelpWidget.WIDTH = 500;
|
||||
AccessibilityHelpWidget.HEIGHT = 300;
|
||||
AccessibilityHelpWidget = __decorate([
|
||||
__param(1, IContextKeyService),
|
||||
__param(2, IKeybindingService),
|
||||
__param(3, IOpenerService)
|
||||
], AccessibilityHelpWidget);
|
||||
class ShowAccessibilityHelpAction extends EditorAction {
|
||||
constructor() {
|
||||
super({
|
||||
id: 'editor.action.showAccessibilityHelp',
|
||||
label: AccessibilityHelpNLS.showAccessibilityHelpAction,
|
||||
alias: 'Show Accessibility Help',
|
||||
precondition: undefined,
|
||||
kbOpts: {
|
||||
primary: 512 /* KeyMod.Alt */ | 59 /* KeyCode.F1 */,
|
||||
weight: 100 /* KeybindingWeight.EditorContrib */,
|
||||
linux: {
|
||||
primary: 512 /* KeyMod.Alt */ | 1024 /* KeyMod.Shift */ | 59 /* KeyCode.F1 */,
|
||||
secondary: [512 /* KeyMod.Alt */ | 59 /* KeyCode.F1 */]
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
run(accessor, editor) {
|
||||
const controller = AccessibilityHelpController.get(editor);
|
||||
if (controller) {
|
||||
controller.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
registerEditorContribution(AccessibilityHelpController.ID, AccessibilityHelpController);
|
||||
registerEditorAction(ShowAccessibilityHelpAction);
|
||||
const AccessibilityHelpCommand = EditorCommand.bindToContribution(AccessibilityHelpController.get);
|
||||
registerEditorCommand(new AccessibilityHelpCommand({
|
||||
id: 'closeAccessibilityHelp',
|
||||
precondition: CONTEXT_ACCESSIBILITY_WIDGET_VISIBLE,
|
||||
handler: x => x.hide(),
|
||||
kbOpts: {
|
||||
weight: 100 /* KeybindingWeight.EditorContrib */ + 100,
|
||||
kbExpr: EditorContextKeys.focus,
|
||||
primary: 9 /* KeyCode.Escape */,
|
||||
secondary: [1024 /* KeyMod.Shift */ | 9 /* KeyCode.Escape */]
|
||||
}
|
||||
}));
|
||||
registerThemingParticipant((theme, collector) => {
|
||||
const widgetBackground = theme.getColor(editorWidgetBackground);
|
||||
if (widgetBackground) {
|
||||
collector.addRule(`.monaco-editor .accessibilityHelpWidget { background-color: ${widgetBackground}; }`);
|
||||
}
|
||||
const widgetForeground = theme.getColor(editorWidgetForeground);
|
||||
if (widgetForeground) {
|
||||
collector.addRule(`.monaco-editor .accessibilityHelpWidget { color: ${widgetForeground}; }`);
|
||||
}
|
||||
const widgetShadowColor = theme.getColor(widgetShadow);
|
||||
if (widgetShadowColor) {
|
||||
collector.addRule(`.monaco-editor .accessibilityHelpWidget { box-shadow: 0 2px 8px ${widgetShadowColor}; }`);
|
||||
}
|
||||
const hcBorder = theme.getColor(contrastBorder);
|
||||
if (hcBorder) {
|
||||
collector.addRule(`.monaco-editor .accessibilityHelpWidget { border: 2px solid ${hcBorder}; }`);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,129 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var _a;
|
||||
import * as strings from '../../../base/common/strings.js';
|
||||
import { LineTokens } from '../../common/tokens/lineTokens.js';
|
||||
import { TokenizationRegistry } from '../../common/languages.js';
|
||||
import { RenderLineInput, renderViewLine2 as renderViewLine } from '../../common/viewLayout/viewLineRenderer.js';
|
||||
import { ViewLineRenderingData } from '../../common/viewModel.js';
|
||||
import { MonarchTokenizer } from '../common/monarch/monarchLexer.js';
|
||||
const ttPolicy = (_a = window.trustedTypes) === null || _a === void 0 ? void 0 : _a.createPolicy('standaloneColorizer', { createHTML: value => value });
|
||||
export class Colorizer {
|
||||
static colorizeElement(themeService, languageService, domNode, options) {
|
||||
options = options || {};
|
||||
const theme = options.theme || 'vs';
|
||||
const mimeType = options.mimeType || domNode.getAttribute('lang') || domNode.getAttribute('data-lang');
|
||||
if (!mimeType) {
|
||||
console.error('Mode not detected');
|
||||
return Promise.resolve();
|
||||
}
|
||||
const languageId = languageService.getLanguageIdByMimeType(mimeType) || mimeType;
|
||||
themeService.setTheme(theme);
|
||||
const text = domNode.firstChild ? domNode.firstChild.nodeValue : '';
|
||||
domNode.className += ' ' + theme;
|
||||
const render = (str) => {
|
||||
var _a;
|
||||
const trustedhtml = (_a = ttPolicy === null || ttPolicy === void 0 ? void 0 : ttPolicy.createHTML(str)) !== null && _a !== void 0 ? _a : str;
|
||||
domNode.innerHTML = trustedhtml;
|
||||
};
|
||||
return this.colorize(languageService, text || '', languageId, options).then(render, (err) => console.error(err));
|
||||
}
|
||||
static colorize(languageService, text, languageId, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const languageIdCodec = languageService.languageIdCodec;
|
||||
let tabSize = 4;
|
||||
if (options && typeof options.tabSize === 'number') {
|
||||
tabSize = options.tabSize;
|
||||
}
|
||||
if (strings.startsWithUTF8BOM(text)) {
|
||||
text = text.substr(1);
|
||||
}
|
||||
const lines = strings.splitLines(text);
|
||||
if (!languageService.isRegisteredLanguageId(languageId)) {
|
||||
return _fakeColorize(lines, tabSize, languageIdCodec);
|
||||
}
|
||||
const tokenizationSupport = yield TokenizationRegistry.getOrCreate(languageId);
|
||||
if (tokenizationSupport) {
|
||||
return _colorize(lines, tabSize, tokenizationSupport, languageIdCodec);
|
||||
}
|
||||
return _fakeColorize(lines, tabSize, languageIdCodec);
|
||||
});
|
||||
}
|
||||
static colorizeLine(line, mightContainNonBasicASCII, mightContainRTL, tokens, tabSize = 4) {
|
||||
const isBasicASCII = ViewLineRenderingData.isBasicASCII(line, mightContainNonBasicASCII);
|
||||
const containsRTL = ViewLineRenderingData.containsRTL(line, isBasicASCII, mightContainRTL);
|
||||
const renderResult = renderViewLine(new RenderLineInput(false, true, line, false, isBasicASCII, containsRTL, 0, tokens, [], tabSize, 0, 0, 0, 0, -1, 'none', false, false, null));
|
||||
return renderResult.html;
|
||||
}
|
||||
static colorizeModelLine(model, lineNumber, tabSize = 4) {
|
||||
const content = model.getLineContent(lineNumber);
|
||||
model.tokenization.forceTokenization(lineNumber);
|
||||
const tokens = model.tokenization.getLineTokens(lineNumber);
|
||||
const inflatedTokens = tokens.inflate();
|
||||
return this.colorizeLine(content, model.mightContainNonBasicASCII(), model.mightContainRTL(), inflatedTokens, tabSize);
|
||||
}
|
||||
}
|
||||
function _colorize(lines, tabSize, tokenizationSupport, languageIdCodec) {
|
||||
return new Promise((c, e) => {
|
||||
const execute = () => {
|
||||
const result = _actualColorize(lines, tabSize, tokenizationSupport, languageIdCodec);
|
||||
if (tokenizationSupport instanceof MonarchTokenizer) {
|
||||
const status = tokenizationSupport.getLoadStatus();
|
||||
if (status.loaded === false) {
|
||||
status.promise.then(execute, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
c(result);
|
||||
};
|
||||
execute();
|
||||
});
|
||||
}
|
||||
function _fakeColorize(lines, tabSize, languageIdCodec) {
|
||||
let html = [];
|
||||
const defaultMetadata = ((0 /* FontStyle.None */ << 11 /* MetadataConsts.FONT_STYLE_OFFSET */)
|
||||
| (1 /* ColorId.DefaultForeground */ << 15 /* MetadataConsts.FOREGROUND_OFFSET */)
|
||||
| (2 /* ColorId.DefaultBackground */ << 24 /* MetadataConsts.BACKGROUND_OFFSET */)) >>> 0;
|
||||
const tokens = new Uint32Array(2);
|
||||
tokens[0] = 0;
|
||||
tokens[1] = defaultMetadata;
|
||||
for (let i = 0, length = lines.length; i < length; i++) {
|
||||
const line = lines[i];
|
||||
tokens[0] = line.length;
|
||||
const lineTokens = new LineTokens(tokens, line, languageIdCodec);
|
||||
const isBasicASCII = ViewLineRenderingData.isBasicASCII(line, /* check for basic ASCII */ true);
|
||||
const containsRTL = ViewLineRenderingData.containsRTL(line, isBasicASCII, /* check for RTL */ true);
|
||||
const renderResult = renderViewLine(new RenderLineInput(false, true, line, false, isBasicASCII, containsRTL, 0, lineTokens, [], tabSize, 0, 0, 0, 0, -1, 'none', false, false, null));
|
||||
html = html.concat(renderResult.html);
|
||||
html.push('<br/>');
|
||||
}
|
||||
return html.join('');
|
||||
}
|
||||
function _actualColorize(lines, tabSize, tokenizationSupport, languageIdCodec) {
|
||||
let html = [];
|
||||
let state = tokenizationSupport.getInitialState();
|
||||
for (let i = 0, length = lines.length; i < length; i++) {
|
||||
const line = lines[i];
|
||||
const tokenizeResult = tokenizationSupport.tokenizeEncoded(line, true, state);
|
||||
LineTokens.convertToEndOffset(tokenizeResult.tokens, line.length);
|
||||
const lineTokens = new LineTokens(tokenizeResult.tokens, line, languageIdCodec);
|
||||
const isBasicASCII = ViewLineRenderingData.isBasicASCII(line, /* check for basic ASCII */ true);
|
||||
const containsRTL = ViewLineRenderingData.containsRTL(line, isBasicASCII, /* check for RTL */ true);
|
||||
const renderResult = renderViewLine(new RenderLineInput(false, true, line, false, isBasicASCII, containsRTL, 0, lineTokens.inflate(), [], tabSize, 0, 0, 0, 0, -1, 'none', false, false, null));
|
||||
html = html.concat(renderResult.html);
|
||||
html.push('<br/>');
|
||||
state = tokenizeResult.endState;
|
||||
}
|
||||
return html.join('');
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
.monaco-editor .iPadShowKeyboard {
|
||||
width: 58px;
|
||||
min-width: 0;
|
||||
height: 36px;
|
||||
min-height: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
position: absolute;
|
||||
resize: none;
|
||||
overflow: hidden;
|
||||
background: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTMiIGhlaWdodD0iMzYiIHZpZXdCb3g9IjAgMCA1MyAzNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwKSI+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNNDguMDM2NCA0LjAxMDQySDQuMDA3NzlMNC4wMDc3OSAzMi4wMjg2SDQ4LjAzNjRWNC4wMTA0MlpNNC4wMDc3OSAwLjAwNzgxMjVDMS43OTcyMSAwLjAwNzgxMjUgMC4wMDUxODc5OSAxLjc5OTg0IDAuMDA1MTg3OTkgNC4wMTA0MlYzMi4wMjg2QzAuMDA1MTg3OTkgMzQuMjM5MiAxLjc5NzIxIDM2LjAzMTIgNC4wMDc3OSAzNi4wMzEySDQ4LjAzNjRDNTAuMjQ3IDM2LjAzMTIgNTIuMDM5IDM0LjIzOTIgNTIuMDM5IDMyLjAyODZWNC4wMTA0MkM1Mi4wMzkgMS43OTk4NCA1MC4yNDcgMC4wMDc4MTI1IDQ4LjAzNjQgMC4wMDc4MTI1SDQuMDA3NzlaTTguMDEwNDIgOC4wMTMwMkgxMi4wMTNWMTIuMDE1Nkg4LjAxMDQyVjguMDEzMDJaTTIwLjAxODIgOC4wMTMwMkgxNi4wMTU2VjEyLjAxNTZIMjAuMDE4MlY4LjAxMzAyWk0yNC4wMjA4IDguMDEzMDJIMjguMDIzNFYxMi4wMTU2SDI0LjAyMDhWOC4wMTMwMlpNMzYuMDI4NiA4LjAxMzAySDMyLjAyNlYxMi4wMTU2SDM2LjAyODZWOC4wMTMwMlpNNDAuMDMxMiA4LjAxMzAySDQ0LjAzMzlWMTIuMDE1Nkg0MC4wMzEyVjguMDEzMDJaTTE2LjAxNTYgMTYuMDE4Mkg4LjAxMDQyVjIwLjAyMDhIMTYuMDE1NlYxNi4wMTgyWk0yMC4wMTgyIDE2LjAxODJIMjQuMDIwOFYyMC4wMjA4SDIwLjAxODJWMTYuMDE4MlpNMzIuMDI2IDE2LjAxODJIMjguMDIzNFYyMC4wMjA4SDMyLjAyNlYxNi4wMTgyWk00NC4wMzM5IDE2LjAxODJWMjAuMDIwOEgzNi4wMjg2VjE2LjAxODJINDQuMDMzOVpNMTIuMDEzIDI0LjAyMzRIOC4wMTA0MlYyOC4wMjZIMTIuMDEzVjI0LjAyMzRaTTE2LjAxNTYgMjQuMDIzNEgzNi4wMjg2VjI4LjAyNkgxNi4wMTU2VjI0LjAyMzRaTTQ0LjAzMzkgMjQuMDIzNEg0MC4wMzEyVjI4LjAyNkg0NC4wMzM5VjI0LjAyMzRaIiBmaWxsPSIjNDI0MjQyIi8+CjwvZz4KPGRlZnM+CjxjbGlwUGF0aCBpZD0iY2xpcDAiPgo8cmVjdCB3aWR0aD0iNTMiIGhlaWdodD0iMzYiIGZpbGw9IndoaXRlIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg==") center center no-repeat;
|
||||
border: 4px solid #F6F6F6;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.monaco-editor.vs-dark .iPadShowKeyboard {
|
||||
background: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTMiIGhlaWdodD0iMzYiIHZpZXdCb3g9IjAgMCA1MyAzNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwKSI+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNNDguMDM2NCA0LjAxMDQySDQuMDA3NzlMNC4wMDc3OSAzMi4wMjg2SDQ4LjAzNjRWNC4wMTA0MlpNNC4wMDc3OSAwLjAwNzgxMjVDMS43OTcyMSAwLjAwNzgxMjUgMC4wMDUxODc5OSAxLjc5OTg0IDAuMDA1MTg3OTkgNC4wMTA0MlYzMi4wMjg2QzAuMDA1MTg3OTkgMzQuMjM5MiAxLjc5NzIxIDM2LjAzMTIgNC4wMDc3OSAzNi4wMzEySDQ4LjAzNjRDNTAuMjQ3IDM2LjAzMTIgNTIuMDM5IDM0LjIzOTIgNTIuMDM5IDMyLjAyODZWNC4wMTA0MkM1Mi4wMzkgMS43OTk4NCA1MC4yNDcgMC4wMDc4MTI1IDQ4LjAzNjQgMC4wMDc4MTI1SDQuMDA3NzlaTTguMDEwNDIgOC4wMTMwMkgxMi4wMTNWMTIuMDE1Nkg4LjAxMDQyVjguMDEzMDJaTTIwLjAxODIgOC4wMTMwMkgxNi4wMTU2VjEyLjAxNTZIMjAuMDE4MlY4LjAxMzAyWk0yNC4wMjA4IDguMDEzMDJIMjguMDIzNFYxMi4wMTU2SDI0LjAyMDhWOC4wMTMwMlpNMzYuMDI4NiA4LjAxMzAySDMyLjAyNlYxMi4wMTU2SDM2LjAyODZWOC4wMTMwMlpNNDAuMDMxMiA4LjAxMzAySDQ0LjAzMzlWMTIuMDE1Nkg0MC4wMzEyVjguMDEzMDJaTTE2LjAxNTYgMTYuMDE4Mkg4LjAxMDQyVjIwLjAyMDhIMTYuMDE1NlYxNi4wMTgyWk0yMC4wMTgyIDE2LjAxODJIMjQuMDIwOFYyMC4wMjA4SDIwLjAxODJWMTYuMDE4MlpNMzIuMDI2IDE2LjAxODJIMjguMDIzNFYyMC4wMjA4SDMyLjAyNlYxNi4wMTgyWk00NC4wMzM5IDE2LjAxODJWMjAuMDIwOEgzNi4wMjg2VjE2LjAxODJINDQuMDMzOVpNMTIuMDEzIDI0LjAyMzRIOC4wMTA0MlYyOC4wMjZIMTIuMDEzVjI0LjAyMzRaTTE2LjAxNTYgMjQuMDIzNEgzNi4wMjg2VjI4LjAyNkgxNi4wMTU2VjI0LjAyMzRaTTQ0LjAzMzkgMjQuMDIzNEg0MC4wMzEyVjI4LjAyNkg0NC4wMzM5VjI0LjAyMzRaIiBmaWxsPSIjQzVDNUM1Ii8+CjwvZz4KPGRlZnM+CjxjbGlwUGF0aCBpZD0iY2xpcDAiPgo8cmVjdCB3aWR0aD0iNTMiIGhlaWdodD0iMzYiIGZpbGw9IndoaXRlIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg==") center center no-repeat;
|
||||
border: 4px solid #252526;
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import './iPadShowKeyboard.css';
|
||||
import * as dom from '../../../../base/browser/dom.js';
|
||||
import { Disposable } from '../../../../base/common/lifecycle.js';
|
||||
import { registerEditorContribution } from '../../../browser/editorExtensions.js';
|
||||
import { isIOS } from '../../../../base/common/platform.js';
|
||||
export class IPadShowKeyboard extends Disposable {
|
||||
constructor(editor) {
|
||||
super();
|
||||
this.editor = editor;
|
||||
this.widget = null;
|
||||
if (isIOS) {
|
||||
this._register(editor.onDidChangeConfiguration(() => this.update()));
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
update() {
|
||||
const shouldHaveWidget = (!this.editor.getOption(83 /* EditorOption.readOnly */));
|
||||
if (!this.widget && shouldHaveWidget) {
|
||||
this.widget = new ShowKeyboardWidget(this.editor);
|
||||
}
|
||||
else if (this.widget && !shouldHaveWidget) {
|
||||
this.widget.dispose();
|
||||
this.widget = null;
|
||||
}
|
||||
}
|
||||
dispose() {
|
||||
super.dispose();
|
||||
if (this.widget) {
|
||||
this.widget.dispose();
|
||||
this.widget = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
IPadShowKeyboard.ID = 'editor.contrib.iPadShowKeyboard';
|
||||
class ShowKeyboardWidget extends Disposable {
|
||||
constructor(editor) {
|
||||
super();
|
||||
this.editor = editor;
|
||||
this._domNode = document.createElement('textarea');
|
||||
this._domNode.className = 'iPadShowKeyboard';
|
||||
this._register(dom.addDisposableListener(this._domNode, 'touchstart', (e) => {
|
||||
this.editor.focus();
|
||||
}));
|
||||
this._register(dom.addDisposableListener(this._domNode, 'focus', (e) => {
|
||||
this.editor.focus();
|
||||
}));
|
||||
this.editor.addOverlayWidget(this);
|
||||
}
|
||||
dispose() {
|
||||
this.editor.removeOverlayWidget(this);
|
||||
super.dispose();
|
||||
}
|
||||
// ----- IOverlayWidget API
|
||||
getId() {
|
||||
return ShowKeyboardWidget.ID;
|
||||
}
|
||||
getDomNode() {
|
||||
return this._domNode;
|
||||
}
|
||||
getPosition() {
|
||||
return {
|
||||
preference: 1 /* OverlayWidgetPositionPreference.BOTTOM_RIGHT_CORNER */
|
||||
};
|
||||
}
|
||||
}
|
||||
ShowKeyboardWidget.ID = 'editor.contrib.ShowKeyboardWidget';
|
||||
registerEditorContribution(IPadShowKeyboard.ID, IPadShowKeyboard);
|
||||
@@ -0,0 +1,40 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
.monaco-editor .tokens-inspect-widget {
|
||||
z-index: 50;
|
||||
user-select: text;
|
||||
-webkit-user-select: text;
|
||||
-ms-user-select: text;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.tokens-inspect-separator {
|
||||
height: 1px;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.monaco-editor .tokens-inspect-widget .tm-token {
|
||||
font-family: var(--monaco-monospace-font);
|
||||
}
|
||||
|
||||
.monaco-editor .tokens-inspect-widget .tm-token-length {
|
||||
font-weight: normal;
|
||||
font-size: 60%;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.monaco-editor .tokens-inspect-widget .tm-metadata-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.monaco-editor .tokens-inspect-widget .tm-metadata-value {
|
||||
font-family: var(--monaco-monospace-font);
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.monaco-editor .tokens-inspect-widget .tm-token-type {
|
||||
font-family: var(--monaco-monospace-font);
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
import './inspectTokens.css';
|
||||
import { $, append, reset } from '../../../../base/browser/dom.js';
|
||||
import { Color } from '../../../../base/common/color.js';
|
||||
import { Disposable } from '../../../../base/common/lifecycle.js';
|
||||
import { EditorAction, registerEditorAction, registerEditorContribution } from '../../../browser/editorExtensions.js';
|
||||
import { TokenizationRegistry } from '../../../common/languages.js';
|
||||
import { TokenMetadata } from '../../../common/encodedTokenAttributes.js';
|
||||
import { NullState, nullTokenize, nullTokenizeEncoded } from '../../../common/languages/nullTokenize.js';
|
||||
import { ILanguageService } from '../../../common/languages/language.js';
|
||||
import { IStandaloneThemeService } from '../../common/standaloneTheme.js';
|
||||
import { editorHoverBackground, editorHoverBorder, editorHoverForeground } from '../../../../platform/theme/common/colorRegistry.js';
|
||||
import { registerThemingParticipant } from '../../../../platform/theme/common/themeService.js';
|
||||
import { InspectTokensNLS } from '../../../common/standaloneStrings.js';
|
||||
import { isHighContrast } from '../../../../platform/theme/common/theme.js';
|
||||
let InspectTokensController = class InspectTokensController extends Disposable {
|
||||
constructor(editor, standaloneColorService, languageService) {
|
||||
super();
|
||||
this._editor = editor;
|
||||
this._languageService = languageService;
|
||||
this._widget = null;
|
||||
this._register(this._editor.onDidChangeModel((e) => this.stop()));
|
||||
this._register(this._editor.onDidChangeModelLanguage((e) => this.stop()));
|
||||
this._register(TokenizationRegistry.onDidChange((e) => this.stop()));
|
||||
this._register(this._editor.onKeyUp((e) => e.keyCode === 9 /* KeyCode.Escape */ && this.stop()));
|
||||
}
|
||||
static get(editor) {
|
||||
return editor.getContribution(InspectTokensController.ID);
|
||||
}
|
||||
dispose() {
|
||||
this.stop();
|
||||
super.dispose();
|
||||
}
|
||||
launch() {
|
||||
if (this._widget) {
|
||||
return;
|
||||
}
|
||||
if (!this._editor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
this._widget = new InspectTokensWidget(this._editor, this._languageService);
|
||||
}
|
||||
stop() {
|
||||
if (this._widget) {
|
||||
this._widget.dispose();
|
||||
this._widget = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
InspectTokensController.ID = 'editor.contrib.inspectTokens';
|
||||
InspectTokensController = __decorate([
|
||||
__param(1, IStandaloneThemeService),
|
||||
__param(2, ILanguageService)
|
||||
], InspectTokensController);
|
||||
class InspectTokens extends EditorAction {
|
||||
constructor() {
|
||||
super({
|
||||
id: 'editor.action.inspectTokens',
|
||||
label: InspectTokensNLS.inspectTokensAction,
|
||||
alias: 'Developer: Inspect Tokens',
|
||||
precondition: undefined
|
||||
});
|
||||
}
|
||||
run(accessor, editor) {
|
||||
const controller = InspectTokensController.get(editor);
|
||||
if (controller) {
|
||||
controller.launch();
|
||||
}
|
||||
}
|
||||
}
|
||||
function renderTokenText(tokenText) {
|
||||
let result = '';
|
||||
for (let charIndex = 0, len = tokenText.length; charIndex < len; charIndex++) {
|
||||
const charCode = tokenText.charCodeAt(charIndex);
|
||||
switch (charCode) {
|
||||
case 9 /* CharCode.Tab */:
|
||||
result += '\u2192'; // →
|
||||
break;
|
||||
case 32 /* CharCode.Space */:
|
||||
result += '\u00B7'; // ·
|
||||
break;
|
||||
default:
|
||||
result += String.fromCharCode(charCode);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function getSafeTokenizationSupport(languageIdCodec, languageId) {
|
||||
const tokenizationSupport = TokenizationRegistry.get(languageId);
|
||||
if (tokenizationSupport) {
|
||||
return tokenizationSupport;
|
||||
}
|
||||
const encodedLanguageId = languageIdCodec.encodeLanguageId(languageId);
|
||||
return {
|
||||
getInitialState: () => NullState,
|
||||
tokenize: (line, hasEOL, state) => nullTokenize(languageId, state),
|
||||
tokenizeEncoded: (line, hasEOL, state) => nullTokenizeEncoded(encodedLanguageId, state)
|
||||
};
|
||||
}
|
||||
class InspectTokensWidget extends Disposable {
|
||||
constructor(editor, languageService) {
|
||||
super();
|
||||
// Editor.IContentWidget.allowEditorOverflow
|
||||
this.allowEditorOverflow = true;
|
||||
this._editor = editor;
|
||||
this._languageService = languageService;
|
||||
this._model = this._editor.getModel();
|
||||
this._domNode = document.createElement('div');
|
||||
this._domNode.className = 'tokens-inspect-widget';
|
||||
this._tokenizationSupport = getSafeTokenizationSupport(this._languageService.languageIdCodec, this._model.getLanguageId());
|
||||
this._compute(this._editor.getPosition());
|
||||
this._register(this._editor.onDidChangeCursorPosition((e) => this._compute(this._editor.getPosition())));
|
||||
this._editor.addContentWidget(this);
|
||||
}
|
||||
dispose() {
|
||||
this._editor.removeContentWidget(this);
|
||||
super.dispose();
|
||||
}
|
||||
getId() {
|
||||
return InspectTokensWidget._ID;
|
||||
}
|
||||
_compute(position) {
|
||||
const data = this._getTokensAtLine(position.lineNumber);
|
||||
let token1Index = 0;
|
||||
for (let i = data.tokens1.length - 1; i >= 0; i--) {
|
||||
const t = data.tokens1[i];
|
||||
if (position.column - 1 >= t.offset) {
|
||||
token1Index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
let token2Index = 0;
|
||||
for (let i = (data.tokens2.length >>> 1); i >= 0; i--) {
|
||||
if (position.column - 1 >= data.tokens2[(i << 1)]) {
|
||||
token2Index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const lineContent = this._model.getLineContent(position.lineNumber);
|
||||
let tokenText = '';
|
||||
if (token1Index < data.tokens1.length) {
|
||||
const tokenStartIndex = data.tokens1[token1Index].offset;
|
||||
const tokenEndIndex = token1Index + 1 < data.tokens1.length ? data.tokens1[token1Index + 1].offset : lineContent.length;
|
||||
tokenText = lineContent.substring(tokenStartIndex, tokenEndIndex);
|
||||
}
|
||||
reset(this._domNode, $('h2.tm-token', undefined, renderTokenText(tokenText), $('span.tm-token-length', undefined, `${tokenText.length} ${tokenText.length === 1 ? 'char' : 'chars'}`)));
|
||||
append(this._domNode, $('hr.tokens-inspect-separator', { 'style': 'clear:both' }));
|
||||
const metadata = (token2Index << 1) + 1 < data.tokens2.length ? this._decodeMetadata(data.tokens2[(token2Index << 1) + 1]) : null;
|
||||
append(this._domNode, $('table.tm-metadata-table', undefined, $('tbody', undefined, $('tr', undefined, $('td.tm-metadata-key', undefined, 'language'), $('td.tm-metadata-value', undefined, `${metadata ? metadata.languageId : '-?-'}`)), $('tr', undefined, $('td.tm-metadata-key', undefined, 'token type'), $('td.tm-metadata-value', undefined, `${metadata ? this._tokenTypeToString(metadata.tokenType) : '-?-'}`)), $('tr', undefined, $('td.tm-metadata-key', undefined, 'font style'), $('td.tm-metadata-value', undefined, `${metadata ? this._fontStyleToString(metadata.fontStyle) : '-?-'}`)), $('tr', undefined, $('td.tm-metadata-key', undefined, 'foreground'), $('td.tm-metadata-value', undefined, `${metadata ? Color.Format.CSS.formatHex(metadata.foreground) : '-?-'}`)), $('tr', undefined, $('td.tm-metadata-key', undefined, 'background'), $('td.tm-metadata-value', undefined, `${metadata ? Color.Format.CSS.formatHex(metadata.background) : '-?-'}`)))));
|
||||
append(this._domNode, $('hr.tokens-inspect-separator'));
|
||||
if (token1Index < data.tokens1.length) {
|
||||
append(this._domNode, $('span.tm-token-type', undefined, data.tokens1[token1Index].type));
|
||||
}
|
||||
this._editor.layoutContentWidget(this);
|
||||
}
|
||||
_decodeMetadata(metadata) {
|
||||
const colorMap = TokenizationRegistry.getColorMap();
|
||||
const languageId = TokenMetadata.getLanguageId(metadata);
|
||||
const tokenType = TokenMetadata.getTokenType(metadata);
|
||||
const fontStyle = TokenMetadata.getFontStyle(metadata);
|
||||
const foreground = TokenMetadata.getForeground(metadata);
|
||||
const background = TokenMetadata.getBackground(metadata);
|
||||
return {
|
||||
languageId: this._languageService.languageIdCodec.decodeLanguageId(languageId),
|
||||
tokenType: tokenType,
|
||||
fontStyle: fontStyle,
|
||||
foreground: colorMap[foreground],
|
||||
background: colorMap[background]
|
||||
};
|
||||
}
|
||||
_tokenTypeToString(tokenType) {
|
||||
switch (tokenType) {
|
||||
case 0 /* StandardTokenType.Other */: return 'Other';
|
||||
case 1 /* StandardTokenType.Comment */: return 'Comment';
|
||||
case 2 /* StandardTokenType.String */: return 'String';
|
||||
case 3 /* StandardTokenType.RegEx */: return 'RegEx';
|
||||
default: return '??';
|
||||
}
|
||||
}
|
||||
_fontStyleToString(fontStyle) {
|
||||
let r = '';
|
||||
if (fontStyle & 1 /* FontStyle.Italic */) {
|
||||
r += 'italic ';
|
||||
}
|
||||
if (fontStyle & 2 /* FontStyle.Bold */) {
|
||||
r += 'bold ';
|
||||
}
|
||||
if (fontStyle & 4 /* FontStyle.Underline */) {
|
||||
r += 'underline ';
|
||||
}
|
||||
if (fontStyle & 8 /* FontStyle.Strikethrough */) {
|
||||
r += 'strikethrough ';
|
||||
}
|
||||
if (r.length === 0) {
|
||||
r = '---';
|
||||
}
|
||||
return r;
|
||||
}
|
||||
_getTokensAtLine(lineNumber) {
|
||||
const stateBeforeLine = this._getStateBeforeLine(lineNumber);
|
||||
const tokenizationResult1 = this._tokenizationSupport.tokenize(this._model.getLineContent(lineNumber), true, stateBeforeLine);
|
||||
const tokenizationResult2 = this._tokenizationSupport.tokenizeEncoded(this._model.getLineContent(lineNumber), true, stateBeforeLine);
|
||||
return {
|
||||
startState: stateBeforeLine,
|
||||
tokens1: tokenizationResult1.tokens,
|
||||
tokens2: tokenizationResult2.tokens,
|
||||
endState: tokenizationResult1.endState
|
||||
};
|
||||
}
|
||||
_getStateBeforeLine(lineNumber) {
|
||||
let state = this._tokenizationSupport.getInitialState();
|
||||
for (let i = 1; i < lineNumber; i++) {
|
||||
const tokenizationResult = this._tokenizationSupport.tokenize(this._model.getLineContent(i), true, state);
|
||||
state = tokenizationResult.endState;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
getDomNode() {
|
||||
return this._domNode;
|
||||
}
|
||||
getPosition() {
|
||||
return {
|
||||
position: this._editor.getPosition(),
|
||||
preference: [2 /* ContentWidgetPositionPreference.BELOW */, 1 /* ContentWidgetPositionPreference.ABOVE */]
|
||||
};
|
||||
}
|
||||
}
|
||||
InspectTokensWidget._ID = 'editor.contrib.inspectTokensWidget';
|
||||
registerEditorContribution(InspectTokensController.ID, InspectTokensController);
|
||||
registerEditorAction(InspectTokens);
|
||||
registerThemingParticipant((theme, collector) => {
|
||||
const border = theme.getColor(editorHoverBorder);
|
||||
if (border) {
|
||||
const borderWidth = isHighContrast(theme.type) ? 2 : 1;
|
||||
collector.addRule(`.monaco-editor .tokens-inspect-widget { border: ${borderWidth}px solid ${border}; }`);
|
||||
collector.addRule(`.monaco-editor .tokens-inspect-widget .tokens-inspect-separator { background-color: ${border}; }`);
|
||||
}
|
||||
const background = theme.getColor(editorHoverBackground);
|
||||
if (background) {
|
||||
collector.addRule(`.monaco-editor .tokens-inspect-widget { background-color: ${background}; }`);
|
||||
}
|
||||
const foreground = theme.getColor(editorHoverForeground);
|
||||
if (foreground) {
|
||||
collector.addRule(`.monaco-editor .tokens-inspect-widget { color: ${foreground}; }`);
|
||||
}
|
||||
});
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import { Registry } from '../../../../platform/registry/common/platform.js';
|
||||
import { Extensions } from '../../../../platform/quickinput/common/quickAccess.js';
|
||||
import { QuickCommandNLS } from '../../../common/standaloneStrings.js';
|
||||
import { ICodeEditorService } from '../../../browser/services/codeEditorService.js';
|
||||
import { AbstractEditorCommandsQuickAccessProvider } from '../../../contrib/quickAccess/browser/commandsQuickAccess.js';
|
||||
import { withNullAsUndefined } from '../../../../base/common/types.js';
|
||||
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
|
||||
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';
|
||||
import { ICommandService } from '../../../../platform/commands/common/commands.js';
|
||||
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js';
|
||||
import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js';
|
||||
import { EditorAction, registerEditorAction } from '../../../browser/editorExtensions.js';
|
||||
import { EditorContextKeys } from '../../../common/editorContextKeys.js';
|
||||
import { IQuickInputService } from '../../../../platform/quickinput/common/quickInput.js';
|
||||
let StandaloneCommandsQuickAccessProvider = class StandaloneCommandsQuickAccessProvider extends AbstractEditorCommandsQuickAccessProvider {
|
||||
constructor(instantiationService, codeEditorService, keybindingService, commandService, telemetryService, dialogService) {
|
||||
super({ showAlias: false }, instantiationService, keybindingService, commandService, telemetryService, dialogService);
|
||||
this.codeEditorService = codeEditorService;
|
||||
}
|
||||
get activeTextEditorControl() { return withNullAsUndefined(this.codeEditorService.getFocusedCodeEditor()); }
|
||||
getCommandPicks() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return this.getCodeEditorCommandPicks();
|
||||
});
|
||||
}
|
||||
};
|
||||
StandaloneCommandsQuickAccessProvider = __decorate([
|
||||
__param(0, IInstantiationService),
|
||||
__param(1, ICodeEditorService),
|
||||
__param(2, IKeybindingService),
|
||||
__param(3, ICommandService),
|
||||
__param(4, ITelemetryService),
|
||||
__param(5, IDialogService)
|
||||
], StandaloneCommandsQuickAccessProvider);
|
||||
export { StandaloneCommandsQuickAccessProvider };
|
||||
export class GotoLineAction extends EditorAction {
|
||||
constructor() {
|
||||
super({
|
||||
id: GotoLineAction.ID,
|
||||
label: QuickCommandNLS.quickCommandActionLabel,
|
||||
alias: 'Command Palette',
|
||||
precondition: undefined,
|
||||
kbOpts: {
|
||||
kbExpr: EditorContextKeys.focus,
|
||||
primary: 59 /* KeyCode.F1 */,
|
||||
weight: 100 /* KeybindingWeight.EditorContrib */
|
||||
},
|
||||
contextMenuOpts: {
|
||||
group: 'z_commands',
|
||||
order: 1
|
||||
}
|
||||
});
|
||||
}
|
||||
run(accessor) {
|
||||
accessor.get(IQuickInputService).quickAccess.show(StandaloneCommandsQuickAccessProvider.PREFIX);
|
||||
}
|
||||
}
|
||||
GotoLineAction.ID = 'editor.action.quickCommand';
|
||||
registerEditorAction(GotoLineAction);
|
||||
Registry.as(Extensions.Quickaccess).registerQuickAccessProvider({
|
||||
ctor: StandaloneCommandsQuickAccessProvider,
|
||||
prefix: StandaloneCommandsQuickAccessProvider.PREFIX,
|
||||
helpEntries: [{ description: QuickCommandNLS.quickCommandHelp, commandId: GotoLineAction.ID }]
|
||||
});
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
import { AbstractGotoLineQuickAccessProvider } from '../../../contrib/quickAccess/browser/gotoLineQuickAccess.js';
|
||||
import { Registry } from '../../../../platform/registry/common/platform.js';
|
||||
import { Extensions } from '../../../../platform/quickinput/common/quickAccess.js';
|
||||
import { ICodeEditorService } from '../../../browser/services/codeEditorService.js';
|
||||
import { withNullAsUndefined } from '../../../../base/common/types.js';
|
||||
import { GoToLineNLS } from '../../../common/standaloneStrings.js';
|
||||
import { Event } from '../../../../base/common/event.js';
|
||||
import { EditorAction, registerEditorAction } from '../../../browser/editorExtensions.js';
|
||||
import { EditorContextKeys } from '../../../common/editorContextKeys.js';
|
||||
import { IQuickInputService } from '../../../../platform/quickinput/common/quickInput.js';
|
||||
let StandaloneGotoLineQuickAccessProvider = class StandaloneGotoLineQuickAccessProvider extends AbstractGotoLineQuickAccessProvider {
|
||||
constructor(editorService) {
|
||||
super();
|
||||
this.editorService = editorService;
|
||||
this.onDidActiveTextEditorControlChange = Event.None;
|
||||
}
|
||||
get activeTextEditorControl() {
|
||||
return withNullAsUndefined(this.editorService.getFocusedCodeEditor());
|
||||
}
|
||||
};
|
||||
StandaloneGotoLineQuickAccessProvider = __decorate([
|
||||
__param(0, ICodeEditorService)
|
||||
], StandaloneGotoLineQuickAccessProvider);
|
||||
export { StandaloneGotoLineQuickAccessProvider };
|
||||
export class GotoLineAction extends EditorAction {
|
||||
constructor() {
|
||||
super({
|
||||
id: GotoLineAction.ID,
|
||||
label: GoToLineNLS.gotoLineActionLabel,
|
||||
alias: 'Go to Line/Column...',
|
||||
precondition: undefined,
|
||||
kbOpts: {
|
||||
kbExpr: EditorContextKeys.focus,
|
||||
primary: 2048 /* KeyMod.CtrlCmd */ | 37 /* KeyCode.KeyG */,
|
||||
mac: { primary: 256 /* KeyMod.WinCtrl */ | 37 /* KeyCode.KeyG */ },
|
||||
weight: 100 /* KeybindingWeight.EditorContrib */
|
||||
}
|
||||
});
|
||||
}
|
||||
run(accessor) {
|
||||
accessor.get(IQuickInputService).quickAccess.show(StandaloneGotoLineQuickAccessProvider.PREFIX);
|
||||
}
|
||||
}
|
||||
GotoLineAction.ID = 'editor.action.gotoLine';
|
||||
registerEditorAction(GotoLineAction);
|
||||
Registry.as(Extensions.Quickaccess).registerQuickAccessProvider({
|
||||
ctor: StandaloneGotoLineQuickAccessProvider,
|
||||
prefix: StandaloneGotoLineQuickAccessProvider.PREFIX,
|
||||
helpEntries: [{ description: GoToLineNLS.gotoLineActionLabel, commandId: GotoLineAction.ID }]
|
||||
});
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
import '../../../../base/browser/ui/codicons/codiconStyles.js'; // The codicon symbol styles are defined here and must be loaded
|
||||
import '../../../contrib/symbolIcons/browser/symbolIcons.js'; // The codicon symbol colors are defined here and must be loaded to get colors
|
||||
import { AbstractGotoSymbolQuickAccessProvider } from '../../../contrib/quickAccess/browser/gotoSymbolQuickAccess.js';
|
||||
import { Registry } from '../../../../platform/registry/common/platform.js';
|
||||
import { Extensions } from '../../../../platform/quickinput/common/quickAccess.js';
|
||||
import { ICodeEditorService } from '../../../browser/services/codeEditorService.js';
|
||||
import { withNullAsUndefined } from '../../../../base/common/types.js';
|
||||
import { QuickOutlineNLS } from '../../../common/standaloneStrings.js';
|
||||
import { Event } from '../../../../base/common/event.js';
|
||||
import { EditorAction, registerEditorAction } from '../../../browser/editorExtensions.js';
|
||||
import { EditorContextKeys } from '../../../common/editorContextKeys.js';
|
||||
import { IQuickInputService } from '../../../../platform/quickinput/common/quickInput.js';
|
||||
import { IOutlineModelService } from '../../../contrib/documentSymbols/browser/outlineModel.js';
|
||||
import { ILanguageFeaturesService } from '../../../common/services/languageFeatures.js';
|
||||
let StandaloneGotoSymbolQuickAccessProvider = class StandaloneGotoSymbolQuickAccessProvider extends AbstractGotoSymbolQuickAccessProvider {
|
||||
constructor(editorService, languageFeaturesService, outlineModelService) {
|
||||
super(languageFeaturesService, outlineModelService);
|
||||
this.editorService = editorService;
|
||||
this.onDidActiveTextEditorControlChange = Event.None;
|
||||
}
|
||||
get activeTextEditorControl() {
|
||||
return withNullAsUndefined(this.editorService.getFocusedCodeEditor());
|
||||
}
|
||||
};
|
||||
StandaloneGotoSymbolQuickAccessProvider = __decorate([
|
||||
__param(0, ICodeEditorService),
|
||||
__param(1, ILanguageFeaturesService),
|
||||
__param(2, IOutlineModelService)
|
||||
], StandaloneGotoSymbolQuickAccessProvider);
|
||||
export { StandaloneGotoSymbolQuickAccessProvider };
|
||||
export class GotoSymbolAction extends EditorAction {
|
||||
constructor() {
|
||||
super({
|
||||
id: GotoSymbolAction.ID,
|
||||
label: QuickOutlineNLS.quickOutlineActionLabel,
|
||||
alias: 'Go to Symbol...',
|
||||
precondition: EditorContextKeys.hasDocumentSymbolProvider,
|
||||
kbOpts: {
|
||||
kbExpr: EditorContextKeys.focus,
|
||||
primary: 2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 45 /* KeyCode.KeyO */,
|
||||
weight: 100 /* KeybindingWeight.EditorContrib */
|
||||
},
|
||||
contextMenuOpts: {
|
||||
group: 'navigation',
|
||||
order: 3
|
||||
}
|
||||
});
|
||||
}
|
||||
run(accessor) {
|
||||
accessor.get(IQuickInputService).quickAccess.show(AbstractGotoSymbolQuickAccessProvider.PREFIX);
|
||||
}
|
||||
}
|
||||
GotoSymbolAction.ID = 'editor.action.quickOutline';
|
||||
registerEditorAction(GotoSymbolAction);
|
||||
Registry.as(Extensions.Quickaccess).registerQuickAccessProvider({
|
||||
ctor: StandaloneGotoSymbolQuickAccessProvider,
|
||||
prefix: AbstractGotoSymbolQuickAccessProvider.PREFIX,
|
||||
helpEntries: [
|
||||
{ description: QuickOutlineNLS.quickOutlineActionLabel, prefix: AbstractGotoSymbolQuickAccessProvider.PREFIX, commandId: GotoSymbolAction.ID },
|
||||
{ description: QuickOutlineNLS.quickOutlineByCategoryActionLabel, prefix: AbstractGotoSymbolQuickAccessProvider.PREFIX_BY_CATEGORY }
|
||||
]
|
||||
});
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { Registry } from '../../../../platform/registry/common/platform.js';
|
||||
import { Extensions } from '../../../../platform/quickinput/common/quickAccess.js';
|
||||
import { QuickHelpNLS } from '../../../common/standaloneStrings.js';
|
||||
import { HelpQuickAccessProvider } from '../../../../platform/quickinput/browser/helpQuickAccess.js';
|
||||
Registry.as(Extensions.Quickaccess).registerQuickAccessProvider({
|
||||
ctor: HelpQuickAccessProvider,
|
||||
prefix: '',
|
||||
helpEntries: [{ description: QuickHelpNLS.helpQuickAccessActionLabel }]
|
||||
});
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
.quick-input-widget {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.quick-input-widget .monaco-highlighted-label .highlight,
|
||||
.quick-input-widget .monaco-highlighted-label .highlight {
|
||||
color: #0066BF;
|
||||
}
|
||||
|
||||
.vs .quick-input-widget .monaco-list-row.focused .monaco-highlighted-label .highlight,
|
||||
.vs .quick-input-widget .monaco-list-row.focused .monaco-highlighted-label .highlight {
|
||||
color: #9DDDFF;
|
||||
}
|
||||
|
||||
.vs-dark .quick-input-widget .monaco-highlighted-label .highlight,
|
||||
.vs-dark .quick-input-widget .monaco-highlighted-label .highlight {
|
||||
color: #0097fb;
|
||||
}
|
||||
|
||||
.hc-black .quick-input-widget .monaco-highlighted-label .highlight,
|
||||
.hc-black .quick-input-widget .monaco-highlighted-label .highlight {
|
||||
color: #F38518;
|
||||
}
|
||||
|
||||
.hc-light .quick-input-widget .monaco-highlighted-label .highlight,
|
||||
.hc-light .quick-input-widget .monaco-highlighted-label .highlight {
|
||||
color: #0F4A85;
|
||||
}
|
||||
|
||||
.monaco-keybinding > .monaco-keybinding-key {
|
||||
background-color: rgba(221, 221, 221, 0.4);
|
||||
border: solid 1px rgba(204, 204, 204, 0.4);
|
||||
border-bottom-color: rgba(187, 187, 187, 0.4);
|
||||
box-shadow: inset 0 -1px 0 rgba(187, 187, 187, 0.4);
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.hc-black .monaco-keybinding > .monaco-keybinding-key {
|
||||
background-color: transparent;
|
||||
border: solid 1px rgb(111, 195, 223);
|
||||
box-shadow: none;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.hc-light .monaco-keybinding > .monaco-keybinding-key {
|
||||
background-color: transparent;
|
||||
border: solid 1px #0F4A85;
|
||||
box-shadow: none;
|
||||
color: #292929;
|
||||
}
|
||||
|
||||
.vs-dark .monaco-keybinding > .monaco-keybinding-key {
|
||||
background-color: rgba(128, 128, 128, 0.17);
|
||||
border: solid 1px rgba(51, 51, 51, 0.6);
|
||||
border-bottom-color: rgba(68, 68, 68, 0.6);
|
||||
box-shadow: inset 0 -1px 0 rgba(68, 68, 68, 0.6);
|
||||
color: #ccc;
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
import './standaloneQuickInput.css';
|
||||
import { registerEditorContribution } from '../../../browser/editorExtensions.js';
|
||||
import { IThemeService } from '../../../../platform/theme/common/themeService.js';
|
||||
import { CancellationToken } from '../../../../base/common/cancellation.js';
|
||||
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
|
||||
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
|
||||
import { IAccessibilityService } from '../../../../platform/accessibility/common/accessibility.js';
|
||||
import { EditorScopedLayoutService } from '../standaloneLayoutService.js';
|
||||
import { ICodeEditorService } from '../../../browser/services/codeEditorService.js';
|
||||
import { QuickInputService } from '../../../../platform/quickinput/browser/quickInput.js';
|
||||
import { once } from '../../../../base/common/functional.js';
|
||||
let EditorScopedQuickInputService = class EditorScopedQuickInputService extends QuickInputService {
|
||||
constructor(editor, instantiationService, contextKeyService, themeService, accessibilityService, codeEditorService) {
|
||||
super(instantiationService, contextKeyService, themeService, accessibilityService, new EditorScopedLayoutService(editor.getContainerDomNode(), codeEditorService));
|
||||
this.host = undefined;
|
||||
// Use the passed in code editor as host for the quick input widget
|
||||
const contribution = QuickInputEditorContribution.get(editor);
|
||||
if (contribution) {
|
||||
const widget = contribution.widget;
|
||||
this.host = {
|
||||
_serviceBrand: undefined,
|
||||
get hasContainer() { return true; },
|
||||
get container() { return widget.getDomNode(); },
|
||||
get dimension() { return editor.getLayoutInfo(); },
|
||||
get onDidLayout() { return editor.onDidLayoutChange; },
|
||||
focus: () => editor.focus(),
|
||||
offset: { top: 0, quickPickTop: 0 }
|
||||
};
|
||||
}
|
||||
else {
|
||||
this.host = undefined;
|
||||
}
|
||||
}
|
||||
createController() {
|
||||
return super.createController(this.host);
|
||||
}
|
||||
};
|
||||
EditorScopedQuickInputService = __decorate([
|
||||
__param(1, IInstantiationService),
|
||||
__param(2, IContextKeyService),
|
||||
__param(3, IThemeService),
|
||||
__param(4, IAccessibilityService),
|
||||
__param(5, ICodeEditorService)
|
||||
], EditorScopedQuickInputService);
|
||||
export { EditorScopedQuickInputService };
|
||||
let StandaloneQuickInputService = class StandaloneQuickInputService {
|
||||
constructor(instantiationService, codeEditorService) {
|
||||
this.instantiationService = instantiationService;
|
||||
this.codeEditorService = codeEditorService;
|
||||
this.mapEditorToService = new Map();
|
||||
}
|
||||
get activeService() {
|
||||
const editor = this.codeEditorService.getFocusedCodeEditor();
|
||||
if (!editor) {
|
||||
throw new Error('Quick input service needs a focused editor to work.');
|
||||
}
|
||||
// Find the quick input implementation for the focused
|
||||
// editor or create it lazily if not yet created
|
||||
let quickInputService = this.mapEditorToService.get(editor);
|
||||
if (!quickInputService) {
|
||||
const newQuickInputService = quickInputService = this.instantiationService.createInstance(EditorScopedQuickInputService, editor);
|
||||
this.mapEditorToService.set(editor, quickInputService);
|
||||
once(editor.onDidDispose)(() => {
|
||||
newQuickInputService.dispose();
|
||||
this.mapEditorToService.delete(editor);
|
||||
});
|
||||
}
|
||||
return quickInputService;
|
||||
}
|
||||
get quickAccess() { return this.activeService.quickAccess; }
|
||||
pick(picks, options = {}, token = CancellationToken.None) {
|
||||
return this.activeService /* TS fail */.pick(picks, options, token);
|
||||
}
|
||||
createQuickPick() {
|
||||
return this.activeService.createQuickPick();
|
||||
}
|
||||
};
|
||||
StandaloneQuickInputService = __decorate([
|
||||
__param(0, IInstantiationService),
|
||||
__param(1, ICodeEditorService)
|
||||
], StandaloneQuickInputService);
|
||||
export { StandaloneQuickInputService };
|
||||
export class QuickInputEditorContribution {
|
||||
constructor(editor) {
|
||||
this.editor = editor;
|
||||
this.widget = new QuickInputEditorWidget(this.editor);
|
||||
}
|
||||
static get(editor) {
|
||||
return editor.getContribution(QuickInputEditorContribution.ID);
|
||||
}
|
||||
dispose() {
|
||||
this.widget.dispose();
|
||||
}
|
||||
}
|
||||
QuickInputEditorContribution.ID = 'editor.controller.quickInput';
|
||||
export class QuickInputEditorWidget {
|
||||
constructor(codeEditor) {
|
||||
this.codeEditor = codeEditor;
|
||||
this.domNode = document.createElement('div');
|
||||
this.codeEditor.addOverlayWidget(this);
|
||||
}
|
||||
getId() {
|
||||
return QuickInputEditorWidget.ID;
|
||||
}
|
||||
getDomNode() {
|
||||
return this.domNode;
|
||||
}
|
||||
getPosition() {
|
||||
return { preference: 2 /* OverlayWidgetPositionPreference.TOP_CENTER */ };
|
||||
}
|
||||
dispose() {
|
||||
this.codeEditor.removeOverlayWidget(this);
|
||||
}
|
||||
}
|
||||
QuickInputEditorWidget.ID = 'editor.contrib.quickInputWidget';
|
||||
registerEditorContribution(QuickInputEditorContribution.ID, QuickInputEditorContribution);
|
||||
+36
@@ -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.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
import { registerEditorContribution } from '../../../browser/editorExtensions.js';
|
||||
import { ICodeEditorService } from '../../../browser/services/codeEditorService.js';
|
||||
import { ReferencesController } from '../../../contrib/gotoSymbol/browser/peek/referencesController.js';
|
||||
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
|
||||
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
|
||||
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
|
||||
import { INotificationService } from '../../../../platform/notification/common/notification.js';
|
||||
import { IStorageService } from '../../../../platform/storage/common/storage.js';
|
||||
let StandaloneReferencesController = class StandaloneReferencesController extends ReferencesController {
|
||||
constructor(editor, contextKeyService, editorService, notificationService, instantiationService, storageService, configurationService) {
|
||||
super(true, editor, contextKeyService, editorService, notificationService, instantiationService, storageService, configurationService);
|
||||
}
|
||||
};
|
||||
StandaloneReferencesController = __decorate([
|
||||
__param(1, IContextKeyService),
|
||||
__param(2, ICodeEditorService),
|
||||
__param(3, INotificationService),
|
||||
__param(4, IInstantiationService),
|
||||
__param(5, IStorageService),
|
||||
__param(6, IConfigurationService)
|
||||
], StandaloneReferencesController);
|
||||
export { StandaloneReferencesController };
|
||||
registerEditorContribution(ReferencesController.ID, StandaloneReferencesController);
|
||||
@@ -0,0 +1,251 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Default standalone editor fonts */
|
||||
.monaco-editor {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "HelveticaNeue-Light", system-ui, "Ubuntu", "Droid Sans", sans-serif;
|
||||
--monaco-monospace-font: "SF Mono", Monaco, Menlo, Consolas, "Ubuntu Mono", "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace;
|
||||
}
|
||||
|
||||
.monaco-menu .monaco-action-bar.vertical .action-item .action-menu-item:focus .action-label {
|
||||
stroke-width: 1.2px;
|
||||
}
|
||||
|
||||
.monaco-editor.vs-dark .monaco-menu .monaco-action-bar.vertical .action-menu-item:focus .action-label,
|
||||
.monaco-editor.hc-black .monaco-menu .monaco-action-bar.vertical .action-menu-item:focus .action-label,
|
||||
.monaco-editor.hc-light .monaco-menu .monaco-action-bar.vertical .action-menu-item:focus .action-label {
|
||||
stroke-width: 1.2px;
|
||||
}
|
||||
|
||||
.monaco-hover p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* See https://github.com/microsoft/monaco-editor/issues/2168#issuecomment-780078600 */
|
||||
.monaco-aria-container {
|
||||
position: absolute !important;
|
||||
top: 0; /* avoid being placed underneath a sibling element */
|
||||
height: 1px;
|
||||
width: 1px;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
clip: rect(1px, 1px, 1px, 1px);
|
||||
clip-path: inset(50%);
|
||||
}
|
||||
|
||||
/* The hc-black theme is already high contrast optimized */
|
||||
.monaco-editor.hc-black,
|
||||
.monaco-editor.hc-light {
|
||||
-ms-high-contrast-adjust: none;
|
||||
}
|
||||
/* In case the browser goes into high contrast mode and the editor is not configured with the hc-black theme */
|
||||
@media screen and (-ms-high-contrast:active) {
|
||||
|
||||
/* current line highlight */
|
||||
.monaco-editor.vs .view-overlays .current-line,
|
||||
.monaco-editor.vs-dark .view-overlays .current-line {
|
||||
border-color: windowtext !important;
|
||||
border-left: 0;
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
/* view cursors */
|
||||
.monaco-editor.vs .cursor,
|
||||
.monaco-editor.vs-dark .cursor {
|
||||
background-color: windowtext !important;
|
||||
}
|
||||
/* dnd target */
|
||||
.monaco-editor.vs .dnd-target,
|
||||
.monaco-editor.vs-dark .dnd-target {
|
||||
border-color: windowtext !important;
|
||||
}
|
||||
|
||||
/* selected text background */
|
||||
.monaco-editor.vs .selected-text,
|
||||
.monaco-editor.vs-dark .selected-text {
|
||||
background-color: highlight !important;
|
||||
}
|
||||
|
||||
/* allow the text to have a transparent background. */
|
||||
.monaco-editor.vs .view-line,
|
||||
.monaco-editor.vs-dark .view-line {
|
||||
-ms-high-contrast-adjust: none;
|
||||
}
|
||||
|
||||
/* text color */
|
||||
.monaco-editor.vs .view-line span,
|
||||
.monaco-editor.vs-dark .view-line span {
|
||||
color: windowtext !important;
|
||||
}
|
||||
/* selected text color */
|
||||
.monaco-editor.vs .view-line span.inline-selected-text,
|
||||
.monaco-editor.vs-dark .view-line span.inline-selected-text {
|
||||
color: highlighttext !important;
|
||||
}
|
||||
|
||||
/* allow decorations */
|
||||
.monaco-editor.vs .view-overlays,
|
||||
.monaco-editor.vs-dark .view-overlays {
|
||||
-ms-high-contrast-adjust: none;
|
||||
}
|
||||
|
||||
/* various decorations */
|
||||
.monaco-editor.vs .selectionHighlight,
|
||||
.monaco-editor.vs-dark .selectionHighlight,
|
||||
.monaco-editor.vs .wordHighlight,
|
||||
.monaco-editor.vs-dark .wordHighlight,
|
||||
.monaco-editor.vs .wordHighlightStrong,
|
||||
.monaco-editor.vs-dark .wordHighlightStrong,
|
||||
.monaco-editor.vs .reference-decoration,
|
||||
.monaco-editor.vs-dark .reference-decoration {
|
||||
border: 2px dotted highlight !important;
|
||||
background: transparent !important;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.monaco-editor.vs .rangeHighlight,
|
||||
.monaco-editor.vs-dark .rangeHighlight {
|
||||
background: transparent !important;
|
||||
border: 1px dotted activeborder !important;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.monaco-editor.vs .bracket-match,
|
||||
.monaco-editor.vs-dark .bracket-match {
|
||||
border-color: windowtext !important;
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
/* find widget */
|
||||
.monaco-editor.vs .findMatch,
|
||||
.monaco-editor.vs-dark .findMatch,
|
||||
.monaco-editor.vs .currentFindMatch,
|
||||
.monaco-editor.vs-dark .currentFindMatch {
|
||||
border: 2px dotted activeborder !important;
|
||||
background: transparent !important;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.monaco-editor.vs .find-widget,
|
||||
.monaco-editor.vs-dark .find-widget {
|
||||
border: 1px solid windowtext;
|
||||
}
|
||||
|
||||
/* list - used by suggest widget */
|
||||
.monaco-editor.vs .monaco-list .monaco-list-row,
|
||||
.monaco-editor.vs-dark .monaco-list .monaco-list-row {
|
||||
-ms-high-contrast-adjust: none;
|
||||
color: windowtext !important;
|
||||
}
|
||||
.monaco-editor.vs .monaco-list .monaco-list-row.focused,
|
||||
.monaco-editor.vs-dark .monaco-list .monaco-list-row.focused {
|
||||
color: highlighttext !important;
|
||||
background-color: highlight !important;
|
||||
}
|
||||
.monaco-editor.vs .monaco-list .monaco-list-row:hover,
|
||||
.monaco-editor.vs-dark .monaco-list .monaco-list-row:hover {
|
||||
background: transparent !important;
|
||||
border: 1px solid highlight;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* scrollbars */
|
||||
.monaco-editor.vs .monaco-scrollable-element > .scrollbar,
|
||||
.monaco-editor.vs-dark .monaco-scrollable-element > .scrollbar {
|
||||
-ms-high-contrast-adjust: none;
|
||||
background: background !important;
|
||||
border: 1px solid windowtext;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.monaco-editor.vs .monaco-scrollable-element > .scrollbar > .slider,
|
||||
.monaco-editor.vs-dark .monaco-scrollable-element > .scrollbar > .slider {
|
||||
background: windowtext !important;
|
||||
}
|
||||
.monaco-editor.vs .monaco-scrollable-element > .scrollbar > .slider:hover,
|
||||
.monaco-editor.vs-dark .monaco-scrollable-element > .scrollbar > .slider:hover {
|
||||
background: highlight !important;
|
||||
}
|
||||
.monaco-editor.vs .monaco-scrollable-element > .scrollbar > .slider.active,
|
||||
.monaco-editor.vs-dark .monaco-scrollable-element > .scrollbar > .slider.active {
|
||||
background: highlight !important;
|
||||
}
|
||||
|
||||
/* overview ruler */
|
||||
.monaco-editor.vs .decorationsOverviewRuler,
|
||||
.monaco-editor.vs-dark .decorationsOverviewRuler {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
/* minimap */
|
||||
.monaco-editor.vs .minimap,
|
||||
.monaco-editor.vs-dark .minimap {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* squiggles */
|
||||
.monaco-editor.vs .squiggly-d-error,
|
||||
.monaco-editor.vs-dark .squiggly-d-error {
|
||||
background: transparent !important;
|
||||
border-bottom: 4px double #E47777;
|
||||
}
|
||||
.monaco-editor.vs .squiggly-c-warning,
|
||||
.monaco-editor.vs-dark .squiggly-c-warning {
|
||||
border-bottom: 4px double #71B771;
|
||||
}
|
||||
.monaco-editor.vs .squiggly-b-info,
|
||||
.monaco-editor.vs-dark .squiggly-b-info {
|
||||
border-bottom: 4px double #71B771;
|
||||
}
|
||||
.monaco-editor.vs .squiggly-a-hint,
|
||||
.monaco-editor.vs-dark .squiggly-a-hint {
|
||||
border-bottom: 4px double #6c6c6c;
|
||||
}
|
||||
|
||||
/* contextmenu */
|
||||
.monaco-editor.vs .monaco-menu .monaco-action-bar.vertical .action-menu-item:focus .action-label,
|
||||
.monaco-editor.vs-dark .monaco-menu .monaco-action-bar.vertical .action-menu-item:focus .action-label {
|
||||
-ms-high-contrast-adjust: none;
|
||||
color: highlighttext !important;
|
||||
background-color: highlight !important;
|
||||
}
|
||||
.monaco-editor.vs .monaco-menu .monaco-action-bar.vertical .action-menu-item:hover .action-label,
|
||||
.monaco-editor.vs-dark .monaco-menu .monaco-action-bar.vertical .action-menu-item:hover .action-label {
|
||||
-ms-high-contrast-adjust: none;
|
||||
background: transparent !important;
|
||||
border: 1px solid highlight;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* diff editor */
|
||||
.monaco-diff-editor.vs .diffOverviewRuler,
|
||||
.monaco-diff-editor.vs-dark .diffOverviewRuler {
|
||||
display: none;
|
||||
}
|
||||
.monaco-editor.vs .line-insert,
|
||||
.monaco-editor.vs-dark .line-insert,
|
||||
.monaco-editor.vs .line-delete,
|
||||
.monaco-editor.vs-dark .line-delete {
|
||||
background: transparent !important;
|
||||
border: 1px solid highlight !important;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.monaco-editor.vs .char-insert,
|
||||
.monaco-editor.vs-dark .char-insert,
|
||||
.monaco-editor.vs .char-delete,
|
||||
.monaco-editor.vs-dark .char-delete {
|
||||
background: transparent !important;
|
||||
}
|
||||
}
|
||||
|
||||
/*.monaco-editor.vs [tabindex="0"]:focus {
|
||||
outline: 1px solid rgba(0, 122, 204, 0.4);
|
||||
outline-offset: -1px;
|
||||
opacity: 1 !important;
|
||||
}
|
||||
|
||||
.monaco-editor.vs-dark [tabindex="0"]:focus {
|
||||
outline: 1px solid rgba(14, 99, 156, 0.6);
|
||||
outline-offset: -1px;
|
||||
opacity: 1 !important;
|
||||
}*/
|
||||
@@ -0,0 +1,323 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
import * as aria from '../../../base/browser/ui/aria/aria.js';
|
||||
import { Disposable, toDisposable, DisposableStore } from '../../../base/common/lifecycle.js';
|
||||
import { ICodeEditorService } from '../../browser/services/codeEditorService.js';
|
||||
import { CodeEditorWidget } from '../../browser/widget/codeEditorWidget.js';
|
||||
import { DiffEditorWidget } from '../../browser/widget/diffEditorWidget.js';
|
||||
import { InternalEditorAction } from '../../common/editorAction.js';
|
||||
import { IEditorWorkerService } from '../../common/services/editorWorker.js';
|
||||
import { StandaloneKeybindingService, updateConfigurationService } from './standaloneServices.js';
|
||||
import { IStandaloneThemeService } from '../common/standaloneTheme.js';
|
||||
import { MenuId, MenuRegistry } from '../../../platform/actions/common/actions.js';
|
||||
import { CommandsRegistry, ICommandService } from '../../../platform/commands/common/commands.js';
|
||||
import { IConfigurationService } from '../../../platform/configuration/common/configuration.js';
|
||||
import { ContextKeyExpr, IContextKeyService } from '../../../platform/contextkey/common/contextkey.js';
|
||||
import { IContextMenuService } from '../../../platform/contextview/browser/contextView.js';
|
||||
import { IInstantiationService } from '../../../platform/instantiation/common/instantiation.js';
|
||||
import { IKeybindingService } from '../../../platform/keybinding/common/keybinding.js';
|
||||
import { INotificationService } from '../../../platform/notification/common/notification.js';
|
||||
import { IThemeService } from '../../../platform/theme/common/themeService.js';
|
||||
import { IAccessibilityService } from '../../../platform/accessibility/common/accessibility.js';
|
||||
import { StandaloneCodeEditorNLS } from '../../common/standaloneStrings.js';
|
||||
import { IClipboardService } from '../../../platform/clipboard/common/clipboardService.js';
|
||||
import { IEditorProgressService } from '../../../platform/progress/common/progress.js';
|
||||
import { IModelService } from '../../common/services/model.js';
|
||||
import { ILanguageService } from '../../common/languages/language.js';
|
||||
import { StandaloneCodeEditorService } from './standaloneCodeEditorService.js';
|
||||
import { PLAINTEXT_LANGUAGE_ID } from '../../common/languages/modesRegistry.js';
|
||||
import { ILanguageConfigurationService } from '../../common/languages/languageConfigurationRegistry.js';
|
||||
import { ILanguageFeaturesService } from '../../common/services/languageFeatures.js';
|
||||
let LAST_GENERATED_COMMAND_ID = 0;
|
||||
let ariaDomNodeCreated = false;
|
||||
/**
|
||||
* Create ARIA dom node inside parent,
|
||||
* or only for the first editor instantiation inside document.body.
|
||||
* @param parent container element for ARIA dom node
|
||||
*/
|
||||
function createAriaDomNode(parent) {
|
||||
if (!parent) {
|
||||
if (ariaDomNodeCreated) {
|
||||
return;
|
||||
}
|
||||
ariaDomNodeCreated = true;
|
||||
}
|
||||
aria.setARIAContainer(parent || document.body);
|
||||
}
|
||||
/**
|
||||
* A code editor to be used both by the standalone editor and the standalone diff editor.
|
||||
*/
|
||||
let StandaloneCodeEditor = class StandaloneCodeEditor extends CodeEditorWidget {
|
||||
constructor(domElement, _options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService, themeService, notificationService, accessibilityService, languageConfigurationService, languageFeaturesService) {
|
||||
const options = Object.assign({}, _options);
|
||||
options.ariaLabel = options.ariaLabel || StandaloneCodeEditorNLS.editorViewAccessibleLabel;
|
||||
options.ariaLabel = options.ariaLabel + ';' + (StandaloneCodeEditorNLS.accessibilityHelpMessage);
|
||||
super(domElement, options, {}, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService, accessibilityService, languageConfigurationService, languageFeaturesService);
|
||||
if (keybindingService instanceof StandaloneKeybindingService) {
|
||||
this._standaloneKeybindingService = keybindingService;
|
||||
}
|
||||
else {
|
||||
this._standaloneKeybindingService = null;
|
||||
}
|
||||
createAriaDomNode(options.ariaContainerElement);
|
||||
}
|
||||
addCommand(keybinding, handler, context) {
|
||||
if (!this._standaloneKeybindingService) {
|
||||
console.warn('Cannot add command because the editor is configured with an unrecognized KeybindingService');
|
||||
return null;
|
||||
}
|
||||
const commandId = 'DYNAMIC_' + (++LAST_GENERATED_COMMAND_ID);
|
||||
const whenExpression = ContextKeyExpr.deserialize(context);
|
||||
this._standaloneKeybindingService.addDynamicKeybinding(commandId, keybinding, handler, whenExpression);
|
||||
return commandId;
|
||||
}
|
||||
createContextKey(key, defaultValue) {
|
||||
return this._contextKeyService.createKey(key, defaultValue);
|
||||
}
|
||||
addAction(_descriptor) {
|
||||
if ((typeof _descriptor.id !== 'string') || (typeof _descriptor.label !== 'string') || (typeof _descriptor.run !== 'function')) {
|
||||
throw new Error('Invalid action descriptor, `id`, `label` and `run` are required properties!');
|
||||
}
|
||||
if (!this._standaloneKeybindingService) {
|
||||
console.warn('Cannot add keybinding because the editor is configured with an unrecognized KeybindingService');
|
||||
return Disposable.None;
|
||||
}
|
||||
// Read descriptor options
|
||||
const id = _descriptor.id;
|
||||
const label = _descriptor.label;
|
||||
const precondition = ContextKeyExpr.and(ContextKeyExpr.equals('editorId', this.getId()), ContextKeyExpr.deserialize(_descriptor.precondition));
|
||||
const keybindings = _descriptor.keybindings;
|
||||
const keybindingsWhen = ContextKeyExpr.and(precondition, ContextKeyExpr.deserialize(_descriptor.keybindingContext));
|
||||
const contextMenuGroupId = _descriptor.contextMenuGroupId || null;
|
||||
const contextMenuOrder = _descriptor.contextMenuOrder || 0;
|
||||
const run = (accessor, ...args) => {
|
||||
return Promise.resolve(_descriptor.run(this, ...args));
|
||||
};
|
||||
const toDispose = new DisposableStore();
|
||||
// Generate a unique id to allow the same descriptor.id across multiple editor instances
|
||||
const uniqueId = this.getId() + ':' + id;
|
||||
// Register the command
|
||||
toDispose.add(CommandsRegistry.registerCommand(uniqueId, run));
|
||||
// Register the context menu item
|
||||
if (contextMenuGroupId) {
|
||||
const menuItem = {
|
||||
command: {
|
||||
id: uniqueId,
|
||||
title: label
|
||||
},
|
||||
when: precondition,
|
||||
group: contextMenuGroupId,
|
||||
order: contextMenuOrder
|
||||
};
|
||||
toDispose.add(MenuRegistry.appendMenuItem(MenuId.EditorContext, menuItem));
|
||||
}
|
||||
// Register the keybindings
|
||||
if (Array.isArray(keybindings)) {
|
||||
for (const kb of keybindings) {
|
||||
toDispose.add(this._standaloneKeybindingService.addDynamicKeybinding(uniqueId, kb, run, keybindingsWhen));
|
||||
}
|
||||
}
|
||||
// Finally, register an internal editor action
|
||||
const internalAction = new InternalEditorAction(uniqueId, label, label, precondition, run, this._contextKeyService);
|
||||
// Store it under the original id, such that trigger with the original id will work
|
||||
this._actions[id] = internalAction;
|
||||
toDispose.add(toDisposable(() => {
|
||||
delete this._actions[id];
|
||||
}));
|
||||
return toDispose;
|
||||
}
|
||||
_triggerCommand(handlerId, payload) {
|
||||
if (this._codeEditorService instanceof StandaloneCodeEditorService) {
|
||||
// Help commands find this editor as the active editor
|
||||
try {
|
||||
this._codeEditorService.setActiveCodeEditor(this);
|
||||
super._triggerCommand(handlerId, payload);
|
||||
}
|
||||
finally {
|
||||
this._codeEditorService.setActiveCodeEditor(null);
|
||||
}
|
||||
}
|
||||
else {
|
||||
super._triggerCommand(handlerId, payload);
|
||||
}
|
||||
}
|
||||
};
|
||||
StandaloneCodeEditor = __decorate([
|
||||
__param(2, IInstantiationService),
|
||||
__param(3, ICodeEditorService),
|
||||
__param(4, ICommandService),
|
||||
__param(5, IContextKeyService),
|
||||
__param(6, IKeybindingService),
|
||||
__param(7, IThemeService),
|
||||
__param(8, INotificationService),
|
||||
__param(9, IAccessibilityService),
|
||||
__param(10, ILanguageConfigurationService),
|
||||
__param(11, ILanguageFeaturesService)
|
||||
], StandaloneCodeEditor);
|
||||
export { StandaloneCodeEditor };
|
||||
let StandaloneEditor = class StandaloneEditor extends StandaloneCodeEditor {
|
||||
constructor(domElement, _options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService, themeService, notificationService, configurationService, accessibilityService, modelService, languageService, languageConfigurationService, languageFeaturesService) {
|
||||
const options = Object.assign({}, _options);
|
||||
updateConfigurationService(configurationService, options, false);
|
||||
const themeDomRegistration = themeService.registerEditorContainer(domElement);
|
||||
if (typeof options.theme === 'string') {
|
||||
themeService.setTheme(options.theme);
|
||||
}
|
||||
if (typeof options.autoDetectHighContrast !== 'undefined') {
|
||||
themeService.setAutoDetectHighContrast(Boolean(options.autoDetectHighContrast));
|
||||
}
|
||||
const _model = options.model;
|
||||
delete options.model;
|
||||
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService, themeService, notificationService, accessibilityService, languageConfigurationService, languageFeaturesService);
|
||||
this._configurationService = configurationService;
|
||||
this._standaloneThemeService = themeService;
|
||||
this._register(themeDomRegistration);
|
||||
let model;
|
||||
if (typeof _model === 'undefined') {
|
||||
const languageId = languageService.getLanguageIdByMimeType(options.language) || options.language || PLAINTEXT_LANGUAGE_ID;
|
||||
model = createTextModel(modelService, languageService, options.value || '', languageId, undefined);
|
||||
this._ownsModel = true;
|
||||
}
|
||||
else {
|
||||
model = _model;
|
||||
this._ownsModel = false;
|
||||
}
|
||||
this._attachModel(model);
|
||||
if (model) {
|
||||
const e = {
|
||||
oldModelUrl: null,
|
||||
newModelUrl: model.uri
|
||||
};
|
||||
this._onDidChangeModel.fire(e);
|
||||
}
|
||||
}
|
||||
dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
updateOptions(newOptions) {
|
||||
updateConfigurationService(this._configurationService, newOptions, false);
|
||||
if (typeof newOptions.theme === 'string') {
|
||||
this._standaloneThemeService.setTheme(newOptions.theme);
|
||||
}
|
||||
if (typeof newOptions.autoDetectHighContrast !== 'undefined') {
|
||||
this._standaloneThemeService.setAutoDetectHighContrast(Boolean(newOptions.autoDetectHighContrast));
|
||||
}
|
||||
super.updateOptions(newOptions);
|
||||
}
|
||||
_postDetachModelCleanup(detachedModel) {
|
||||
super._postDetachModelCleanup(detachedModel);
|
||||
if (detachedModel && this._ownsModel) {
|
||||
detachedModel.dispose();
|
||||
this._ownsModel = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
StandaloneEditor = __decorate([
|
||||
__param(2, IInstantiationService),
|
||||
__param(3, ICodeEditorService),
|
||||
__param(4, ICommandService),
|
||||
__param(5, IContextKeyService),
|
||||
__param(6, IKeybindingService),
|
||||
__param(7, IStandaloneThemeService),
|
||||
__param(8, INotificationService),
|
||||
__param(9, IConfigurationService),
|
||||
__param(10, IAccessibilityService),
|
||||
__param(11, IModelService),
|
||||
__param(12, ILanguageService),
|
||||
__param(13, ILanguageConfigurationService),
|
||||
__param(14, ILanguageFeaturesService)
|
||||
], StandaloneEditor);
|
||||
export { StandaloneEditor };
|
||||
let StandaloneDiffEditor = class StandaloneDiffEditor extends DiffEditorWidget {
|
||||
constructor(domElement, _options, instantiationService, contextKeyService, editorWorkerService, codeEditorService, themeService, notificationService, configurationService, contextMenuService, editorProgressService, clipboardService) {
|
||||
const options = Object.assign({}, _options);
|
||||
updateConfigurationService(configurationService, options, true);
|
||||
const themeDomRegistration = themeService.registerEditorContainer(domElement);
|
||||
if (typeof options.theme === 'string') {
|
||||
themeService.setTheme(options.theme);
|
||||
}
|
||||
if (typeof options.autoDetectHighContrast !== 'undefined') {
|
||||
themeService.setAutoDetectHighContrast(Boolean(options.autoDetectHighContrast));
|
||||
}
|
||||
super(domElement, options, {}, clipboardService, editorWorkerService, contextKeyService, instantiationService, codeEditorService, themeService, notificationService, contextMenuService, editorProgressService);
|
||||
this._configurationService = configurationService;
|
||||
this._standaloneThemeService = themeService;
|
||||
this._register(themeDomRegistration);
|
||||
}
|
||||
dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
updateOptions(newOptions) {
|
||||
updateConfigurationService(this._configurationService, newOptions, true);
|
||||
if (typeof newOptions.theme === 'string') {
|
||||
this._standaloneThemeService.setTheme(newOptions.theme);
|
||||
}
|
||||
if (typeof newOptions.autoDetectHighContrast !== 'undefined') {
|
||||
this._standaloneThemeService.setAutoDetectHighContrast(Boolean(newOptions.autoDetectHighContrast));
|
||||
}
|
||||
super.updateOptions(newOptions);
|
||||
}
|
||||
_createInnerEditor(instantiationService, container, options) {
|
||||
return instantiationService.createInstance(StandaloneCodeEditor, container, options);
|
||||
}
|
||||
getOriginalEditor() {
|
||||
return super.getOriginalEditor();
|
||||
}
|
||||
getModifiedEditor() {
|
||||
return super.getModifiedEditor();
|
||||
}
|
||||
addCommand(keybinding, handler, context) {
|
||||
return this.getModifiedEditor().addCommand(keybinding, handler, context);
|
||||
}
|
||||
createContextKey(key, defaultValue) {
|
||||
return this.getModifiedEditor().createContextKey(key, defaultValue);
|
||||
}
|
||||
addAction(descriptor) {
|
||||
return this.getModifiedEditor().addAction(descriptor);
|
||||
}
|
||||
};
|
||||
StandaloneDiffEditor = __decorate([
|
||||
__param(2, IInstantiationService),
|
||||
__param(3, IContextKeyService),
|
||||
__param(4, IEditorWorkerService),
|
||||
__param(5, ICodeEditorService),
|
||||
__param(6, IStandaloneThemeService),
|
||||
__param(7, INotificationService),
|
||||
__param(8, IConfigurationService),
|
||||
__param(9, IContextMenuService),
|
||||
__param(10, IEditorProgressService),
|
||||
__param(11, IClipboardService)
|
||||
], StandaloneDiffEditor);
|
||||
export { StandaloneDiffEditor };
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function createTextModel(modelService, languageService, value, languageId, uri) {
|
||||
value = value || '';
|
||||
if (!languageId) {
|
||||
const firstLF = value.indexOf('\n');
|
||||
let firstLine = value;
|
||||
if (firstLF !== -1) {
|
||||
firstLine = value.substring(0, firstLF);
|
||||
}
|
||||
return doCreateModel(modelService, value, languageService.createByFilepathOrFirstLine(uri || null, firstLine), uri);
|
||||
}
|
||||
return doCreateModel(modelService, value, languageService.createById(languageId), uri);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function doCreateModel(modelService, value, languageSelection, uri) {
|
||||
return modelService.createModel(value, languageSelection, uri);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import { windowOpenNoOpener } from '../../../base/browser/dom.js';
|
||||
import { Schemas } from '../../../base/common/network.js';
|
||||
import { AbstractCodeEditorService } from '../../browser/services/abstractCodeEditorService.js';
|
||||
import { ICodeEditorService } from '../../browser/services/codeEditorService.js';
|
||||
import { IContextKeyService } from '../../../platform/contextkey/common/contextkey.js';
|
||||
import { registerSingleton } from '../../../platform/instantiation/common/extensions.js';
|
||||
import { IThemeService } from '../../../platform/theme/common/themeService.js';
|
||||
let StandaloneCodeEditorService = class StandaloneCodeEditorService extends AbstractCodeEditorService {
|
||||
constructor(contextKeyService, themeService) {
|
||||
super(themeService);
|
||||
this.onCodeEditorAdd(() => this._checkContextKey());
|
||||
this.onCodeEditorRemove(() => this._checkContextKey());
|
||||
this._editorIsOpen = contextKeyService.createKey('editorIsOpen', false);
|
||||
this._activeCodeEditor = null;
|
||||
this.registerCodeEditorOpenHandler((input, source, sideBySide) => __awaiter(this, void 0, void 0, function* () {
|
||||
if (!source) {
|
||||
return null;
|
||||
}
|
||||
return this.doOpenEditor(source, input);
|
||||
}));
|
||||
}
|
||||
_checkContextKey() {
|
||||
let hasCodeEditor = false;
|
||||
for (const editor of this.listCodeEditors()) {
|
||||
if (!editor.isSimpleWidget) {
|
||||
hasCodeEditor = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this._editorIsOpen.set(hasCodeEditor);
|
||||
}
|
||||
setActiveCodeEditor(activeCodeEditor) {
|
||||
this._activeCodeEditor = activeCodeEditor;
|
||||
}
|
||||
getActiveCodeEditor() {
|
||||
return this._activeCodeEditor;
|
||||
}
|
||||
doOpenEditor(editor, input) {
|
||||
const model = this.findModel(editor, input.resource);
|
||||
if (!model) {
|
||||
if (input.resource) {
|
||||
const schema = input.resource.scheme;
|
||||
if (schema === Schemas.http || schema === Schemas.https) {
|
||||
// This is a fully qualified http or https URL
|
||||
windowOpenNoOpener(input.resource.toString());
|
||||
return editor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const selection = (input.options ? input.options.selection : null);
|
||||
if (selection) {
|
||||
if (typeof selection.endLineNumber === 'number' && typeof selection.endColumn === 'number') {
|
||||
editor.setSelection(selection);
|
||||
editor.revealRangeInCenter(selection, 1 /* ScrollType.Immediate */);
|
||||
}
|
||||
else {
|
||||
const pos = {
|
||||
lineNumber: selection.startLineNumber,
|
||||
column: selection.startColumn
|
||||
};
|
||||
editor.setPosition(pos);
|
||||
editor.revealPositionInCenter(pos, 1 /* ScrollType.Immediate */);
|
||||
}
|
||||
}
|
||||
return editor;
|
||||
}
|
||||
findModel(editor, resource) {
|
||||
const model = editor.getModel();
|
||||
if (model && model.uri.toString() !== resource.toString()) {
|
||||
return null;
|
||||
}
|
||||
return model;
|
||||
}
|
||||
};
|
||||
StandaloneCodeEditorService = __decorate([
|
||||
__param(0, IContextKeyService),
|
||||
__param(1, IThemeService)
|
||||
], StandaloneCodeEditorService);
|
||||
export { StandaloneCodeEditorService };
|
||||
registerSingleton(ICodeEditorService, StandaloneCodeEditorService);
|
||||
@@ -0,0 +1,333 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import './standalone-tokens.css';
|
||||
import { splitLines } from '../../../base/common/strings.js';
|
||||
import { FontMeasurements } from '../../browser/config/fontMeasurements.js';
|
||||
import { ICodeEditorService } from '../../browser/services/codeEditorService.js';
|
||||
import { DiffNavigator } from '../../browser/widget/diffNavigator.js';
|
||||
import { ApplyUpdateResult, ConfigurationChangedEvent, EditorOptions } from '../../common/config/editorOptions.js';
|
||||
import { BareFontInfo, FontInfo } from '../../common/config/fontInfo.js';
|
||||
import { EditorType } from '../../common/editorCommon.js';
|
||||
import { FindMatch, TextModelResolvedOptions } from '../../common/model.js';
|
||||
import * as languages from '../../common/languages.js';
|
||||
import { ILanguageConfigurationService } from '../../common/languages/languageConfigurationRegistry.js';
|
||||
import { NullState, nullTokenize } from '../../common/languages/nullTokenize.js';
|
||||
import { ILanguageService } from '../../common/languages/language.js';
|
||||
import { IModelService } from '../../common/services/model.js';
|
||||
import { createWebWorker as actualCreateWebWorker } from '../../browser/services/webWorker.js';
|
||||
import * as standaloneEnums from '../../common/standalone/standaloneEnums.js';
|
||||
import { Colorizer } from './colorizer.js';
|
||||
import { createTextModel, StandaloneDiffEditor, StandaloneEditor } from './standaloneCodeEditor.js';
|
||||
import { StandaloneServices } from './standaloneServices.js';
|
||||
import { IStandaloneThemeService } from '../common/standaloneTheme.js';
|
||||
import { CommandsRegistry } from '../../../platform/commands/common/commands.js';
|
||||
import { IMarkerService } from '../../../platform/markers/common/markers.js';
|
||||
/**
|
||||
* Create a new editor under `domElement`.
|
||||
* `domElement` should be empty (not contain other dom nodes).
|
||||
* The editor will read the size of `domElement`.
|
||||
*/
|
||||
export function create(domElement, options, override) {
|
||||
const instantiationService = StandaloneServices.initialize(override || {});
|
||||
return instantiationService.createInstance(StandaloneEditor, domElement, options);
|
||||
}
|
||||
/**
|
||||
* Emitted when an editor is created.
|
||||
* Creating a diff editor might cause this listener to be invoked with the two editors.
|
||||
* @event
|
||||
*/
|
||||
export function onDidCreateEditor(listener) {
|
||||
const codeEditorService = StandaloneServices.get(ICodeEditorService);
|
||||
return codeEditorService.onCodeEditorAdd((editor) => {
|
||||
listener(editor);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Emitted when an diff editor is created.
|
||||
* @event
|
||||
*/
|
||||
export function onDidCreateDiffEditor(listener) {
|
||||
const codeEditorService = StandaloneServices.get(ICodeEditorService);
|
||||
return codeEditorService.onDiffEditorAdd((editor) => {
|
||||
listener(editor);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get all the created editors.
|
||||
*/
|
||||
export function getEditors() {
|
||||
const codeEditorService = StandaloneServices.get(ICodeEditorService);
|
||||
return codeEditorService.listCodeEditors();
|
||||
}
|
||||
/**
|
||||
* Get all the created diff editors.
|
||||
*/
|
||||
export function getDiffEditors() {
|
||||
const codeEditorService = StandaloneServices.get(ICodeEditorService);
|
||||
return codeEditorService.listDiffEditors();
|
||||
}
|
||||
/**
|
||||
* Create a new diff editor under `domElement`.
|
||||
* `domElement` should be empty (not contain other dom nodes).
|
||||
* The editor will read the size of `domElement`.
|
||||
*/
|
||||
export function createDiffEditor(domElement, options, override) {
|
||||
const instantiationService = StandaloneServices.initialize(override || {});
|
||||
return instantiationService.createInstance(StandaloneDiffEditor, domElement, options);
|
||||
}
|
||||
export function createDiffNavigator(diffEditor, opts) {
|
||||
return new DiffNavigator(diffEditor, opts);
|
||||
}
|
||||
/**
|
||||
* Create a new editor model.
|
||||
* You can specify the language that should be set for this model or let the language be inferred from the `uri`.
|
||||
*/
|
||||
export function createModel(value, language, uri) {
|
||||
const languageService = StandaloneServices.get(ILanguageService);
|
||||
const languageId = languageService.getLanguageIdByMimeType(language) || language;
|
||||
return createTextModel(StandaloneServices.get(IModelService), languageService, value, languageId, uri);
|
||||
}
|
||||
/**
|
||||
* Change the language for a model.
|
||||
*/
|
||||
export function setModelLanguage(model, languageId) {
|
||||
const languageService = StandaloneServices.get(ILanguageService);
|
||||
const modelService = StandaloneServices.get(IModelService);
|
||||
modelService.setMode(model, languageService.createById(languageId));
|
||||
}
|
||||
/**
|
||||
* Set the markers for a model.
|
||||
*/
|
||||
export function setModelMarkers(model, owner, markers) {
|
||||
if (model) {
|
||||
const markerService = StandaloneServices.get(IMarkerService);
|
||||
markerService.changeOne(owner, model.uri, markers);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Remove all markers of an owner.
|
||||
*/
|
||||
export function removeAllMarkers(owner) {
|
||||
const markerService = StandaloneServices.get(IMarkerService);
|
||||
markerService.changeAll(owner, []);
|
||||
}
|
||||
/**
|
||||
* Get markers for owner and/or resource
|
||||
*
|
||||
* @returns list of markers
|
||||
*/
|
||||
export function getModelMarkers(filter) {
|
||||
const markerService = StandaloneServices.get(IMarkerService);
|
||||
return markerService.read(filter);
|
||||
}
|
||||
/**
|
||||
* Emitted when markers change for a model.
|
||||
* @event
|
||||
*/
|
||||
export function onDidChangeMarkers(listener) {
|
||||
const markerService = StandaloneServices.get(IMarkerService);
|
||||
return markerService.onMarkerChanged(listener);
|
||||
}
|
||||
/**
|
||||
* Get the model that has `uri` if it exists.
|
||||
*/
|
||||
export function getModel(uri) {
|
||||
const modelService = StandaloneServices.get(IModelService);
|
||||
return modelService.getModel(uri);
|
||||
}
|
||||
/**
|
||||
* Get all the created models.
|
||||
*/
|
||||
export function getModels() {
|
||||
const modelService = StandaloneServices.get(IModelService);
|
||||
return modelService.getModels();
|
||||
}
|
||||
/**
|
||||
* Emitted when a model is created.
|
||||
* @event
|
||||
*/
|
||||
export function onDidCreateModel(listener) {
|
||||
const modelService = StandaloneServices.get(IModelService);
|
||||
return modelService.onModelAdded(listener);
|
||||
}
|
||||
/**
|
||||
* Emitted right before a model is disposed.
|
||||
* @event
|
||||
*/
|
||||
export function onWillDisposeModel(listener) {
|
||||
const modelService = StandaloneServices.get(IModelService);
|
||||
return modelService.onModelRemoved(listener);
|
||||
}
|
||||
/**
|
||||
* Emitted when a different language is set to a model.
|
||||
* @event
|
||||
*/
|
||||
export function onDidChangeModelLanguage(listener) {
|
||||
const modelService = StandaloneServices.get(IModelService);
|
||||
return modelService.onModelLanguageChanged((e) => {
|
||||
listener({
|
||||
model: e.model,
|
||||
oldLanguage: e.oldLanguageId
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Create a new web worker that has model syncing capabilities built in.
|
||||
* Specify an AMD module to load that will `create` an object that will be proxied.
|
||||
*/
|
||||
export function createWebWorker(opts) {
|
||||
return actualCreateWebWorker(StandaloneServices.get(IModelService), StandaloneServices.get(ILanguageConfigurationService), opts);
|
||||
}
|
||||
/**
|
||||
* Colorize the contents of `domNode` using attribute `data-lang`.
|
||||
*/
|
||||
export function colorizeElement(domNode, options) {
|
||||
const languageService = StandaloneServices.get(ILanguageService);
|
||||
const themeService = StandaloneServices.get(IStandaloneThemeService);
|
||||
themeService.registerEditorContainer(domNode);
|
||||
return Colorizer.colorizeElement(themeService, languageService, domNode, options);
|
||||
}
|
||||
/**
|
||||
* Colorize `text` using language `languageId`.
|
||||
*/
|
||||
export function colorize(text, languageId, options) {
|
||||
const languageService = StandaloneServices.get(ILanguageService);
|
||||
const themeService = StandaloneServices.get(IStandaloneThemeService);
|
||||
themeService.registerEditorContainer(document.body);
|
||||
return Colorizer.colorize(languageService, text, languageId, options);
|
||||
}
|
||||
/**
|
||||
* Colorize a line in a model.
|
||||
*/
|
||||
export function colorizeModelLine(model, lineNumber, tabSize = 4) {
|
||||
const themeService = StandaloneServices.get(IStandaloneThemeService);
|
||||
themeService.registerEditorContainer(document.body);
|
||||
return Colorizer.colorizeModelLine(model, lineNumber, tabSize);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function getSafeTokenizationSupport(language) {
|
||||
const tokenizationSupport = languages.TokenizationRegistry.get(language);
|
||||
if (tokenizationSupport) {
|
||||
return tokenizationSupport;
|
||||
}
|
||||
return {
|
||||
getInitialState: () => NullState,
|
||||
tokenize: (line, hasEOL, state) => nullTokenize(language, state)
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Tokenize `text` using language `languageId`
|
||||
*/
|
||||
export function tokenize(text, languageId) {
|
||||
// Needed in order to get the mode registered for subsequent look-ups
|
||||
languages.TokenizationRegistry.getOrCreate(languageId);
|
||||
const tokenizationSupport = getSafeTokenizationSupport(languageId);
|
||||
const lines = splitLines(text);
|
||||
const result = [];
|
||||
let state = tokenizationSupport.getInitialState();
|
||||
for (let i = 0, len = lines.length; i < len; i++) {
|
||||
const line = lines[i];
|
||||
const tokenizationResult = tokenizationSupport.tokenize(line, true, state);
|
||||
result[i] = tokenizationResult.tokens;
|
||||
state = tokenizationResult.endState;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Define a new theme or update an existing theme.
|
||||
*/
|
||||
export function defineTheme(themeName, themeData) {
|
||||
const standaloneThemeService = StandaloneServices.get(IStandaloneThemeService);
|
||||
standaloneThemeService.defineTheme(themeName, themeData);
|
||||
}
|
||||
/**
|
||||
* Switches to a theme.
|
||||
*/
|
||||
export function setTheme(themeName) {
|
||||
const standaloneThemeService = StandaloneServices.get(IStandaloneThemeService);
|
||||
standaloneThemeService.setTheme(themeName);
|
||||
}
|
||||
/**
|
||||
* Clears all cached font measurements and triggers re-measurement.
|
||||
*/
|
||||
export function remeasureFonts() {
|
||||
FontMeasurements.clearAllFontInfos();
|
||||
}
|
||||
/**
|
||||
* Register a command.
|
||||
*/
|
||||
export function registerCommand(id, handler) {
|
||||
return CommandsRegistry.registerCommand({ id, handler });
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function createMonacoEditorAPI() {
|
||||
return {
|
||||
// methods
|
||||
create: create,
|
||||
getEditors: getEditors,
|
||||
getDiffEditors: getDiffEditors,
|
||||
onDidCreateEditor: onDidCreateEditor,
|
||||
onDidCreateDiffEditor: onDidCreateDiffEditor,
|
||||
createDiffEditor: createDiffEditor,
|
||||
createDiffNavigator: createDiffNavigator,
|
||||
createModel: createModel,
|
||||
setModelLanguage: setModelLanguage,
|
||||
setModelMarkers: setModelMarkers,
|
||||
getModelMarkers: getModelMarkers,
|
||||
removeAllMarkers: removeAllMarkers,
|
||||
onDidChangeMarkers: onDidChangeMarkers,
|
||||
getModels: getModels,
|
||||
getModel: getModel,
|
||||
onDidCreateModel: onDidCreateModel,
|
||||
onWillDisposeModel: onWillDisposeModel,
|
||||
onDidChangeModelLanguage: onDidChangeModelLanguage,
|
||||
createWebWorker: createWebWorker,
|
||||
colorizeElement: colorizeElement,
|
||||
colorize: colorize,
|
||||
colorizeModelLine: colorizeModelLine,
|
||||
tokenize: tokenize,
|
||||
defineTheme: defineTheme,
|
||||
setTheme: setTheme,
|
||||
remeasureFonts: remeasureFonts,
|
||||
registerCommand: registerCommand,
|
||||
// enums
|
||||
AccessibilitySupport: standaloneEnums.AccessibilitySupport,
|
||||
ContentWidgetPositionPreference: standaloneEnums.ContentWidgetPositionPreference,
|
||||
CursorChangeReason: standaloneEnums.CursorChangeReason,
|
||||
DefaultEndOfLine: standaloneEnums.DefaultEndOfLine,
|
||||
EditorAutoIndentStrategy: standaloneEnums.EditorAutoIndentStrategy,
|
||||
EditorOption: standaloneEnums.EditorOption,
|
||||
EndOfLinePreference: standaloneEnums.EndOfLinePreference,
|
||||
EndOfLineSequence: standaloneEnums.EndOfLineSequence,
|
||||
MinimapPosition: standaloneEnums.MinimapPosition,
|
||||
MouseTargetType: standaloneEnums.MouseTargetType,
|
||||
OverlayWidgetPositionPreference: standaloneEnums.OverlayWidgetPositionPreference,
|
||||
OverviewRulerLane: standaloneEnums.OverviewRulerLane,
|
||||
RenderLineNumbersType: standaloneEnums.RenderLineNumbersType,
|
||||
RenderMinimap: standaloneEnums.RenderMinimap,
|
||||
ScrollbarVisibility: standaloneEnums.ScrollbarVisibility,
|
||||
ScrollType: standaloneEnums.ScrollType,
|
||||
TextEditorCursorBlinkingStyle: standaloneEnums.TextEditorCursorBlinkingStyle,
|
||||
TextEditorCursorStyle: standaloneEnums.TextEditorCursorStyle,
|
||||
TrackedRangeStickiness: standaloneEnums.TrackedRangeStickiness,
|
||||
WrappingIndent: standaloneEnums.WrappingIndent,
|
||||
InjectedTextCursorStops: standaloneEnums.InjectedTextCursorStops,
|
||||
PositionAffinity: standaloneEnums.PositionAffinity,
|
||||
// classes
|
||||
ConfigurationChangedEvent: ConfigurationChangedEvent,
|
||||
BareFontInfo: BareFontInfo,
|
||||
FontInfo: FontInfo,
|
||||
TextModelResolvedOptions: TextModelResolvedOptions,
|
||||
FindMatch: FindMatch,
|
||||
ApplyUpdateResult: ApplyUpdateResult,
|
||||
// vars
|
||||
EditorType: EditorType,
|
||||
EditorOptions: EditorOptions
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,547 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import { Color } from '../../../base/common/color.js';
|
||||
import { Range } from '../../common/core/range.js';
|
||||
import * as languages from '../../common/languages.js';
|
||||
import { ILanguageConfigurationService } from '../../common/languages/languageConfigurationRegistry.js';
|
||||
import { ModesRegistry } from '../../common/languages/modesRegistry.js';
|
||||
import { ILanguageService } from '../../common/languages/language.js';
|
||||
import * as standaloneEnums from '../../common/standalone/standaloneEnums.js';
|
||||
import { StandaloneServices } from './standaloneServices.js';
|
||||
import { compile } from '../common/monarch/monarchCompile.js';
|
||||
import { MonarchTokenizer } from '../common/monarch/monarchLexer.js';
|
||||
import { IStandaloneThemeService } from '../common/standaloneTheme.js';
|
||||
import { IMarkerService } from '../../../platform/markers/common/markers.js';
|
||||
import { ILanguageFeaturesService } from '../../common/services/languageFeatures.js';
|
||||
import { IConfigurationService } from '../../../platform/configuration/common/configuration.js';
|
||||
/**
|
||||
* Register information about a new language.
|
||||
*/
|
||||
export function register(language) {
|
||||
// Intentionally using the `ModesRegistry` here to avoid
|
||||
// instantiating services too quickly in the standalone editor.
|
||||
ModesRegistry.registerLanguage(language);
|
||||
}
|
||||
/**
|
||||
* Get the information of all the registered languages.
|
||||
*/
|
||||
export function getLanguages() {
|
||||
let result = [];
|
||||
result = result.concat(ModesRegistry.getLanguages());
|
||||
return result;
|
||||
}
|
||||
export function getEncodedLanguageId(languageId) {
|
||||
const languageService = StandaloneServices.get(ILanguageService);
|
||||
return languageService.languageIdCodec.encodeLanguageId(languageId);
|
||||
}
|
||||
/**
|
||||
* An event emitted when a language is needed for the first time (e.g. a model has it set).
|
||||
* @event
|
||||
*/
|
||||
export function onLanguage(languageId, callback) {
|
||||
const languageService = StandaloneServices.get(ILanguageService);
|
||||
const disposable = languageService.onDidEncounterLanguage((encounteredLanguageId) => {
|
||||
if (encounteredLanguageId === languageId) {
|
||||
// stop listening
|
||||
disposable.dispose();
|
||||
// invoke actual listener
|
||||
callback();
|
||||
}
|
||||
});
|
||||
return disposable;
|
||||
}
|
||||
/**
|
||||
* Set the editing configuration for a language.
|
||||
*/
|
||||
export function setLanguageConfiguration(languageId, configuration) {
|
||||
const languageService = StandaloneServices.get(ILanguageService);
|
||||
if (!languageService.isRegisteredLanguageId(languageId)) {
|
||||
throw new Error(`Cannot set configuration for unknown language ${languageId}`);
|
||||
}
|
||||
const languageConfigurationService = StandaloneServices.get(ILanguageConfigurationService);
|
||||
return languageConfigurationService.register(languageId, configuration, 100);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export class EncodedTokenizationSupportAdapter {
|
||||
constructor(languageId, actual) {
|
||||
this._languageId = languageId;
|
||||
this._actual = actual;
|
||||
}
|
||||
getInitialState() {
|
||||
return this._actual.getInitialState();
|
||||
}
|
||||
tokenize(line, hasEOL, state) {
|
||||
if (typeof this._actual.tokenize === 'function') {
|
||||
return TokenizationSupportAdapter.adaptTokenize(this._languageId, this._actual, line, state);
|
||||
}
|
||||
throw new Error('Not supported!');
|
||||
}
|
||||
tokenizeEncoded(line, hasEOL, state) {
|
||||
const result = this._actual.tokenizeEncoded(line, state);
|
||||
return new languages.EncodedTokenizationResult(result.tokens, result.endState);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export class TokenizationSupportAdapter {
|
||||
constructor(_languageId, _actual, _languageService, _standaloneThemeService) {
|
||||
this._languageId = _languageId;
|
||||
this._actual = _actual;
|
||||
this._languageService = _languageService;
|
||||
this._standaloneThemeService = _standaloneThemeService;
|
||||
}
|
||||
getInitialState() {
|
||||
return this._actual.getInitialState();
|
||||
}
|
||||
static _toClassicTokens(tokens, language) {
|
||||
const result = [];
|
||||
let previousStartIndex = 0;
|
||||
for (let i = 0, len = tokens.length; i < len; i++) {
|
||||
const t = tokens[i];
|
||||
let startIndex = t.startIndex;
|
||||
// Prevent issues stemming from a buggy external tokenizer.
|
||||
if (i === 0) {
|
||||
// Force first token to start at first index!
|
||||
startIndex = 0;
|
||||
}
|
||||
else if (startIndex < previousStartIndex) {
|
||||
// Force tokens to be after one another!
|
||||
startIndex = previousStartIndex;
|
||||
}
|
||||
result[i] = new languages.Token(startIndex, t.scopes, language);
|
||||
previousStartIndex = startIndex;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static adaptTokenize(language, actual, line, state) {
|
||||
const actualResult = actual.tokenize(line, state);
|
||||
const tokens = TokenizationSupportAdapter._toClassicTokens(actualResult.tokens, language);
|
||||
let endState;
|
||||
// try to save an object if possible
|
||||
if (actualResult.endState.equals(state)) {
|
||||
endState = state;
|
||||
}
|
||||
else {
|
||||
endState = actualResult.endState;
|
||||
}
|
||||
return new languages.TokenizationResult(tokens, endState);
|
||||
}
|
||||
tokenize(line, hasEOL, state) {
|
||||
return TokenizationSupportAdapter.adaptTokenize(this._languageId, this._actual, line, state);
|
||||
}
|
||||
_toBinaryTokens(languageIdCodec, tokens) {
|
||||
const languageId = languageIdCodec.encodeLanguageId(this._languageId);
|
||||
const tokenTheme = this._standaloneThemeService.getColorTheme().tokenTheme;
|
||||
const result = [];
|
||||
let resultLen = 0;
|
||||
let previousStartIndex = 0;
|
||||
for (let i = 0, len = tokens.length; i < len; i++) {
|
||||
const t = tokens[i];
|
||||
const metadata = tokenTheme.match(languageId, t.scopes);
|
||||
if (resultLen > 0 && result[resultLen - 1] === metadata) {
|
||||
// same metadata
|
||||
continue;
|
||||
}
|
||||
let startIndex = t.startIndex;
|
||||
// Prevent issues stemming from a buggy external tokenizer.
|
||||
if (i === 0) {
|
||||
// Force first token to start at first index!
|
||||
startIndex = 0;
|
||||
}
|
||||
else if (startIndex < previousStartIndex) {
|
||||
// Force tokens to be after one another!
|
||||
startIndex = previousStartIndex;
|
||||
}
|
||||
result[resultLen++] = startIndex;
|
||||
result[resultLen++] = metadata;
|
||||
previousStartIndex = startIndex;
|
||||
}
|
||||
const actualResult = new Uint32Array(resultLen);
|
||||
for (let i = 0; i < resultLen; i++) {
|
||||
actualResult[i] = result[i];
|
||||
}
|
||||
return actualResult;
|
||||
}
|
||||
tokenizeEncoded(line, hasEOL, state) {
|
||||
const actualResult = this._actual.tokenize(line, state);
|
||||
const tokens = this._toBinaryTokens(this._languageService.languageIdCodec, actualResult.tokens);
|
||||
let endState;
|
||||
// try to save an object if possible
|
||||
if (actualResult.endState.equals(state)) {
|
||||
endState = state;
|
||||
}
|
||||
else {
|
||||
endState = actualResult.endState;
|
||||
}
|
||||
return new languages.EncodedTokenizationResult(tokens, endState);
|
||||
}
|
||||
}
|
||||
function isATokensProvider(provider) {
|
||||
return (typeof provider.getInitialState === 'function');
|
||||
}
|
||||
function isEncodedTokensProvider(provider) {
|
||||
return 'tokenizeEncoded' in provider;
|
||||
}
|
||||
function isThenable(obj) {
|
||||
return obj && typeof obj.then === 'function';
|
||||
}
|
||||
/**
|
||||
* Change the color map that is used for token colors.
|
||||
* Supported formats (hex): #RRGGBB, $RRGGBBAA, #RGB, #RGBA
|
||||
*/
|
||||
export function setColorMap(colorMap) {
|
||||
const standaloneThemeService = StandaloneServices.get(IStandaloneThemeService);
|
||||
if (colorMap) {
|
||||
const result = [null];
|
||||
for (let i = 1, len = colorMap.length; i < len; i++) {
|
||||
result[i] = Color.fromHex(colorMap[i]);
|
||||
}
|
||||
standaloneThemeService.setColorMapOverride(result);
|
||||
}
|
||||
else {
|
||||
standaloneThemeService.setColorMapOverride(null);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function createTokenizationSupportAdapter(languageId, provider) {
|
||||
if (isEncodedTokensProvider(provider)) {
|
||||
return new EncodedTokenizationSupportAdapter(languageId, provider);
|
||||
}
|
||||
else {
|
||||
return new TokenizationSupportAdapter(languageId, provider, StandaloneServices.get(ILanguageService), StandaloneServices.get(IStandaloneThemeService));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Register a tokens provider factory for a language. This tokenizer will be exclusive with a tokenizer
|
||||
* set using `setTokensProvider` or one created using `setMonarchTokensProvider`, but will work together
|
||||
* with a tokens provider set using `registerDocumentSemanticTokensProvider` or `registerDocumentRangeSemanticTokensProvider`.
|
||||
*/
|
||||
export function registerTokensProviderFactory(languageId, factory) {
|
||||
const adaptedFactory = {
|
||||
createTokenizationSupport: () => __awaiter(this, void 0, void 0, function* () {
|
||||
const result = yield Promise.resolve(factory.create());
|
||||
if (!result) {
|
||||
return null;
|
||||
}
|
||||
if (isATokensProvider(result)) {
|
||||
return createTokenizationSupportAdapter(languageId, result);
|
||||
}
|
||||
return new MonarchTokenizer(StandaloneServices.get(ILanguageService), StandaloneServices.get(IStandaloneThemeService), languageId, compile(languageId, result), StandaloneServices.get(IConfigurationService));
|
||||
})
|
||||
};
|
||||
return languages.TokenizationRegistry.registerFactory(languageId, adaptedFactory);
|
||||
}
|
||||
/**
|
||||
* Set the tokens provider for a language (manual implementation). This tokenizer will be exclusive
|
||||
* with a tokenizer created using `setMonarchTokensProvider`, or with `registerTokensProviderFactory`,
|
||||
* but will work together with a tokens provider set using `registerDocumentSemanticTokensProvider`
|
||||
* or `registerDocumentRangeSemanticTokensProvider`.
|
||||
*/
|
||||
export function setTokensProvider(languageId, provider) {
|
||||
const languageService = StandaloneServices.get(ILanguageService);
|
||||
if (!languageService.isRegisteredLanguageId(languageId)) {
|
||||
throw new Error(`Cannot set tokens provider for unknown language ${languageId}`);
|
||||
}
|
||||
if (isThenable(provider)) {
|
||||
return registerTokensProviderFactory(languageId, { create: () => provider });
|
||||
}
|
||||
return languages.TokenizationRegistry.register(languageId, createTokenizationSupportAdapter(languageId, provider));
|
||||
}
|
||||
/**
|
||||
* Set the tokens provider for a language (monarch implementation). This tokenizer will be exclusive
|
||||
* with a tokenizer set using `setTokensProvider`, or with `registerTokensProviderFactory`, but will
|
||||
* work together with a tokens provider set using `registerDocumentSemanticTokensProvider` or
|
||||
* `registerDocumentRangeSemanticTokensProvider`.
|
||||
*/
|
||||
export function setMonarchTokensProvider(languageId, languageDef) {
|
||||
const create = (languageDef) => {
|
||||
return new MonarchTokenizer(StandaloneServices.get(ILanguageService), StandaloneServices.get(IStandaloneThemeService), languageId, compile(languageId, languageDef), StandaloneServices.get(IConfigurationService));
|
||||
};
|
||||
if (isThenable(languageDef)) {
|
||||
return registerTokensProviderFactory(languageId, { create: () => languageDef });
|
||||
}
|
||||
return languages.TokenizationRegistry.register(languageId, create(languageDef));
|
||||
}
|
||||
/**
|
||||
* Register a reference provider (used by e.g. reference search).
|
||||
*/
|
||||
export function registerReferenceProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.referenceProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a rename provider (used by e.g. rename symbol).
|
||||
*/
|
||||
export function registerRenameProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.renameProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a signature help provider (used by e.g. parameter hints).
|
||||
*/
|
||||
export function registerSignatureHelpProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.signatureHelpProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a hover provider (used by e.g. editor hover).
|
||||
*/
|
||||
export function registerHoverProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.hoverProvider.register(languageSelector, {
|
||||
provideHover: (model, position, token) => {
|
||||
const word = model.getWordAtPosition(position);
|
||||
return Promise.resolve(provider.provideHover(model, position, token)).then((value) => {
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
if (!value.range && word) {
|
||||
value.range = new Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn);
|
||||
}
|
||||
if (!value.range) {
|
||||
value.range = new Range(position.lineNumber, position.column, position.lineNumber, position.column);
|
||||
}
|
||||
return value;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Register a document symbol provider (used by e.g. outline).
|
||||
*/
|
||||
export function registerDocumentSymbolProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.documentSymbolProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a document highlight provider (used by e.g. highlight occurrences).
|
||||
*/
|
||||
export function registerDocumentHighlightProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.documentHighlightProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register an linked editing range provider.
|
||||
*/
|
||||
export function registerLinkedEditingRangeProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.linkedEditingRangeProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a definition provider (used by e.g. go to definition).
|
||||
*/
|
||||
export function registerDefinitionProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.definitionProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a implementation provider (used by e.g. go to implementation).
|
||||
*/
|
||||
export function registerImplementationProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.implementationProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a type definition provider (used by e.g. go to type definition).
|
||||
*/
|
||||
export function registerTypeDefinitionProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.typeDefinitionProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a code lens provider (used by e.g. inline code lenses).
|
||||
*/
|
||||
export function registerCodeLensProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.codeLensProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a code action provider (used by e.g. quick fix).
|
||||
*/
|
||||
export function registerCodeActionProvider(languageSelector, provider, metadata) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.codeActionProvider.register(languageSelector, {
|
||||
providedCodeActionKinds: metadata === null || metadata === void 0 ? void 0 : metadata.providedCodeActionKinds,
|
||||
documentation: metadata === null || metadata === void 0 ? void 0 : metadata.documentation,
|
||||
provideCodeActions: (model, range, context, token) => {
|
||||
const markerService = StandaloneServices.get(IMarkerService);
|
||||
const markers = markerService.read({ resource: model.uri }).filter(m => {
|
||||
return Range.areIntersectingOrTouching(m, range);
|
||||
});
|
||||
return provider.provideCodeActions(model, range, { markers, only: context.only, trigger: context.trigger }, token);
|
||||
},
|
||||
resolveCodeAction: provider.resolveCodeAction
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Register a formatter that can handle only entire models.
|
||||
*/
|
||||
export function registerDocumentFormattingEditProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.documentFormattingEditProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a formatter that can handle a range inside a model.
|
||||
*/
|
||||
export function registerDocumentRangeFormattingEditProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.documentRangeFormattingEditProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a formatter than can do formatting as the user types.
|
||||
*/
|
||||
export function registerOnTypeFormattingEditProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.onTypeFormattingEditProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a link provider that can find links in text.
|
||||
*/
|
||||
export function registerLinkProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.linkProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a completion item provider (use by e.g. suggestions).
|
||||
*/
|
||||
export function registerCompletionItemProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.completionProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a document color provider (used by Color Picker, Color Decorator).
|
||||
*/
|
||||
export function registerColorProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.colorProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a folding range provider
|
||||
*/
|
||||
export function registerFoldingRangeProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.foldingRangeProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a declaration provider
|
||||
*/
|
||||
export function registerDeclarationProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.declarationProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a selection range provider
|
||||
*/
|
||||
export function registerSelectionRangeProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.selectionRangeProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a document semantic tokens provider. A semantic tokens provider will complement and enhance a
|
||||
* simple top-down tokenizer. Simple top-down tokenizers can be set either via `setMonarchTokensProvider`
|
||||
* or `setTokensProvider`.
|
||||
*
|
||||
* For the best user experience, register both a semantic tokens provider and a top-down tokenizer.
|
||||
*/
|
||||
export function registerDocumentSemanticTokensProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.documentSemanticTokensProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register a document range semantic tokens provider. A semantic tokens provider will complement and enhance a
|
||||
* simple top-down tokenizer. Simple top-down tokenizers can be set either via `setMonarchTokensProvider`
|
||||
* or `setTokensProvider`.
|
||||
*
|
||||
* For the best user experience, register both a semantic tokens provider and a top-down tokenizer.
|
||||
*/
|
||||
export function registerDocumentRangeSemanticTokensProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.documentRangeSemanticTokensProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register an inline completions provider.
|
||||
*/
|
||||
export function registerInlineCompletionsProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.inlineCompletionsProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* Register an inlay hints provider.
|
||||
*/
|
||||
export function registerInlayHintsProvider(languageSelector, provider) {
|
||||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.inlayHintsProvider.register(languageSelector, provider);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function createMonacoLanguagesAPI() {
|
||||
return {
|
||||
register: register,
|
||||
getLanguages: getLanguages,
|
||||
onLanguage: onLanguage,
|
||||
getEncodedLanguageId: getEncodedLanguageId,
|
||||
// provider methods
|
||||
setLanguageConfiguration: setLanguageConfiguration,
|
||||
setColorMap: setColorMap,
|
||||
registerTokensProviderFactory: registerTokensProviderFactory,
|
||||
setTokensProvider: setTokensProvider,
|
||||
setMonarchTokensProvider: setMonarchTokensProvider,
|
||||
registerReferenceProvider: registerReferenceProvider,
|
||||
registerRenameProvider: registerRenameProvider,
|
||||
registerCompletionItemProvider: registerCompletionItemProvider,
|
||||
registerSignatureHelpProvider: registerSignatureHelpProvider,
|
||||
registerHoverProvider: registerHoverProvider,
|
||||
registerDocumentSymbolProvider: registerDocumentSymbolProvider,
|
||||
registerDocumentHighlightProvider: registerDocumentHighlightProvider,
|
||||
registerLinkedEditingRangeProvider: registerLinkedEditingRangeProvider,
|
||||
registerDefinitionProvider: registerDefinitionProvider,
|
||||
registerImplementationProvider: registerImplementationProvider,
|
||||
registerTypeDefinitionProvider: registerTypeDefinitionProvider,
|
||||
registerCodeLensProvider: registerCodeLensProvider,
|
||||
registerCodeActionProvider: registerCodeActionProvider,
|
||||
registerDocumentFormattingEditProvider: registerDocumentFormattingEditProvider,
|
||||
registerDocumentRangeFormattingEditProvider: registerDocumentRangeFormattingEditProvider,
|
||||
registerOnTypeFormattingEditProvider: registerOnTypeFormattingEditProvider,
|
||||
registerLinkProvider: registerLinkProvider,
|
||||
registerColorProvider: registerColorProvider,
|
||||
registerFoldingRangeProvider: registerFoldingRangeProvider,
|
||||
registerDeclarationProvider: registerDeclarationProvider,
|
||||
registerSelectionRangeProvider: registerSelectionRangeProvider,
|
||||
registerDocumentSemanticTokensProvider: registerDocumentSemanticTokensProvider,
|
||||
registerDocumentRangeSemanticTokensProvider: registerDocumentRangeSemanticTokensProvider,
|
||||
registerInlineCompletionsProvider: registerInlineCompletionsProvider,
|
||||
registerInlayHintsProvider: registerInlayHintsProvider,
|
||||
// enums
|
||||
DocumentHighlightKind: standaloneEnums.DocumentHighlightKind,
|
||||
CompletionItemKind: standaloneEnums.CompletionItemKind,
|
||||
CompletionItemTag: standaloneEnums.CompletionItemTag,
|
||||
CompletionItemInsertTextRule: standaloneEnums.CompletionItemInsertTextRule,
|
||||
SymbolKind: standaloneEnums.SymbolKind,
|
||||
SymbolTag: standaloneEnums.SymbolTag,
|
||||
IndentAction: standaloneEnums.IndentAction,
|
||||
CompletionTriggerKind: standaloneEnums.CompletionTriggerKind,
|
||||
SignatureHelpTriggerKind: standaloneEnums.SignatureHelpTriggerKind,
|
||||
InlayHintKind: standaloneEnums.InlayHintKind,
|
||||
InlineCompletionTriggerKind: standaloneEnums.InlineCompletionTriggerKind,
|
||||
CodeActionTriggerType: standaloneEnums.CodeActionTriggerType,
|
||||
// classes
|
||||
FoldingRangeKind: languages.FoldingRangeKind,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
import * as dom from '../../../base/browser/dom.js';
|
||||
import { Event } from '../../../base/common/event.js';
|
||||
import { ILayoutService } from '../../../platform/layout/browser/layoutService.js';
|
||||
import { ICodeEditorService } from '../../browser/services/codeEditorService.js';
|
||||
import { registerSingleton } from '../../../platform/instantiation/common/extensions.js';
|
||||
let StandaloneLayoutService = class StandaloneLayoutService {
|
||||
constructor(_codeEditorService) {
|
||||
this._codeEditorService = _codeEditorService;
|
||||
this.onDidLayout = Event.None;
|
||||
this.offset = { top: 0, quickPickTop: 0 };
|
||||
}
|
||||
get dimension() {
|
||||
if (!this._dimension) {
|
||||
this._dimension = dom.getClientArea(window.document.body);
|
||||
}
|
||||
return this._dimension;
|
||||
}
|
||||
get hasContainer() {
|
||||
return false;
|
||||
}
|
||||
get container() {
|
||||
// On a page, multiple editors can be created. Therefore, there are multiple containers, not
|
||||
// just a single one. Please use `ICodeEditorService` to get the current focused code editor
|
||||
// and use its container if necessary. You can also instantiate `EditorScopedLayoutService`
|
||||
// which implements `ILayoutService` but is not a part of the service collection because
|
||||
// it is code editor instance specific.
|
||||
throw new Error(`ILayoutService.container is not available in the standalone editor!`);
|
||||
}
|
||||
focus() {
|
||||
var _a;
|
||||
(_a = this._codeEditorService.getFocusedCodeEditor()) === null || _a === void 0 ? void 0 : _a.focus();
|
||||
}
|
||||
};
|
||||
StandaloneLayoutService = __decorate([
|
||||
__param(0, ICodeEditorService)
|
||||
], StandaloneLayoutService);
|
||||
let EditorScopedLayoutService = class EditorScopedLayoutService extends StandaloneLayoutService {
|
||||
constructor(_container, codeEditorService) {
|
||||
super(codeEditorService);
|
||||
this._container = _container;
|
||||
}
|
||||
get hasContainer() {
|
||||
return false;
|
||||
}
|
||||
get container() {
|
||||
return this._container;
|
||||
}
|
||||
};
|
||||
EditorScopedLayoutService = __decorate([
|
||||
__param(1, ICodeEditorService)
|
||||
], EditorScopedLayoutService);
|
||||
export { EditorScopedLayoutService };
|
||||
registerSingleton(ILayoutService, StandaloneLayoutService);
|
||||
@@ -0,0 +1,685 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import '../../common/languages/languageConfigurationRegistry.js';
|
||||
import './standaloneCodeEditorService.js';
|
||||
import './standaloneLayoutService.js';
|
||||
import '../../../platform/undoRedo/common/undoRedoService.js';
|
||||
import '../../common/services/languageFeatureDebounce.js';
|
||||
import * as strings from '../../../base/common/strings.js';
|
||||
import * as dom from '../../../base/browser/dom.js';
|
||||
import { StandardKeyboardEvent } from '../../../base/browser/keyboardEvent.js';
|
||||
import { Emitter } from '../../../base/common/event.js';
|
||||
import { SimpleKeybinding, createKeybinding } from '../../../base/common/keybindings.js';
|
||||
import { ImmortalReference, toDisposable, DisposableStore, Disposable } from '../../../base/common/lifecycle.js';
|
||||
import { OS, isLinux, isMacintosh } from '../../../base/common/platform.js';
|
||||
import Severity from '../../../base/common/severity.js';
|
||||
import { URI } from '../../../base/common/uri.js';
|
||||
import { IBulkEditService, ResourceTextEdit } from '../../browser/services/bulkEditService.js';
|
||||
import { isDiffEditorConfigurationKey, isEditorConfigurationKey } from '../../common/config/editorConfigurationSchema.js';
|
||||
import { EditOperation } from '../../common/core/editOperation.js';
|
||||
import { Position as Pos } from '../../common/core/position.js';
|
||||
import { Range } from '../../common/core/range.js';
|
||||
import { IModelService } from '../../common/services/model.js';
|
||||
import { ITextModelService } from '../../common/services/resolverService.js';
|
||||
import { ITextResourceConfigurationService, ITextResourcePropertiesService } from '../../common/services/textResourceConfiguration.js';
|
||||
import { CommandsRegistry, ICommandService } from '../../../platform/commands/common/commands.js';
|
||||
import { IConfigurationService } from '../../../platform/configuration/common/configuration.js';
|
||||
import { Configuration, ConfigurationModel, ConfigurationChangeEvent } from '../../../platform/configuration/common/configurationModels.js';
|
||||
import { IContextKeyService } from '../../../platform/contextkey/common/contextkey.js';
|
||||
import { IDialogService } from '../../../platform/dialogs/common/dialogs.js';
|
||||
import { createDecorator, IInstantiationService } from '../../../platform/instantiation/common/instantiation.js';
|
||||
import { AbstractKeybindingService } from '../../../platform/keybinding/common/abstractKeybindingService.js';
|
||||
import { IKeybindingService } from '../../../platform/keybinding/common/keybinding.js';
|
||||
import { KeybindingResolver } from '../../../platform/keybinding/common/keybindingResolver.js';
|
||||
import { KeybindingsRegistry } from '../../../platform/keybinding/common/keybindingsRegistry.js';
|
||||
import { ResolvedKeybindingItem } from '../../../platform/keybinding/common/resolvedKeybindingItem.js';
|
||||
import { USLayoutResolvedKeybinding } from '../../../platform/keybinding/common/usLayoutResolvedKeybinding.js';
|
||||
import { ILabelService } from '../../../platform/label/common/label.js';
|
||||
import { INotificationService, NoOpNotification } from '../../../platform/notification/common/notification.js';
|
||||
import { IEditorProgressService, IProgressService } from '../../../platform/progress/common/progress.js';
|
||||
import { ITelemetryService } from '../../../platform/telemetry/common/telemetry.js';
|
||||
import { IWorkspaceContextService, WorkspaceFolder } from '../../../platform/workspace/common/workspace.js';
|
||||
import { ILayoutService } from '../../../platform/layout/browser/layoutService.js';
|
||||
import { StandaloneServicesNLS } from '../../common/standaloneStrings.js';
|
||||
import { basename } from '../../../base/common/resources.js';
|
||||
import { ICodeEditorService } from '../../browser/services/codeEditorService.js';
|
||||
import { ConsoleLogger, ILogService, LogService } from '../../../platform/log/common/log.js';
|
||||
import { IWorkspaceTrustManagementService } from '../../../platform/workspace/common/workspaceTrust.js';
|
||||
import { IContextMenuService, IContextViewService } from '../../../platform/contextview/browser/contextView.js';
|
||||
import { ContextViewService } from '../../../platform/contextview/browser/contextViewService.js';
|
||||
import { LanguageService } from '../../common/services/languageService.js';
|
||||
import { ContextMenuService } from '../../../platform/contextview/browser/contextMenuService.js';
|
||||
import { IThemeService } from '../../../platform/theme/common/themeService.js';
|
||||
import { getSingletonServiceDescriptors, registerSingleton } from '../../../platform/instantiation/common/extensions.js';
|
||||
import { OpenerService } from '../../browser/services/openerService.js';
|
||||
import { IEditorWorkerService } from '../../common/services/editorWorker.js';
|
||||
import { EditorWorkerService } from '../../browser/services/editorWorkerService.js';
|
||||
import { ILanguageService } from '../../common/languages/language.js';
|
||||
import { MarkerDecorationsService } from '../../common/services/markerDecorationsService.js';
|
||||
import { IMarkerDecorationsService } from '../../common/services/markerDecorations.js';
|
||||
import { ModelService } from '../../common/services/modelService.js';
|
||||
import { StandaloneQuickInputService } from './quickInput/standaloneQuickInputService.js';
|
||||
import { StandaloneThemeService } from './standaloneThemeService.js';
|
||||
import { IStandaloneThemeService } from '../common/standaloneTheme.js';
|
||||
import { AccessibilityService } from '../../../platform/accessibility/browser/accessibilityService.js';
|
||||
import { IAccessibilityService } from '../../../platform/accessibility/common/accessibility.js';
|
||||
import { IMenuService } from '../../../platform/actions/common/actions.js';
|
||||
import { MenuService } from '../../../platform/actions/common/menuService.js';
|
||||
import { BrowserClipboardService } from '../../../platform/clipboard/browser/clipboardService.js';
|
||||
import { IClipboardService } from '../../../platform/clipboard/common/clipboardService.js';
|
||||
import { ContextKeyService } from '../../../platform/contextkey/browser/contextKeyService.js';
|
||||
import { SyncDescriptor } from '../../../platform/instantiation/common/descriptors.js';
|
||||
import { InstantiationService } from '../../../platform/instantiation/common/instantiationService.js';
|
||||
import { ServiceCollection } from '../../../platform/instantiation/common/serviceCollection.js';
|
||||
import { IListService, ListService } from '../../../platform/list/browser/listService.js';
|
||||
import { IMarkerService } from '../../../platform/markers/common/markers.js';
|
||||
import { MarkerService } from '../../../platform/markers/common/markerService.js';
|
||||
import { IOpenerService } from '../../../platform/opener/common/opener.js';
|
||||
import { IQuickInputService } from '../../../platform/quickinput/common/quickInput.js';
|
||||
import { IStorageService, InMemoryStorageService } from '../../../platform/storage/common/storage.js';
|
||||
import '../../common/services/languageFeaturesService.js';
|
||||
import { DefaultConfigurationModel } from '../../../platform/configuration/common/configurations.js';
|
||||
class SimpleModel {
|
||||
constructor(model) {
|
||||
this.disposed = false;
|
||||
this.model = model;
|
||||
this._onWillDispose = new Emitter();
|
||||
}
|
||||
get textEditorModel() {
|
||||
return this.model;
|
||||
}
|
||||
dispose() {
|
||||
this.disposed = true;
|
||||
this._onWillDispose.fire();
|
||||
}
|
||||
}
|
||||
let StandaloneTextModelService = class StandaloneTextModelService {
|
||||
constructor(modelService) {
|
||||
this.modelService = modelService;
|
||||
}
|
||||
createModelReference(resource) {
|
||||
const model = this.modelService.getModel(resource);
|
||||
if (!model) {
|
||||
return Promise.reject(new Error(`Model not found`));
|
||||
}
|
||||
return Promise.resolve(new ImmortalReference(new SimpleModel(model)));
|
||||
}
|
||||
};
|
||||
StandaloneTextModelService = __decorate([
|
||||
__param(0, IModelService)
|
||||
], StandaloneTextModelService);
|
||||
class StandaloneEditorProgressService {
|
||||
show() {
|
||||
return StandaloneEditorProgressService.NULL_PROGRESS_RUNNER;
|
||||
}
|
||||
showWhile(promise, delay) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield promise;
|
||||
});
|
||||
}
|
||||
}
|
||||
StandaloneEditorProgressService.NULL_PROGRESS_RUNNER = {
|
||||
done: () => { },
|
||||
total: () => { },
|
||||
worked: () => { }
|
||||
};
|
||||
class StandaloneProgressService {
|
||||
withProgress(_options, task, onDidCancel) {
|
||||
return task({
|
||||
report: () => { },
|
||||
});
|
||||
}
|
||||
}
|
||||
class StandaloneDialogService {
|
||||
confirm(confirmation) {
|
||||
return this.doConfirm(confirmation).then(confirmed => {
|
||||
return {
|
||||
confirmed,
|
||||
checkboxChecked: false // unsupported
|
||||
};
|
||||
});
|
||||
}
|
||||
doConfirm(confirmation) {
|
||||
let messageText = confirmation.message;
|
||||
if (confirmation.detail) {
|
||||
messageText = messageText + '\n\n' + confirmation.detail;
|
||||
}
|
||||
return Promise.resolve(window.confirm(messageText));
|
||||
}
|
||||
show(severity, message, buttons, options) {
|
||||
return Promise.resolve({ choice: 0 });
|
||||
}
|
||||
}
|
||||
export class StandaloneNotificationService {
|
||||
info(message) {
|
||||
return this.notify({ severity: Severity.Info, message });
|
||||
}
|
||||
warn(message) {
|
||||
return this.notify({ severity: Severity.Warning, message });
|
||||
}
|
||||
error(error) {
|
||||
return this.notify({ severity: Severity.Error, message: error });
|
||||
}
|
||||
notify(notification) {
|
||||
switch (notification.severity) {
|
||||
case Severity.Error:
|
||||
console.error(notification.message);
|
||||
break;
|
||||
case Severity.Warning:
|
||||
console.warn(notification.message);
|
||||
break;
|
||||
default:
|
||||
console.log(notification.message);
|
||||
break;
|
||||
}
|
||||
return StandaloneNotificationService.NO_OP;
|
||||
}
|
||||
status(message, options) {
|
||||
return Disposable.None;
|
||||
}
|
||||
}
|
||||
StandaloneNotificationService.NO_OP = new NoOpNotification();
|
||||
let StandaloneCommandService = class StandaloneCommandService {
|
||||
constructor(instantiationService) {
|
||||
this._onWillExecuteCommand = new Emitter();
|
||||
this._onDidExecuteCommand = new Emitter();
|
||||
this.onWillExecuteCommand = this._onWillExecuteCommand.event;
|
||||
this.onDidExecuteCommand = this._onDidExecuteCommand.event;
|
||||
this._instantiationService = instantiationService;
|
||||
}
|
||||
executeCommand(id, ...args) {
|
||||
const command = CommandsRegistry.getCommand(id);
|
||||
if (!command) {
|
||||
return Promise.reject(new Error(`command '${id}' not found`));
|
||||
}
|
||||
try {
|
||||
this._onWillExecuteCommand.fire({ commandId: id, args });
|
||||
const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler, ...args]);
|
||||
this._onDidExecuteCommand.fire({ commandId: id, args });
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
catch (err) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
StandaloneCommandService = __decorate([
|
||||
__param(0, IInstantiationService)
|
||||
], StandaloneCommandService);
|
||||
export { StandaloneCommandService };
|
||||
let StandaloneKeybindingService = class StandaloneKeybindingService extends AbstractKeybindingService {
|
||||
constructor(contextKeyService, commandService, telemetryService, notificationService, logService, codeEditorService) {
|
||||
super(contextKeyService, commandService, telemetryService, notificationService, logService);
|
||||
this._cachedResolver = null;
|
||||
this._dynamicKeybindings = [];
|
||||
this._domNodeListeners = [];
|
||||
const addContainer = (domNode) => {
|
||||
const disposables = new DisposableStore();
|
||||
// for standard keybindings
|
||||
disposables.add(dom.addDisposableListener(domNode, dom.EventType.KEY_DOWN, (e) => {
|
||||
const keyEvent = new StandardKeyboardEvent(e);
|
||||
const shouldPreventDefault = this._dispatch(keyEvent, keyEvent.target);
|
||||
if (shouldPreventDefault) {
|
||||
keyEvent.preventDefault();
|
||||
keyEvent.stopPropagation();
|
||||
}
|
||||
}));
|
||||
// for single modifier chord keybindings (e.g. shift shift)
|
||||
disposables.add(dom.addDisposableListener(domNode, dom.EventType.KEY_UP, (e) => {
|
||||
const keyEvent = new StandardKeyboardEvent(e);
|
||||
const shouldPreventDefault = this._singleModifierDispatch(keyEvent, keyEvent.target);
|
||||
if (shouldPreventDefault) {
|
||||
keyEvent.preventDefault();
|
||||
}
|
||||
}));
|
||||
this._domNodeListeners.push(new DomNodeListeners(domNode, disposables));
|
||||
};
|
||||
const removeContainer = (domNode) => {
|
||||
for (let i = 0; i < this._domNodeListeners.length; i++) {
|
||||
const domNodeListeners = this._domNodeListeners[i];
|
||||
if (domNodeListeners.domNode === domNode) {
|
||||
this._domNodeListeners.splice(i, 1);
|
||||
domNodeListeners.dispose();
|
||||
}
|
||||
}
|
||||
};
|
||||
const addCodeEditor = (codeEditor) => {
|
||||
if (codeEditor.getOption(56 /* EditorOption.inDiffEditor */)) {
|
||||
return;
|
||||
}
|
||||
addContainer(codeEditor.getContainerDomNode());
|
||||
};
|
||||
const removeCodeEditor = (codeEditor) => {
|
||||
if (codeEditor.getOption(56 /* EditorOption.inDiffEditor */)) {
|
||||
return;
|
||||
}
|
||||
removeContainer(codeEditor.getContainerDomNode());
|
||||
};
|
||||
this._register(codeEditorService.onCodeEditorAdd(addCodeEditor));
|
||||
this._register(codeEditorService.onCodeEditorRemove(removeCodeEditor));
|
||||
codeEditorService.listCodeEditors().forEach(addCodeEditor);
|
||||
const addDiffEditor = (diffEditor) => {
|
||||
addContainer(diffEditor.getContainerDomNode());
|
||||
};
|
||||
const removeDiffEditor = (diffEditor) => {
|
||||
removeContainer(diffEditor.getContainerDomNode());
|
||||
};
|
||||
this._register(codeEditorService.onDiffEditorAdd(addDiffEditor));
|
||||
this._register(codeEditorService.onDiffEditorRemove(removeDiffEditor));
|
||||
codeEditorService.listDiffEditors().forEach(addDiffEditor);
|
||||
}
|
||||
addDynamicKeybinding(commandId, _keybinding, handler, when) {
|
||||
const keybinding = createKeybinding(_keybinding, OS);
|
||||
const toDispose = new DisposableStore();
|
||||
if (keybinding) {
|
||||
this._dynamicKeybindings.push({
|
||||
keybinding: keybinding.parts,
|
||||
command: commandId,
|
||||
when: when,
|
||||
weight1: 1000,
|
||||
weight2: 0,
|
||||
extensionId: null,
|
||||
isBuiltinExtension: false
|
||||
});
|
||||
toDispose.add(toDisposable(() => {
|
||||
for (let i = 0; i < this._dynamicKeybindings.length; i++) {
|
||||
const kb = this._dynamicKeybindings[i];
|
||||
if (kb.command === commandId) {
|
||||
this._dynamicKeybindings.splice(i, 1);
|
||||
this.updateResolver();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
toDispose.add(CommandsRegistry.registerCommand(commandId, handler));
|
||||
this.updateResolver();
|
||||
return toDispose;
|
||||
}
|
||||
updateResolver() {
|
||||
this._cachedResolver = null;
|
||||
this._onDidUpdateKeybindings.fire();
|
||||
}
|
||||
_getResolver() {
|
||||
if (!this._cachedResolver) {
|
||||
const defaults = this._toNormalizedKeybindingItems(KeybindingsRegistry.getDefaultKeybindings(), true);
|
||||
const overrides = this._toNormalizedKeybindingItems(this._dynamicKeybindings, false);
|
||||
this._cachedResolver = new KeybindingResolver(defaults, overrides, (str) => this._log(str));
|
||||
}
|
||||
return this._cachedResolver;
|
||||
}
|
||||
_documentHasFocus() {
|
||||
return document.hasFocus();
|
||||
}
|
||||
_toNormalizedKeybindingItems(items, isDefault) {
|
||||
const result = [];
|
||||
let resultLen = 0;
|
||||
for (const item of items) {
|
||||
const when = item.when || undefined;
|
||||
const keybinding = item.keybinding;
|
||||
if (!keybinding) {
|
||||
// This might be a removal keybinding item in user settings => accept it
|
||||
result[resultLen++] = new ResolvedKeybindingItem(undefined, item.command, item.commandArgs, when, isDefault, null, false);
|
||||
}
|
||||
else {
|
||||
const resolvedKeybindings = USLayoutResolvedKeybinding.resolveUserBinding(keybinding, OS);
|
||||
for (const resolvedKeybinding of resolvedKeybindings) {
|
||||
result[resultLen++] = new ResolvedKeybindingItem(resolvedKeybinding, item.command, item.commandArgs, when, isDefault, null, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
resolveKeyboardEvent(keyboardEvent) {
|
||||
const keybinding = new SimpleKeybinding(keyboardEvent.ctrlKey, keyboardEvent.shiftKey, keyboardEvent.altKey, keyboardEvent.metaKey, keyboardEvent.keyCode).toChord();
|
||||
return new USLayoutResolvedKeybinding(keybinding, OS);
|
||||
}
|
||||
};
|
||||
StandaloneKeybindingService = __decorate([
|
||||
__param(0, IContextKeyService),
|
||||
__param(1, ICommandService),
|
||||
__param(2, ITelemetryService),
|
||||
__param(3, INotificationService),
|
||||
__param(4, ILogService),
|
||||
__param(5, ICodeEditorService)
|
||||
], StandaloneKeybindingService);
|
||||
export { StandaloneKeybindingService };
|
||||
class DomNodeListeners extends Disposable {
|
||||
constructor(domNode, disposables) {
|
||||
super();
|
||||
this.domNode = domNode;
|
||||
this._register(disposables);
|
||||
}
|
||||
}
|
||||
function isConfigurationOverrides(thing) {
|
||||
return thing
|
||||
&& typeof thing === 'object'
|
||||
&& (!thing.overrideIdentifier || typeof thing.overrideIdentifier === 'string')
|
||||
&& (!thing.resource || thing.resource instanceof URI);
|
||||
}
|
||||
export class StandaloneConfigurationService {
|
||||
constructor() {
|
||||
this._onDidChangeConfiguration = new Emitter();
|
||||
this.onDidChangeConfiguration = this._onDidChangeConfiguration.event;
|
||||
this._configuration = new Configuration(new DefaultConfigurationModel(), new ConfigurationModel(), new ConfigurationModel(), new ConfigurationModel());
|
||||
}
|
||||
getValue(arg1, arg2) {
|
||||
const section = typeof arg1 === 'string' ? arg1 : undefined;
|
||||
const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {};
|
||||
return this._configuration.getValue(section, overrides, undefined);
|
||||
}
|
||||
updateValues(values) {
|
||||
const previous = { data: this._configuration.toData() };
|
||||
const changedKeys = [];
|
||||
for (const entry of values) {
|
||||
const [key, value] = entry;
|
||||
if (this.getValue(key) === value) {
|
||||
continue;
|
||||
}
|
||||
this._configuration.updateValue(key, value);
|
||||
changedKeys.push(key);
|
||||
}
|
||||
if (changedKeys.length > 0) {
|
||||
const configurationChangeEvent = new ConfigurationChangeEvent({ keys: changedKeys, overrides: [] }, previous, this._configuration);
|
||||
configurationChangeEvent.source = 8 /* ConfigurationTarget.MEMORY */;
|
||||
configurationChangeEvent.sourceConfig = null;
|
||||
this._onDidChangeConfiguration.fire(configurationChangeEvent);
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
updateValue(key, value, arg3, arg4) {
|
||||
return this.updateValues([[key, value]]);
|
||||
}
|
||||
inspect(key, options = {}) {
|
||||
return this._configuration.inspect(key, options, undefined);
|
||||
}
|
||||
}
|
||||
let StandaloneResourceConfigurationService = class StandaloneResourceConfigurationService {
|
||||
constructor(configurationService) {
|
||||
this.configurationService = configurationService;
|
||||
this._onDidChangeConfiguration = new Emitter();
|
||||
this.configurationService.onDidChangeConfiguration((e) => {
|
||||
this._onDidChangeConfiguration.fire({ affectedKeys: e.affectedKeys, affectsConfiguration: (resource, configuration) => e.affectsConfiguration(configuration) });
|
||||
});
|
||||
}
|
||||
getValue(resource, arg2, arg3) {
|
||||
const position = Pos.isIPosition(arg2) ? arg2 : null;
|
||||
const section = position ? (typeof arg3 === 'string' ? arg3 : undefined) : (typeof arg2 === 'string' ? arg2 : undefined);
|
||||
if (typeof section === 'undefined') {
|
||||
return this.configurationService.getValue();
|
||||
}
|
||||
return this.configurationService.getValue(section);
|
||||
}
|
||||
};
|
||||
StandaloneResourceConfigurationService = __decorate([
|
||||
__param(0, IConfigurationService)
|
||||
], StandaloneResourceConfigurationService);
|
||||
let StandaloneResourcePropertiesService = class StandaloneResourcePropertiesService {
|
||||
constructor(configurationService) {
|
||||
this.configurationService = configurationService;
|
||||
}
|
||||
getEOL(resource, language) {
|
||||
const eol = this.configurationService.getValue('files.eol', { overrideIdentifier: language, resource });
|
||||
if (eol && typeof eol === 'string' && eol !== 'auto') {
|
||||
return eol;
|
||||
}
|
||||
return (isLinux || isMacintosh) ? '\n' : '\r\n';
|
||||
}
|
||||
};
|
||||
StandaloneResourcePropertiesService = __decorate([
|
||||
__param(0, IConfigurationService)
|
||||
], StandaloneResourcePropertiesService);
|
||||
class StandaloneTelemetryService {
|
||||
publicLog(eventName, data) {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
publicLog2(eventName, data) {
|
||||
return this.publicLog(eventName, data);
|
||||
}
|
||||
}
|
||||
class StandaloneWorkspaceContextService {
|
||||
constructor() {
|
||||
const resource = URI.from({ scheme: StandaloneWorkspaceContextService.SCHEME, authority: 'model', path: '/' });
|
||||
this.workspace = { id: '4064f6ec-cb38-4ad0-af64-ee6467e63c82', folders: [new WorkspaceFolder({ uri: resource, name: '', index: 0 })] };
|
||||
}
|
||||
getWorkspace() {
|
||||
return this.workspace;
|
||||
}
|
||||
getWorkspaceFolder(resource) {
|
||||
return resource && resource.scheme === StandaloneWorkspaceContextService.SCHEME ? this.workspace.folders[0] : null;
|
||||
}
|
||||
}
|
||||
StandaloneWorkspaceContextService.SCHEME = 'inmemory';
|
||||
export function updateConfigurationService(configurationService, source, isDiffEditor) {
|
||||
if (!source) {
|
||||
return;
|
||||
}
|
||||
if (!(configurationService instanceof StandaloneConfigurationService)) {
|
||||
return;
|
||||
}
|
||||
const toUpdate = [];
|
||||
Object.keys(source).forEach((key) => {
|
||||
if (isEditorConfigurationKey(key)) {
|
||||
toUpdate.push([`editor.${key}`, source[key]]);
|
||||
}
|
||||
if (isDiffEditor && isDiffEditorConfigurationKey(key)) {
|
||||
toUpdate.push([`diffEditor.${key}`, source[key]]);
|
||||
}
|
||||
});
|
||||
if (toUpdate.length > 0) {
|
||||
configurationService.updateValues(toUpdate);
|
||||
}
|
||||
}
|
||||
let StandaloneBulkEditService = class StandaloneBulkEditService {
|
||||
constructor(_modelService) {
|
||||
this._modelService = _modelService;
|
||||
//
|
||||
}
|
||||
hasPreviewHandler() {
|
||||
return false;
|
||||
}
|
||||
apply(edits, _options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const textEdits = new Map();
|
||||
for (const edit of edits) {
|
||||
if (!(edit instanceof ResourceTextEdit)) {
|
||||
throw new Error('bad edit - only text edits are supported');
|
||||
}
|
||||
const model = this._modelService.getModel(edit.resource);
|
||||
if (!model) {
|
||||
throw new Error('bad edit - model not found');
|
||||
}
|
||||
if (typeof edit.versionId === 'number' && model.getVersionId() !== edit.versionId) {
|
||||
throw new Error('bad state - model changed in the meantime');
|
||||
}
|
||||
let array = textEdits.get(model);
|
||||
if (!array) {
|
||||
array = [];
|
||||
textEdits.set(model, array);
|
||||
}
|
||||
array.push(EditOperation.replaceMove(Range.lift(edit.textEdit.range), edit.textEdit.text));
|
||||
}
|
||||
let totalEdits = 0;
|
||||
let totalFiles = 0;
|
||||
for (const [model, edits] of textEdits) {
|
||||
model.pushStackElement();
|
||||
model.pushEditOperations([], edits, () => []);
|
||||
model.pushStackElement();
|
||||
totalFiles += 1;
|
||||
totalEdits += edits.length;
|
||||
}
|
||||
return {
|
||||
ariaSummary: strings.format(StandaloneServicesNLS.bulkEditServiceSummary, totalEdits, totalFiles)
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
StandaloneBulkEditService = __decorate([
|
||||
__param(0, IModelService)
|
||||
], StandaloneBulkEditService);
|
||||
class StandaloneUriLabelService {
|
||||
getUriLabel(resource, options) {
|
||||
if (resource.scheme === 'file') {
|
||||
return resource.fsPath;
|
||||
}
|
||||
return resource.path;
|
||||
}
|
||||
getUriBasenameLabel(resource) {
|
||||
return basename(resource);
|
||||
}
|
||||
}
|
||||
let StandaloneContextViewService = class StandaloneContextViewService extends ContextViewService {
|
||||
constructor(layoutService, _codeEditorService) {
|
||||
super(layoutService);
|
||||
this._codeEditorService = _codeEditorService;
|
||||
}
|
||||
showContextView(delegate, container, shadowRoot) {
|
||||
if (!container) {
|
||||
const codeEditor = this._codeEditorService.getFocusedCodeEditor() || this._codeEditorService.getActiveCodeEditor();
|
||||
if (codeEditor) {
|
||||
container = codeEditor.getContainerDomNode();
|
||||
}
|
||||
}
|
||||
return super.showContextView(delegate, container, shadowRoot);
|
||||
}
|
||||
};
|
||||
StandaloneContextViewService = __decorate([
|
||||
__param(0, ILayoutService),
|
||||
__param(1, ICodeEditorService)
|
||||
], StandaloneContextViewService);
|
||||
class StandaloneWorkspaceTrustManagementService {
|
||||
constructor() {
|
||||
this._neverEmitter = new Emitter();
|
||||
this.onDidChangeTrust = this._neverEmitter.event;
|
||||
}
|
||||
isWorkspaceTrusted() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class StandaloneLanguageService extends LanguageService {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
class StandaloneLogService extends LogService {
|
||||
constructor() {
|
||||
super(new ConsoleLogger());
|
||||
}
|
||||
}
|
||||
let StandaloneContextMenuService = class StandaloneContextMenuService extends ContextMenuService {
|
||||
constructor(telemetryService, notificationService, contextViewService, keybindingService, themeService) {
|
||||
super(telemetryService, notificationService, contextViewService, keybindingService, themeService);
|
||||
this.configure({ blockMouse: false }); // we do not want that in the standalone editor
|
||||
}
|
||||
};
|
||||
StandaloneContextMenuService = __decorate([
|
||||
__param(0, ITelemetryService),
|
||||
__param(1, INotificationService),
|
||||
__param(2, IContextViewService),
|
||||
__param(3, IKeybindingService),
|
||||
__param(4, IThemeService)
|
||||
], StandaloneContextMenuService);
|
||||
registerSingleton(IConfigurationService, StandaloneConfigurationService);
|
||||
registerSingleton(ITextResourceConfigurationService, StandaloneResourceConfigurationService);
|
||||
registerSingleton(ITextResourcePropertiesService, StandaloneResourcePropertiesService);
|
||||
registerSingleton(IWorkspaceContextService, StandaloneWorkspaceContextService);
|
||||
registerSingleton(ILabelService, StandaloneUriLabelService);
|
||||
registerSingleton(ITelemetryService, StandaloneTelemetryService);
|
||||
registerSingleton(IDialogService, StandaloneDialogService);
|
||||
registerSingleton(INotificationService, StandaloneNotificationService);
|
||||
registerSingleton(IMarkerService, MarkerService);
|
||||
registerSingleton(ILanguageService, StandaloneLanguageService);
|
||||
registerSingleton(IStandaloneThemeService, StandaloneThemeService);
|
||||
registerSingleton(ILogService, StandaloneLogService);
|
||||
registerSingleton(IModelService, ModelService);
|
||||
registerSingleton(IMarkerDecorationsService, MarkerDecorationsService);
|
||||
registerSingleton(IContextKeyService, ContextKeyService);
|
||||
registerSingleton(IProgressService, StandaloneProgressService);
|
||||
registerSingleton(IEditorProgressService, StandaloneEditorProgressService);
|
||||
registerSingleton(IStorageService, InMemoryStorageService);
|
||||
registerSingleton(IEditorWorkerService, EditorWorkerService);
|
||||
registerSingleton(IBulkEditService, StandaloneBulkEditService);
|
||||
registerSingleton(IWorkspaceTrustManagementService, StandaloneWorkspaceTrustManagementService);
|
||||
registerSingleton(ITextModelService, StandaloneTextModelService);
|
||||
registerSingleton(IAccessibilityService, AccessibilityService);
|
||||
registerSingleton(IListService, ListService);
|
||||
registerSingleton(ICommandService, StandaloneCommandService);
|
||||
registerSingleton(IKeybindingService, StandaloneKeybindingService);
|
||||
registerSingleton(IQuickInputService, StandaloneQuickInputService);
|
||||
registerSingleton(IContextViewService, StandaloneContextViewService);
|
||||
registerSingleton(IOpenerService, OpenerService);
|
||||
registerSingleton(IClipboardService, BrowserClipboardService);
|
||||
registerSingleton(IContextMenuService, StandaloneContextMenuService);
|
||||
registerSingleton(IMenuService, MenuService);
|
||||
/**
|
||||
* We don't want to eagerly instantiate services because embedders get a one time chance
|
||||
* to override services when they create the first editor.
|
||||
*/
|
||||
export var StandaloneServices;
|
||||
(function (StandaloneServices) {
|
||||
const serviceCollection = new ServiceCollection();
|
||||
for (const [id, descriptor] of getSingletonServiceDescriptors()) {
|
||||
serviceCollection.set(id, descriptor);
|
||||
}
|
||||
const instantiationService = new InstantiationService(serviceCollection, true);
|
||||
serviceCollection.set(IInstantiationService, instantiationService);
|
||||
function get(serviceId) {
|
||||
const r = serviceCollection.get(serviceId);
|
||||
if (!r) {
|
||||
throw new Error('Missing service ' + serviceId);
|
||||
}
|
||||
if (r instanceof SyncDescriptor) {
|
||||
return instantiationService.invokeFunction((accessor) => accessor.get(serviceId));
|
||||
}
|
||||
else {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
StandaloneServices.get = get;
|
||||
let initialized = false;
|
||||
function initialize(overrides) {
|
||||
if (initialized) {
|
||||
return instantiationService;
|
||||
}
|
||||
initialized = true;
|
||||
// Add singletons that were registered after this module loaded
|
||||
for (const [id, descriptor] of getSingletonServiceDescriptors()) {
|
||||
if (!serviceCollection.get(id)) {
|
||||
serviceCollection.set(id, descriptor);
|
||||
}
|
||||
}
|
||||
// Initialize the service collection with the overrides, but only if the
|
||||
// service was not instantiated in the meantime.
|
||||
for (const serviceId in overrides) {
|
||||
if (overrides.hasOwnProperty(serviceId)) {
|
||||
const serviceIdentifier = createDecorator(serviceId);
|
||||
const r = serviceCollection.get(serviceIdentifier);
|
||||
if (r instanceof SyncDescriptor) {
|
||||
serviceCollection.set(serviceIdentifier, overrides[serviceId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return instantiationService;
|
||||
}
|
||||
StandaloneServices.initialize = initialize;
|
||||
})(StandaloneServices || (StandaloneServices = {}));
|
||||
@@ -0,0 +1,342 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as dom from '../../../base/browser/dom.js';
|
||||
import { addMatchMediaChangeListener } from '../../../base/browser/browser.js';
|
||||
import { Color } from '../../../base/common/color.js';
|
||||
import { Emitter } from '../../../base/common/event.js';
|
||||
import { TokenizationRegistry } from '../../common/languages.js';
|
||||
import { TokenMetadata } from '../../common/encodedTokenAttributes.js';
|
||||
import { TokenTheme, generateTokensCSSForColorMap } from '../../common/languages/supports/tokenization.js';
|
||||
import { hc_black, hc_light, vs, vs_dark } from '../common/themes.js';
|
||||
import { Registry } from '../../../platform/registry/common/platform.js';
|
||||
import { asCssVariableName, Extensions } from '../../../platform/theme/common/colorRegistry.js';
|
||||
import { Extensions as ThemingExtensions } from '../../../platform/theme/common/themeService.js';
|
||||
import { Disposable } from '../../../base/common/lifecycle.js';
|
||||
import { ColorScheme, isDark, isHighContrast } from '../../../platform/theme/common/theme.js';
|
||||
import { getIconsStyleSheet, UnthemedProductIconTheme } from '../../../platform/theme/browser/iconsStyleSheet.js';
|
||||
export const VS_LIGHT_THEME_NAME = 'vs';
|
||||
export const VS_DARK_THEME_NAME = 'vs-dark';
|
||||
export const HC_BLACK_THEME_NAME = 'hc-black';
|
||||
export const HC_LIGHT_THEME_NAME = 'hc-light';
|
||||
const colorRegistry = Registry.as(Extensions.ColorContribution);
|
||||
const themingRegistry = Registry.as(ThemingExtensions.ThemingContribution);
|
||||
class StandaloneTheme {
|
||||
constructor(name, standaloneThemeData) {
|
||||
this.semanticHighlighting = false;
|
||||
this.themeData = standaloneThemeData;
|
||||
const base = standaloneThemeData.base;
|
||||
if (name.length > 0) {
|
||||
if (isBuiltinTheme(name)) {
|
||||
this.id = name;
|
||||
}
|
||||
else {
|
||||
this.id = base + ' ' + name;
|
||||
}
|
||||
this.themeName = name;
|
||||
}
|
||||
else {
|
||||
this.id = base;
|
||||
this.themeName = base;
|
||||
}
|
||||
this.colors = null;
|
||||
this.defaultColors = Object.create(null);
|
||||
this._tokenTheme = null;
|
||||
}
|
||||
get base() {
|
||||
return this.themeData.base;
|
||||
}
|
||||
notifyBaseUpdated() {
|
||||
if (this.themeData.inherit) {
|
||||
this.colors = null;
|
||||
this._tokenTheme = null;
|
||||
}
|
||||
}
|
||||
getColors() {
|
||||
if (!this.colors) {
|
||||
const colors = new Map();
|
||||
for (const id in this.themeData.colors) {
|
||||
colors.set(id, Color.fromHex(this.themeData.colors[id]));
|
||||
}
|
||||
if (this.themeData.inherit) {
|
||||
const baseData = getBuiltinRules(this.themeData.base);
|
||||
for (const id in baseData.colors) {
|
||||
if (!colors.has(id)) {
|
||||
colors.set(id, Color.fromHex(baseData.colors[id]));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.colors = colors;
|
||||
}
|
||||
return this.colors;
|
||||
}
|
||||
getColor(colorId, useDefault) {
|
||||
const color = this.getColors().get(colorId);
|
||||
if (color) {
|
||||
return color;
|
||||
}
|
||||
if (useDefault !== false) {
|
||||
return this.getDefault(colorId);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
getDefault(colorId) {
|
||||
let color = this.defaultColors[colorId];
|
||||
if (color) {
|
||||
return color;
|
||||
}
|
||||
color = colorRegistry.resolveDefaultColor(colorId, this);
|
||||
this.defaultColors[colorId] = color;
|
||||
return color;
|
||||
}
|
||||
defines(colorId) {
|
||||
return Object.prototype.hasOwnProperty.call(this.getColors(), colorId);
|
||||
}
|
||||
get type() {
|
||||
switch (this.base) {
|
||||
case VS_LIGHT_THEME_NAME: return ColorScheme.LIGHT;
|
||||
case HC_BLACK_THEME_NAME: return ColorScheme.HIGH_CONTRAST_DARK;
|
||||
case HC_LIGHT_THEME_NAME: return ColorScheme.HIGH_CONTRAST_LIGHT;
|
||||
default: return ColorScheme.DARK;
|
||||
}
|
||||
}
|
||||
get tokenTheme() {
|
||||
if (!this._tokenTheme) {
|
||||
let rules = [];
|
||||
let encodedTokensColors = [];
|
||||
if (this.themeData.inherit) {
|
||||
const baseData = getBuiltinRules(this.themeData.base);
|
||||
rules = baseData.rules;
|
||||
if (baseData.encodedTokensColors) {
|
||||
encodedTokensColors = baseData.encodedTokensColors;
|
||||
}
|
||||
}
|
||||
// Pick up default colors from `editor.foreground` and `editor.background` if available
|
||||
const editorForeground = this.themeData.colors['editor.foreground'];
|
||||
const editorBackground = this.themeData.colors['editor.background'];
|
||||
if (editorForeground || editorBackground) {
|
||||
const rule = { token: '' };
|
||||
if (editorForeground) {
|
||||
rule.foreground = editorForeground;
|
||||
}
|
||||
if (editorBackground) {
|
||||
rule.background = editorBackground;
|
||||
}
|
||||
rules.push(rule);
|
||||
}
|
||||
rules = rules.concat(this.themeData.rules);
|
||||
if (this.themeData.encodedTokensColors) {
|
||||
encodedTokensColors = this.themeData.encodedTokensColors;
|
||||
}
|
||||
this._tokenTheme = TokenTheme.createFromRawTokenTheme(rules, encodedTokensColors);
|
||||
}
|
||||
return this._tokenTheme;
|
||||
}
|
||||
getTokenStyleMetadata(type, modifiers, modelLanguage) {
|
||||
// use theme rules match
|
||||
const style = this.tokenTheme._match([type].concat(modifiers).join('.'));
|
||||
const metadata = style.metadata;
|
||||
const foreground = TokenMetadata.getForeground(metadata);
|
||||
const fontStyle = TokenMetadata.getFontStyle(metadata);
|
||||
return {
|
||||
foreground: foreground,
|
||||
italic: Boolean(fontStyle & 1 /* FontStyle.Italic */),
|
||||
bold: Boolean(fontStyle & 2 /* FontStyle.Bold */),
|
||||
underline: Boolean(fontStyle & 4 /* FontStyle.Underline */),
|
||||
strikethrough: Boolean(fontStyle & 8 /* FontStyle.Strikethrough */)
|
||||
};
|
||||
}
|
||||
}
|
||||
function isBuiltinTheme(themeName) {
|
||||
return (themeName === VS_LIGHT_THEME_NAME
|
||||
|| themeName === VS_DARK_THEME_NAME
|
||||
|| themeName === HC_BLACK_THEME_NAME
|
||||
|| themeName === HC_LIGHT_THEME_NAME);
|
||||
}
|
||||
function getBuiltinRules(builtinTheme) {
|
||||
switch (builtinTheme) {
|
||||
case VS_LIGHT_THEME_NAME:
|
||||
return vs;
|
||||
case VS_DARK_THEME_NAME:
|
||||
return vs_dark;
|
||||
case HC_BLACK_THEME_NAME:
|
||||
return hc_black;
|
||||
case HC_LIGHT_THEME_NAME:
|
||||
return hc_light;
|
||||
}
|
||||
}
|
||||
function newBuiltInTheme(builtinTheme) {
|
||||
const themeData = getBuiltinRules(builtinTheme);
|
||||
return new StandaloneTheme(builtinTheme, themeData);
|
||||
}
|
||||
export class StandaloneThemeService extends Disposable {
|
||||
constructor() {
|
||||
super();
|
||||
this._onColorThemeChange = this._register(new Emitter());
|
||||
this.onDidColorThemeChange = this._onColorThemeChange.event;
|
||||
this._onProductIconThemeChange = this._register(new Emitter());
|
||||
this.onDidProductIconThemeChange = this._onProductIconThemeChange.event;
|
||||
this._environment = Object.create(null);
|
||||
this._builtInProductIconTheme = new UnthemedProductIconTheme();
|
||||
this._autoDetectHighContrast = true;
|
||||
this._knownThemes = new Map();
|
||||
this._knownThemes.set(VS_LIGHT_THEME_NAME, newBuiltInTheme(VS_LIGHT_THEME_NAME));
|
||||
this._knownThemes.set(VS_DARK_THEME_NAME, newBuiltInTheme(VS_DARK_THEME_NAME));
|
||||
this._knownThemes.set(HC_BLACK_THEME_NAME, newBuiltInTheme(HC_BLACK_THEME_NAME));
|
||||
this._knownThemes.set(HC_LIGHT_THEME_NAME, newBuiltInTheme(HC_LIGHT_THEME_NAME));
|
||||
const iconsStyleSheet = getIconsStyleSheet(this);
|
||||
this._codiconCSS = iconsStyleSheet.getCSS();
|
||||
this._themeCSS = '';
|
||||
this._allCSS = `${this._codiconCSS}\n${this._themeCSS}`;
|
||||
this._globalStyleElement = null;
|
||||
this._styleElements = [];
|
||||
this._colorMapOverride = null;
|
||||
this.setTheme(VS_LIGHT_THEME_NAME);
|
||||
this._onOSSchemeChanged();
|
||||
iconsStyleSheet.onDidChange(() => {
|
||||
this._codiconCSS = iconsStyleSheet.getCSS();
|
||||
this._updateCSS();
|
||||
});
|
||||
addMatchMediaChangeListener('(forced-colors: active)', () => {
|
||||
this._onOSSchemeChanged();
|
||||
});
|
||||
}
|
||||
registerEditorContainer(domNode) {
|
||||
if (dom.isInShadowDOM(domNode)) {
|
||||
return this._registerShadowDomContainer(domNode);
|
||||
}
|
||||
return this._registerRegularEditorContainer();
|
||||
}
|
||||
_registerRegularEditorContainer() {
|
||||
if (!this._globalStyleElement) {
|
||||
this._globalStyleElement = dom.createStyleSheet();
|
||||
this._globalStyleElement.className = 'monaco-colors';
|
||||
this._globalStyleElement.textContent = this._allCSS;
|
||||
this._styleElements.push(this._globalStyleElement);
|
||||
}
|
||||
return Disposable.None;
|
||||
}
|
||||
_registerShadowDomContainer(domNode) {
|
||||
const styleElement = dom.createStyleSheet(domNode);
|
||||
styleElement.className = 'monaco-colors';
|
||||
styleElement.textContent = this._allCSS;
|
||||
this._styleElements.push(styleElement);
|
||||
return {
|
||||
dispose: () => {
|
||||
for (let i = 0; i < this._styleElements.length; i++) {
|
||||
if (this._styleElements[i] === styleElement) {
|
||||
this._styleElements.splice(i, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
defineTheme(themeName, themeData) {
|
||||
if (!/^[a-z0-9\-]+$/i.test(themeName)) {
|
||||
throw new Error('Illegal theme name!');
|
||||
}
|
||||
if (!isBuiltinTheme(themeData.base) && !isBuiltinTheme(themeName)) {
|
||||
throw new Error('Illegal theme base!');
|
||||
}
|
||||
// set or replace theme
|
||||
this._knownThemes.set(themeName, new StandaloneTheme(themeName, themeData));
|
||||
if (isBuiltinTheme(themeName)) {
|
||||
this._knownThemes.forEach(theme => {
|
||||
if (theme.base === themeName) {
|
||||
theme.notifyBaseUpdated();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (this._theme.themeName === themeName) {
|
||||
this.setTheme(themeName); // refresh theme
|
||||
}
|
||||
}
|
||||
getColorTheme() {
|
||||
return this._theme;
|
||||
}
|
||||
setColorMapOverride(colorMapOverride) {
|
||||
this._colorMapOverride = colorMapOverride;
|
||||
this._updateThemeOrColorMap();
|
||||
}
|
||||
setTheme(themeName) {
|
||||
let theme;
|
||||
if (this._knownThemes.has(themeName)) {
|
||||
theme = this._knownThemes.get(themeName);
|
||||
}
|
||||
else {
|
||||
theme = this._knownThemes.get(VS_LIGHT_THEME_NAME);
|
||||
}
|
||||
this._updateActualTheme(theme);
|
||||
}
|
||||
_updateActualTheme(desiredTheme) {
|
||||
if (!desiredTheme || this._theme === desiredTheme) {
|
||||
// Nothing to do
|
||||
return;
|
||||
}
|
||||
this._theme = desiredTheme;
|
||||
this._updateThemeOrColorMap();
|
||||
}
|
||||
_onOSSchemeChanged() {
|
||||
if (this._autoDetectHighContrast) {
|
||||
const wantsHighContrast = window.matchMedia(`(forced-colors: active)`).matches;
|
||||
if (wantsHighContrast !== isHighContrast(this._theme.type)) {
|
||||
// switch to high contrast or non-high contrast but stick to dark or light
|
||||
let newThemeName;
|
||||
if (isDark(this._theme.type)) {
|
||||
newThemeName = wantsHighContrast ? HC_BLACK_THEME_NAME : VS_DARK_THEME_NAME;
|
||||
}
|
||||
else {
|
||||
newThemeName = wantsHighContrast ? HC_LIGHT_THEME_NAME : VS_LIGHT_THEME_NAME;
|
||||
}
|
||||
this._updateActualTheme(this._knownThemes.get(newThemeName));
|
||||
}
|
||||
}
|
||||
}
|
||||
setAutoDetectHighContrast(autoDetectHighContrast) {
|
||||
this._autoDetectHighContrast = autoDetectHighContrast;
|
||||
this._onOSSchemeChanged();
|
||||
}
|
||||
_updateThemeOrColorMap() {
|
||||
const cssRules = [];
|
||||
const hasRule = {};
|
||||
const ruleCollector = {
|
||||
addRule: (rule) => {
|
||||
if (!hasRule[rule]) {
|
||||
cssRules.push(rule);
|
||||
hasRule[rule] = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
themingRegistry.getThemingParticipants().forEach(p => p(this._theme, ruleCollector, this._environment));
|
||||
const colorVariables = [];
|
||||
for (const item of colorRegistry.getColors()) {
|
||||
const color = this._theme.getColor(item.id, true);
|
||||
if (color) {
|
||||
colorVariables.push(`${asCssVariableName(item.id)}: ${color.toString()};`);
|
||||
}
|
||||
}
|
||||
ruleCollector.addRule(`.monaco-editor { ${colorVariables.join('\n')} }`);
|
||||
const colorMap = this._colorMapOverride || this._theme.tokenTheme.getColorMap();
|
||||
ruleCollector.addRule(generateTokensCSSForColorMap(colorMap));
|
||||
this._themeCSS = cssRules.join('\n');
|
||||
this._updateCSS();
|
||||
TokenizationRegistry.setColorMap(colorMap);
|
||||
this._onColorThemeChange.fire(this._theme);
|
||||
}
|
||||
_updateCSS() {
|
||||
this._allCSS = `${this._codiconCSS}\n${this._themeCSS}`;
|
||||
this._styleElements.forEach(styleElement => styleElement.textContent = this._allCSS);
|
||||
}
|
||||
getFileIconTheme() {
|
||||
return {
|
||||
hasFileIcons: false,
|
||||
hasFolderIcons: false,
|
||||
hidesExplorerArrows: false
|
||||
};
|
||||
}
|
||||
getProductIconTheme() {
|
||||
return this._builtInProductIconTheme;
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { EditorAction, registerEditorAction } from '../../../browser/editorExtensions.js';
|
||||
import { IStandaloneThemeService } from '../../common/standaloneTheme.js';
|
||||
import { ToggleHighContrastNLS } from '../../../common/standaloneStrings.js';
|
||||
import { isDark, isHighContrast } from '../../../../platform/theme/common/theme.js';
|
||||
import { HC_BLACK_THEME_NAME, HC_LIGHT_THEME_NAME, VS_DARK_THEME_NAME, VS_LIGHT_THEME_NAME } from '../standaloneThemeService.js';
|
||||
class ToggleHighContrast extends EditorAction {
|
||||
constructor() {
|
||||
super({
|
||||
id: 'editor.action.toggleHighContrast',
|
||||
label: ToggleHighContrastNLS.toggleHighContrast,
|
||||
alias: 'Toggle High Contrast Theme',
|
||||
precondition: undefined
|
||||
});
|
||||
this._originalThemeName = null;
|
||||
}
|
||||
run(accessor, editor) {
|
||||
const standaloneThemeService = accessor.get(IStandaloneThemeService);
|
||||
const currentTheme = standaloneThemeService.getColorTheme();
|
||||
if (isHighContrast(currentTheme.type)) {
|
||||
// We must toggle back to the integrator's theme
|
||||
standaloneThemeService.setTheme(this._originalThemeName || (isDark(currentTheme.type) ? VS_DARK_THEME_NAME : VS_LIGHT_THEME_NAME));
|
||||
this._originalThemeName = null;
|
||||
}
|
||||
else {
|
||||
standaloneThemeService.setTheme(isDark(currentTheme.type) ? HC_BLACK_THEME_NAME : HC_LIGHT_THEME_NAME);
|
||||
this._originalThemeName = currentTheme.themeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
registerEditorAction(ToggleHighContrast);
|
||||
Reference in New Issue
Block a user