Skip to content

Commit

Permalink
use IOpenerService for hovers
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Apr 14, 2016
1 parent 6350d1a commit a3f49d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
9 changes: 4 additions & 5 deletions src/vs/editor/contrib/hover/browser/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {KeyCode, KeyMod} from 'vs/base/common/keyCodes';
import * as platform from 'vs/base/common/platform';
import {TPromise} from 'vs/base/common/winjs.base';
import {IKeyboardEvent} from 'vs/base/browser/keyboardEvent';
import {IEditorService} from 'vs/platform/editor/common/editor';
import {IKeybindingService, KbExpr} from 'vs/platform/keybinding/common/keybindingService';
import {IOpenerService} from 'vs/platform/opener/common/opener';
import {KbExpr} from 'vs/platform/keybinding/common/keybindingService';
import {Range} from 'vs/editor/common/core/range';
import {EditorAction} from 'vs/editor/common/editorAction';
import {Behaviour} from 'vs/editor/common/editorActionEnablement';
Expand All @@ -39,8 +39,7 @@ class ModesHoverController implements editorCommon.IEditorContribution {
}

constructor(editor: ICodeEditor,
@IEditorService editorService: IEditorService,
@IKeybindingService keybindingService: IKeybindingService
@IOpenerService openerService: IOpenerService
) {
this._editor = editor;

Expand All @@ -55,7 +54,7 @@ class ModesHoverController implements editorCommon.IEditorContribution {
this._toUnhook.push(this._editor.addListener(editorCommon.EventType.ModelDecorationsChanged, () => this._onModelDecorationsChanged()));
this._toUnhook.push(this._editor.addListener('scroll', () => this._hideWidgets()));

this._contentWidget = new ModesContentHoverWidget(editor, editorService, keybindingService);
this._contentWidget = new ModesContentHoverWidget(editor, openerService);
this._glyphWidget = new ModesGlyphHoverWidget(editor);
}
}
Expand Down
28 changes: 5 additions & 23 deletions src/vs/editor/contrib/hover/browser/modesContentHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import * as nls from 'vs/nls';
import URI from 'vs/base/common/uri';
import {TPromise} from 'vs/base/common/winjs.base';
import {renderHtml} from 'vs/base/browser/htmlContentRenderer';
import {IEditorService} from 'vs/platform/editor/common/editor';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {IOpenerService, NullOpenerService} from 'vs/platform/opener/common/opener';
import {Range} from 'vs/editor/common/core/range';
import {IEditorRange, IRange} from 'vs/editor/common/editorCommon';
import {ExtraInfoRegistry, IComputeExtraInfoResult, IMode} from 'vs/editor/common/modes';
Expand Down Expand Up @@ -123,18 +121,16 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
private _hoverOperation: HoverOperation<IComputeExtraInfoResult[]>;
private _highlightDecorations:string[];
private _isChangingDecorations: boolean;
private _editorService: IEditorService;
private _keybindingService: IKeybindingService;
private _openerService: IOpenerService;
private _shouldFocus: boolean;

constructor(editor: ICodeEditor, editorService: IEditorService, keybindingService: IKeybindingService) {
constructor(editor: ICodeEditor, openerService: IOpenerService) {
super(ModesContentHoverWidget.ID, editor);

this._computer = new ModesContentComputer(this._editor);
this._highlightDecorations = [];
this._isChangingDecorations = false;
this._editorService = editorService;
this._keybindingService = keybindingService;
this._openerService = openerService || NullOpenerService;

this._hoverOperation = new HoverOperation(
this._computer,
Expand Down Expand Up @@ -246,21 +242,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
msg.htmlContent.forEach((content) => {
container.appendChild(renderHtml(content, {
actionCallback: (content) => {

let promise: TPromise<any>;
if (KeybindingsRegistry.getCommands()[content]) {
promise = this._keybindingService.executeCommand(content);
} else {
try {
let resource = URI.parse(content);
promise = this._editorService.openEditor({resource});
} catch (e) {
// ignore
}
}
if (promise) {
promise.then(undefined, err => console.log(err));
}
this._openerService.open(URI.parse(content));
},
codeBlockRenderer: (modeId, value) => {
let mode: IMode;
Expand Down
5 changes: 5 additions & 0 deletions src/vs/platform/opener/common/opener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ export interface IOpenerService {
*/
open(resource: URI): TPromise<any>;
}

export const NullOpenerService: IOpenerService = Object.freeze({
serviceId: undefined,
open() { return TPromise.as(undefined);}
});

0 comments on commit a3f49d3

Please sign in to comment.