mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-31 01:25:38 -05:00
Merge from vscode a5cf1da01d5db3d2557132be8d30f89c38019f6c (#8525)
* Merge from vscode a5cf1da01d5db3d2557132be8d30f89c38019f6c * remove files we don't want * fix hygiene * update distro * update distro * fix hygiene * fix strict nulls * distro * distro * fix tests * fix tests * add another edit * fix viewlet icon * fix azure dialog * fix some padding * fix more padding issues
This commit is contained in:
@@ -18,6 +18,8 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { ICodeLensCache } from 'vs/editor/contrib/codelens/codeLensCache';
|
||||
import { EditorOption } from 'vs/editor/common/config/editorOptions';
|
||||
import { createStyleSheet } from 'vs/base/browser/dom';
|
||||
import { hash } from 'vs/base/common/hash';
|
||||
|
||||
export class CodeLensContribution implements editorCommon.IEditorContribution {
|
||||
|
||||
@@ -27,6 +29,8 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
|
||||
|
||||
private readonly _globalToDispose = new DisposableStore();
|
||||
private readonly _localToDispose = new DisposableStore();
|
||||
private readonly _styleElement: HTMLStyleElement;
|
||||
private readonly _styleClassName: string;
|
||||
private _lenses: CodeLensWidget[] = [];
|
||||
private _currentFindCodeLensSymbolsPromise: CancelablePromise<CodeLensModel> | undefined;
|
||||
private _oldCodeLensModels = new DisposableStore();
|
||||
@@ -53,7 +57,16 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
|
||||
}
|
||||
}));
|
||||
this._globalToDispose.add(CodeLensProviderRegistry.onDidChange(this._onModelChange, this));
|
||||
this._globalToDispose.add(this._editor.onDidChangeConfiguration(e => {
|
||||
if (e.hasChanged(EditorOption.fontInfo)) {
|
||||
this._updateLensStyle();
|
||||
}
|
||||
}));
|
||||
this._onModelChange();
|
||||
|
||||
this._styleClassName = hash(this._editor.getId()).toString(16);
|
||||
this._styleElement = createStyleSheet();
|
||||
this._updateLensStyle();
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
@@ -63,6 +76,15 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
|
||||
dispose(this._currentCodeLensModel);
|
||||
}
|
||||
|
||||
private _updateLensStyle(): void {
|
||||
const options = this._editor.getOptions();
|
||||
const fontInfo = options.get(EditorOption.fontInfo);
|
||||
const lineHeight = options.get(EditorOption.lineHeight);
|
||||
|
||||
const newStyle = `.monaco-editor .codelens-decoration.${this._styleClassName} { height: ${Math.round(lineHeight * 1.1)}px; line-height: ${lineHeight}px; font-size: ${Math.round(fontInfo.fontSize * 0.9)}px; padding-right: ${Math.round(fontInfo.fontSize * 0.45)}px;}`;
|
||||
this._styleElement.innerHTML = newStyle;
|
||||
}
|
||||
|
||||
private _localDispose(): void {
|
||||
if (this._currentFindCodeLensSymbolsPromise) {
|
||||
this._currentFindCodeLensSymbolsPromise.cancel();
|
||||
@@ -200,17 +222,17 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
|
||||
this._disposeAllLenses(undefined, undefined);
|
||||
}
|
||||
}));
|
||||
this._localToDispose.add(this._editor.onDidChangeConfiguration(e => {
|
||||
if (e.hasChanged(EditorOption.fontInfo)) {
|
||||
for (const lens of this._lenses) {
|
||||
lens.updateHeight();
|
||||
}
|
||||
}
|
||||
}));
|
||||
this._localToDispose.add(this._editor.onMouseUp(e => {
|
||||
if (e.target.type === editorBrowser.MouseTargetType.CONTENT_WIDGET && e.target.element && e.target.element.tagName === 'A') {
|
||||
if (e.target.type !== editorBrowser.MouseTargetType.CONTENT_WIDGET) {
|
||||
return;
|
||||
}
|
||||
let target = e.target.element;
|
||||
if (target?.tagName === 'SPAN') {
|
||||
target = target.parentElement;
|
||||
}
|
||||
if (target?.tagName === 'A') {
|
||||
for (const lens of this._lenses) {
|
||||
let command = lens.getCommand(e.target.element as HTMLLinkElement);
|
||||
let command = lens.getCommand(target as HTMLLinkElement);
|
||||
if (command) {
|
||||
this._commandService.executeCommand(command.id, ...(command.arguments || [])).catch(err => this._notificationService.error(err));
|
||||
break;
|
||||
@@ -222,8 +244,10 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
|
||||
}
|
||||
|
||||
private _disposeAllLenses(decChangeAccessor: IModelDecorationsChangeAccessor | undefined, viewZoneChangeAccessor: editorBrowser.IViewZoneChangeAccessor | undefined): void {
|
||||
let helper = new CodeLensHelper();
|
||||
this._lenses.forEach((lens) => lens.dispose(helper, viewZoneChangeAccessor));
|
||||
const helper = new CodeLensHelper();
|
||||
for (const lens of this._lenses) {
|
||||
lens.dispose(helper, viewZoneChangeAccessor);
|
||||
}
|
||||
if (decChangeAccessor) {
|
||||
helper.commit(decChangeAccessor);
|
||||
}
|
||||
@@ -276,7 +300,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
|
||||
groupsIndex++;
|
||||
codeLensIndex++;
|
||||
} else {
|
||||
this._lenses.splice(codeLensIndex, 0, new CodeLensWidget(groups[groupsIndex], this._editor, helper, viewZoneAccessor, () => this._detectVisibleLenses && this._detectVisibleLenses.schedule()));
|
||||
this._lenses.splice(codeLensIndex, 0, new CodeLensWidget(groups[groupsIndex], <editorBrowser.IActiveCodeEditor>this._editor, this._styleClassName, helper, viewZoneAccessor, () => this._detectVisibleLenses && this._detectVisibleLenses.schedule()));
|
||||
codeLensIndex++;
|
||||
groupsIndex++;
|
||||
}
|
||||
@@ -290,7 +314,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
|
||||
|
||||
// Create extra symbols
|
||||
while (groupsIndex < groups.length) {
|
||||
this._lenses.push(new CodeLensWidget(groups[groupsIndex], this._editor, helper, viewZoneAccessor, () => this._detectVisibleLenses && this._detectVisibleLenses.schedule()));
|
||||
this._lenses.push(new CodeLensWidget(groups[groupsIndex], <editorBrowser.IActiveCodeEditor>this._editor, this._styleClassName, helper, viewZoneAccessor, () => this._detectVisibleLenses && this._detectVisibleLenses.schedule()));
|
||||
groupsIndex++;
|
||||
}
|
||||
|
||||
@@ -326,7 +350,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
|
||||
return;
|
||||
}
|
||||
|
||||
this._currentResolveCodeLensSymbolsPromise = createCancelablePromise(token => {
|
||||
const resolvePromise = createCancelablePromise(token => {
|
||||
|
||||
const promises = toResolve.map((request, i) => {
|
||||
|
||||
@@ -343,7 +367,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(() => {
|
||||
if (!token.isCancellationRequested) {
|
||||
if (!token.isCancellationRequested && !lenses[i].isDisposed()) {
|
||||
lenses[i].updateCommands(resolvedSymbols);
|
||||
}
|
||||
});
|
||||
@@ -351,13 +375,21 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
|
||||
|
||||
return Promise.all(promises);
|
||||
});
|
||||
this._currentResolveCodeLensSymbolsPromise = resolvePromise;
|
||||
|
||||
this._currentResolveCodeLensSymbolsPromise.then(() => {
|
||||
if (this._currentCodeLensModel) { // update the cached state with new resolved items
|
||||
this._codeLensCache.put(model, this._currentCodeLensModel);
|
||||
}
|
||||
this._oldCodeLensModels.clear(); // dispose old models once we have updated the UI with the current model
|
||||
this._currentResolveCodeLensSymbolsPromise = undefined;
|
||||
if (resolvePromise === this._currentResolveCodeLensSymbolsPromise) {
|
||||
this._currentResolveCodeLensSymbolsPromise = undefined;
|
||||
}
|
||||
}, err => {
|
||||
onUnexpectedError(err); // can also be cancellation!
|
||||
this._currentResolveCodeLensSymbolsPromise = undefined;
|
||||
if (resolvePromise === this._currentResolveCodeLensSymbolsPromise) {
|
||||
this._currentResolveCodeLensSymbolsPromise = undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user