提交 1b04b836 编写于 作者: S Sandeep Somavarapu

#67076 Show Peek Problem action in the hover footer

上级 41f15455
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
display: none; display: none;
} }
.monaco-editor-hover .hover-row { .monaco-editor-hover .hover-contents {
padding: 4px 8px; padding: 4px 8px;
} }
...@@ -72,39 +72,12 @@ ...@@ -72,39 +72,12 @@
word-break: break-all; word-break: break-all;
} }
.monaco-editor-hover .marker-hover { .monaco-editor-hover .hover-row .actions {
display: flex; display: flex;
padding: 2px 0px;
} }
.monaco-editor-hover .marker-hover > .marker { .monaco-editor-hover .hover-row .actions .action {
flex: 1;
}
.monaco-editor-hover .marker-hover > .actions {
padding-left: 12px;
display: flex;
}
.monaco-editor-hover .marker-hover > .actions > .icon {
width: 16px;
height: 16px;
}
.monaco-editor-hover .marker-hover > .actions .action {
cursor: pointer; cursor: pointer;
padding-left: 4px; padding-left: 8px;
} }
\ No newline at end of file
.monaco-editor-hover .marker-hover > .actions > .peek-marker {
font-size: large;
vertical-align: middle;
}
.monaco-editor-hover .marker-hover > .actions > .light-bulb {
background: url('../codeAction/lightbulb.svg') center center no-repeat;
}
.hc-black .monaco-editor-hover .marker-hover > .actions > .light-bulb,
.vs-dark .monaco-editor-hover .marker-hover > .actions > .light-bulb {
background: url('../codeAction/lightbulb-dark.svg') center center no-repeat;
}
...@@ -23,12 +23,9 @@ import { ModesGlyphHoverWidget } from 'vs/editor/contrib/hover/modesGlyphHover'; ...@@ -23,12 +23,9 @@ import { ModesGlyphHoverWidget } from 'vs/editor/contrib/hover/modesGlyphHover';
import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer'; import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IOpenerService } from 'vs/platform/opener/common/opener'; import { IOpenerService } from 'vs/platform/opener/common/opener';
import { editorHoverBackground, editorHoverBorder, editorHoverHighlight, textCodeBlockBackground, textLinkForeground } from 'vs/platform/theme/common/colorRegistry'; import { editorHoverBackground, editorHoverBorder, editorHoverHighlight, textCodeBlockBackground, textLinkForeground, editorHoverFooterBackground } from 'vs/platform/theme/common/colorRegistry';
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService'; import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDecorationService'; import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDecorationService';
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
export class ModesHoverController implements IEditorContribution { export class ModesHoverController implements IEditorContribution {
...@@ -65,9 +62,6 @@ export class ModesHoverController implements IEditorContribution { ...@@ -65,9 +62,6 @@ export class ModesHoverController implements IEditorContribution {
constructor(private readonly _editor: ICodeEditor, constructor(private readonly _editor: ICodeEditor,
@IOpenerService private readonly _openerService: IOpenerService, @IOpenerService private readonly _openerService: IOpenerService,
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
@IBulkEditService private readonly _bulkEditService: IBulkEditService,
@ICommandService private readonly _commandService: ICommandService,
@IModeService private readonly _modeService: IModeService, @IModeService private readonly _modeService: IModeService,
@IMarkerDecorationsService private readonly _markerDecorationsService: IMarkerDecorationsService, @IMarkerDecorationsService private readonly _markerDecorationsService: IMarkerDecorationsService,
@IThemeService private readonly _themeService: IThemeService @IThemeService private readonly _themeService: IThemeService
...@@ -213,7 +207,7 @@ export class ModesHoverController implements IEditorContribution { ...@@ -213,7 +207,7 @@ export class ModesHoverController implements IEditorContribution {
private _createHoverWidget() { private _createHoverWidget() {
const renderer = new MarkdownRenderer(this._editor, this._modeService, this._openerService); const renderer = new MarkdownRenderer(this._editor, this._modeService, this._openerService);
this._contentWidget = new ModesContentHoverWidget(this._editor, renderer, this._markerDecorationsService, this._themeService, this._contextMenuService, this._bulkEditService, this._commandService, this._openerService); this._contentWidget = new ModesContentHoverWidget(this._editor, renderer, this._markerDecorationsService, this._themeService, this._openerService);
this._glyphWidget = new ModesGlyphHoverWidget(this._editor, renderer); this._glyphWidget = new ModesGlyphHoverWidget(this._editor, renderer);
} }
...@@ -295,6 +289,10 @@ registerThemingParticipant((theme, collector) => { ...@@ -295,6 +289,10 @@ registerThemingParticipant((theme, collector) => {
collector.addRule(`.monaco-editor .monaco-editor-hover hr { border-top: 1px solid ${hoverBorder.transparent(0.5)}; }`); collector.addRule(`.monaco-editor .monaco-editor-hover hr { border-top: 1px solid ${hoverBorder.transparent(0.5)}; }`);
collector.addRule(`.monaco-editor .monaco-editor-hover hr { border-bottom: 0px solid ${hoverBorder.transparent(0.5)}; }`); collector.addRule(`.monaco-editor .monaco-editor-hover hr { border-bottom: 0px solid ${hoverBorder.transparent(0.5)}; }`);
} }
const actionsBackground = theme.getColor(editorHoverFooterBackground);
if (actionsBackground) {
collector.addRule(`.monaco-editor .monaco-editor-hover .hover-row .actions { background-color: ${actionsBackground}; }`);
}
const link = theme.getColor(textLinkForeground); const link = theme.getColor(textLinkForeground);
if (link) { if (link) {
collector.addRule(`.monaco-editor .monaco-editor-hover a { color: ${link}; }`); collector.addRule(`.monaco-editor .monaco-editor-hover a { color: ${link}; }`);
......
...@@ -8,7 +8,7 @@ import * as dom from 'vs/base/browser/dom'; ...@@ -8,7 +8,7 @@ import * as dom from 'vs/base/browser/dom';
import { CancellationToken } from 'vs/base/common/cancellation'; import { CancellationToken } from 'vs/base/common/cancellation';
import { Color, RGBA } from 'vs/base/common/color'; import { Color, RGBA } from 'vs/base/common/color';
import { IMarkdownString, MarkdownString, isEmptyMarkdownString, markedStringsEquals } from 'vs/base/common/htmlContent'; import { IMarkdownString, MarkdownString, isEmptyMarkdownString, markedStringsEquals } from 'vs/base/common/htmlContent';
import { Disposable, IDisposable, combinedDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { Disposable, IDisposable, combinedDisposable } from 'vs/base/common/lifecycle';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { Position } from 'vs/editor/common/core/position'; import { Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range'; import { IRange, Range } from 'vs/editor/common/core/range';
...@@ -30,14 +30,6 @@ import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDeco ...@@ -30,14 +30,6 @@ import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDeco
import { onUnexpectedError } from 'vs/base/common/errors'; import { onUnexpectedError } from 'vs/base/common/errors';
import { IOpenerService, NullOpenerService } from 'vs/platform/opener/common/opener'; import { IOpenerService, NullOpenerService } from 'vs/platform/opener/common/opener';
import { MarkerController } from 'vs/editor/contrib/gotoError/gotoError'; import { MarkerController } from 'vs/editor/contrib/gotoError/gotoError';
import { getCodeActions } from 'vs/editor/contrib/codeAction/codeAction';
import { CodeActionKind } from 'vs/editor/contrib/codeAction/codeActionTrigger';
import { Action } from 'vs/base/common/actions';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { applyCodeAction } from 'vs/editor/contrib/codeAction/codeActionCommands';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
import { CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
const $ = dom.$; const $ = dom.$;
...@@ -215,9 +207,6 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -215,9 +207,6 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
markdownRenderer: MarkdownRenderer, markdownRenderer: MarkdownRenderer,
markerDecorationsService: IMarkerDecorationsService, markerDecorationsService: IMarkerDecorationsService,
private readonly _themeService: IThemeService, private readonly _themeService: IThemeService,
private readonly _contextMenuService: IContextMenuService,
private readonly _bulkEditService: IBulkEditService,
private readonly _commandService: ICommandService,
private readonly _openerService: IOpenerService | null = NullOpenerService, private readonly _openerService: IOpenerService | null = NullOpenerService,
) { ) {
super(ModesContentHoverWidget.ID, editor); super(ModesContentHoverWidget.ID, editor);
...@@ -356,6 +345,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -356,6 +345,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
let containColorPicker = false; let containColorPicker = false;
let markdownDisposeable: IDisposable; let markdownDisposeable: IDisposable;
const markerMessages: MarkerHover[] = [];
messages.forEach((msg) => { messages.forEach((msg) => {
if (!msg.range) { if (!msg.range) {
return; return;
...@@ -449,21 +439,23 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -449,21 +439,23 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
}); });
} else { } else {
if (msg instanceof MarkerHover) { if (msg instanceof MarkerHover) {
markerMessages.push(msg);
isEmptyHoverContent = false; isEmptyHoverContent = false;
fragment.appendChild($('div.hover-row', undefined, this.renderMarkerHover(msg)));
} else { } else {
msg.contents msg.contents
.filter(contents => !isEmptyMarkdownString(contents)) .filter(contents => !isEmptyMarkdownString(contents))
.forEach(contents => { .forEach(contents => {
const renderedContents = this._markdownRenderer.render(contents); const renderedContents = this._markdownRenderer.render(contents);
markdownDisposeable = renderedContents; markdownDisposeable = renderedContents;
fragment.appendChild($('div.hover-row', undefined, renderedContents.element)); fragment.appendChild($('div.hover-row.hover-contents', undefined, renderedContents.element));
isEmptyHoverContent = false; isEmptyHoverContent = false;
}); });
} }
} }
}); });
markerMessages.forEach(msg => fragment.appendChild(this.renderMarkerHover(msg)));
// show // show
if (!containColorPicker && !isEmptyHoverContent) { if (!containColorPicker && !isEmptyHoverContent) {
...@@ -480,8 +472,8 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -480,8 +472,8 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
} }
private renderMarkerHover(markerHover: MarkerHover): HTMLElement { private renderMarkerHover(markerHover: MarkerHover): HTMLElement {
const hoverElement = $('div.marker-hover'); const hoverElement = $('div.hover-row');
const markerElement = dom.append(hoverElement, $('div.marker')); const markerElement = dom.append(hoverElement, $('div.marker.hover-contents'));
const { source, message, code, relatedInformation } = markerHover.marker; const { source, message, code, relatedInformation } = markerHover.marker;
const messageElement = dom.append(markerElement, $('span')); const messageElement = dom.append(markerElement, $('span'));
...@@ -515,22 +507,9 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -515,22 +507,9 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
} }
const actionsElement = dom.append(hoverElement, $('div.actions')); const actionsElement = dom.append(hoverElement, $('div.actions'));
const showCodeActions = dom.append(actionsElement, $('a.action.icon.light-bulb', { title: nls.localize('code actions', "Show Fixes...") }));
const disposables: IDisposable[] = []; const disposables: IDisposable[] = [];
disposables.push(dom.addDisposableListener(showCodeActions, dom.EventType.CLICK, async e => { const peekMarkerAction = dom.append(actionsElement, $('a.action.peek-marker', { title: nls.localize('go to problem', "Peek Problem") }));
e.stopPropagation(); peekMarkerAction.textContent = 'Peek Problem';
e.preventDefault();
const codeActionsPromise = this.getCodeActions(markerHover.marker);
disposables.push(toDisposable(() => codeActionsPromise.cancel()));
const actions = await codeActionsPromise;
const elementPosition = dom.getDomNodePagePosition(showCodeActions);
this._contextMenuService.showContextMenu({
getAnchor: () => ({ x: elementPosition.left + 6, y: elementPosition.top + elementPosition.height + 6 }),
getActions: () => actions
});
}));
const peekMarkerAction = dom.append(actionsElement, $('a.action.icon.peek-marker', { title: nls.localize('go to problem', "Go to Problem") }));
peekMarkerAction.textContent = '';
disposables.push(dom.addDisposableListener(peekMarkerAction, dom.EventType.CLICK, e => { disposables.push(dom.addDisposableListener(peekMarkerAction, dom.EventType.CLICK, e => {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
...@@ -542,23 +521,6 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -542,23 +521,6 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
return hoverElement; return hoverElement;
} }
private getCodeActions(marker: IMarker): CancelablePromise<Action[]> {
return createCancelablePromise(async cancellationToken => {
const codeActions = await getCodeActions(this._editor.getModel()!, new Range(marker.startLineNumber, marker.startColumn, marker.endLineNumber, marker.endColumn), { type: 'manual', filter: { kind: CodeActionKind.QuickFix } }, cancellationToken);
if (codeActions.length) {
return codeActions.map(codeAction => new Action(
codeAction.command ? codeAction.command.id : codeAction.title,
codeAction.title,
undefined,
true,
() => applyCodeAction(codeAction, this._bulkEditService, this._commandService)));
}
return [
new Action('', nls.localize('editor.action.quickFix.noneMessage', "No code actions available"))
];
});
}
private static readonly _DECORATION_OPTIONS = ModelDecorationOptions.register({ private static readonly _DECORATION_OPTIONS = ModelDecorationOptions.register({
className: 'hoverHighlight' className: 'hoverHighlight'
}); });
......
...@@ -310,6 +310,7 @@ export const editorFindRangeHighlightBorder = registerColor('editor.findRangeHig ...@@ -310,6 +310,7 @@ export const editorFindRangeHighlightBorder = registerColor('editor.findRangeHig
export const editorHoverHighlight = registerColor('editor.hoverHighlightBackground', { light: '#ADD6FF26', dark: '#264f7840', hc: '#ADD6FF26' }, nls.localize('hoverHighlight', 'Highlight below the word for which a hover is shown. The color must not be opaque so as not to hide underlying decorations.'), true); export const editorHoverHighlight = registerColor('editor.hoverHighlightBackground', { light: '#ADD6FF26', dark: '#264f7840', hc: '#ADD6FF26' }, nls.localize('hoverHighlight', 'Highlight below the word for which a hover is shown. The color must not be opaque so as not to hide underlying decorations.'), true);
export const editorHoverBackground = registerColor('editorHoverWidget.background', { light: editorWidgetBackground, dark: editorWidgetBackground, hc: editorWidgetBackground }, nls.localize('hoverBackground', 'Background color of the editor hover.')); export const editorHoverBackground = registerColor('editorHoverWidget.background', { light: editorWidgetBackground, dark: editorWidgetBackground, hc: editorWidgetBackground }, nls.localize('hoverBackground', 'Background color of the editor hover.'));
export const editorHoverBorder = registerColor('editorHoverWidget.border', { light: editorWidgetBorder, dark: editorWidgetBorder, hc: editorWidgetBorder }, nls.localize('hoverBorder', 'Border color of the editor hover.')); export const editorHoverBorder = registerColor('editorHoverWidget.border', { light: editorWidgetBorder, dark: editorWidgetBorder, hc: editorWidgetBorder }, nls.localize('hoverBorder', 'Border color of the editor hover.'));
export const editorHoverFooterBackground = registerColor('editorHoverWidget.footerBackground', { dark: Color.fromHex('#808080').transparent(0.2), light: Color.fromHex('#808080').transparent(0.2), hc: null }, nls.localize('hoverFotterground', "Background color of the editor hover footer."));
/** /**
* Editor link colors * Editor link colors
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册