mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-21 12:20:29 -04:00
Merge VS Code 1.31.1 (#4283)
This commit is contained in:
@@ -6,45 +6,49 @@
|
||||
import * as dom from 'vs/base/browser/dom';
|
||||
import { GlobalMouseMoveMonitor, IStandardMouseMoveEventData, standardMouseMoveMerger } from 'vs/base/browser/globalMouseMoveMonitor';
|
||||
import { CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import 'vs/css!./lightBulbWidget';
|
||||
import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { CodeActionsComputeEvent } from './codeActionModel';
|
||||
import { CodeActionsState } from './codeActionModel';
|
||||
|
||||
export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
export class LightBulbWidget extends Disposable implements IContentWidget {
|
||||
|
||||
private static readonly _posPref = [ContentWidgetPositionPreference.EXACT];
|
||||
|
||||
private readonly _domNode: HTMLDivElement;
|
||||
private readonly _editor: ICodeEditor;
|
||||
private readonly _disposables: IDisposable[] = [];
|
||||
private readonly _onClick = new Emitter<{ x: number, y: number }>();
|
||||
|
||||
readonly onClick: Event<{ x: number, y: number }> = this._onClick.event;
|
||||
private readonly _onClick = this._register(new Emitter<{ x: number; y: number; state: CodeActionsState.Triggered }>());
|
||||
public readonly onClick = this._onClick.event;
|
||||
|
||||
private _position: IContentWidgetPosition | null;
|
||||
private _model: CodeActionsComputeEvent | null;
|
||||
private _state: CodeActionsState.State = CodeActionsState.Empty;
|
||||
private _futureFixes = new CancellationTokenSource();
|
||||
|
||||
constructor(editor: ICodeEditor) {
|
||||
super();
|
||||
this._domNode = document.createElement('div');
|
||||
this._domNode.className = 'lightbulb-glyph';
|
||||
|
||||
this._editor = editor;
|
||||
this._editor.addContentWidget(this);
|
||||
|
||||
this._disposables.push(this._editor.onDidChangeModel(_ => this._futureFixes.cancel()));
|
||||
this._disposables.push(this._editor.onDidChangeModelLanguage(_ => this._futureFixes.cancel()));
|
||||
this._disposables.push(this._editor.onDidChangeModelContent(_ => {
|
||||
this._register(this._editor.onDidChangeModel(_ => this._futureFixes.cancel()));
|
||||
this._register(this._editor.onDidChangeModelLanguage(_ => this._futureFixes.cancel()));
|
||||
this._register(this._editor.onDidChangeModelContent(_ => {
|
||||
// cancel when the line in question has been removed
|
||||
const editorModel = this._editor.getModel();
|
||||
if (!this.model || !this.model.position || !editorModel || this.model.position.lineNumber >= editorModel.getLineCount()) {
|
||||
if (this._state.type !== CodeActionsState.Type.Triggered || !editorModel || this._state.position.lineNumber >= editorModel.getLineCount()) {
|
||||
this._futureFixes.cancel();
|
||||
}
|
||||
}));
|
||||
this._disposables.push(dom.addStandardDisposableListener(this._domNode, 'click', e => {
|
||||
this._register(dom.addStandardDisposableListener(this._domNode, 'click', e => {
|
||||
if (this._state.type !== CodeActionsState.Type.Triggered) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure that focus / cursor location is not lost when clicking widget icon
|
||||
this._editor.focus();
|
||||
// a bit of extra work to make sure the menu
|
||||
@@ -53,16 +57,17 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
const { lineHeight } = this._editor.getConfiguration();
|
||||
|
||||
let pad = Math.floor(lineHeight / 3);
|
||||
if (this._position && this._model && this._model.position && this._position.position !== null && this._position.position.lineNumber < this._model.position.lineNumber) {
|
||||
if (this._position && this._position.position !== null && this._position.position.lineNumber < this._state.position.lineNumber) {
|
||||
pad += lineHeight;
|
||||
}
|
||||
|
||||
this._onClick.fire({
|
||||
x: e.posx,
|
||||
y: top + height + pad
|
||||
y: top + height + pad,
|
||||
state: this._state
|
||||
});
|
||||
}));
|
||||
this._disposables.push(dom.addDisposableListener(this._domNode, 'mouseenter', (e: MouseEvent) => {
|
||||
this._register(dom.addDisposableListener(this._domNode, 'mouseenter', (e: MouseEvent) => {
|
||||
if ((e.buttons & 1) !== 1) {
|
||||
return;
|
||||
}
|
||||
@@ -75,7 +80,7 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
monitor.dispose();
|
||||
});
|
||||
}));
|
||||
this._disposables.push(this._editor.onDidChangeConfiguration(e => {
|
||||
this._register(this._editor.onDidChangeConfiguration(e => {
|
||||
// hide when told to do so
|
||||
if (e.contribInfo && !this._editor.getConfiguration().contribInfo.lightbulbEnabled) {
|
||||
this.hide();
|
||||
@@ -84,7 +89,7 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
dispose(this._disposables);
|
||||
super.dispose();
|
||||
this._editor.removeContentWidget(this);
|
||||
}
|
||||
|
||||
@@ -100,9 +105,9 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
return this._position;
|
||||
}
|
||||
|
||||
set model(value: CodeActionsComputeEvent | null) {
|
||||
tryShow(newState: CodeActionsState.State) {
|
||||
|
||||
if (!value || this._position && (!value.position || this._position.position && this._position.position.lineNumber !== value.position.lineNumber)) {
|
||||
if (newState.type !== CodeActionsState.Type.Triggered || this._position && (!newState.position || this._position.position && this._position.position.lineNumber !== newState.position.lineNumber)) {
|
||||
// hide when getting a 'hide'-request or when currently
|
||||
// showing on another line
|
||||
this.hide();
|
||||
@@ -113,14 +118,14 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
|
||||
this._futureFixes = new CancellationTokenSource();
|
||||
const { token } = this._futureFixes;
|
||||
this._model = value;
|
||||
this._state = newState;
|
||||
|
||||
if (!this._model || !this._model.actions) {
|
||||
if (this._state.type === CodeActionsState.Empty.type) {
|
||||
return;
|
||||
}
|
||||
|
||||
const selection = this._model.rangeOrSelection;
|
||||
this._model.actions.then(fixes => {
|
||||
const selection = this._state.rangeOrSelection;
|
||||
this._state.actions.then(fixes => {
|
||||
if (!token.isCancellationRequested && fixes && fixes.length > 0 && selection) {
|
||||
this._show();
|
||||
} else {
|
||||
@@ -131,10 +136,6 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
});
|
||||
}
|
||||
|
||||
get model(): CodeActionsComputeEvent | null {
|
||||
return this._model;
|
||||
}
|
||||
|
||||
set title(value: string) {
|
||||
this._domNode.title = value;
|
||||
}
|
||||
@@ -148,10 +149,10 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
if (!config.contribInfo.lightbulbEnabled) {
|
||||
return;
|
||||
}
|
||||
if (!this._model || !this._model.position) {
|
||||
if (this._state.type !== CodeActionsState.Type.Triggered) {
|
||||
return;
|
||||
}
|
||||
const { lineNumber, column } = this._model.position;
|
||||
const { lineNumber, column } = this._state.position;
|
||||
const model = this._editor.getModel();
|
||||
if (!model) {
|
||||
return;
|
||||
@@ -188,7 +189,7 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
|
||||
hide(): void {
|
||||
this._position = null;
|
||||
this._model = null;
|
||||
this._state = CodeActionsState.Empty;
|
||||
this._futureFixes.cancel();
|
||||
this._editor.layoutContentWidget(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user