Skip to content

Commit b63a9c9

Browse files
committed
Fix some 'super' must be called before accessing 'this' errors
1 parent ec3673e commit b63a9c9

8 files changed

Lines changed: 51 additions & 40 deletions

File tree

src/vs/editor/browser/standalone/simpleServices.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,10 @@ export class StandaloneKeybindingService extends KeybindingService {
216216
private _dynamicCommands: ICommandsMap;
217217

218218
constructor(domNode: HTMLElement) {
219+
super(domNode);
220+
219221
this._dynamicKeybindings = [];
220222
this._dynamicCommands = Object.create(null);
221-
super(domNode);
222223
}
223224

224225
public addDynamicKeybinding(keybinding: number, handler:ICommandHandler, context:string, commandId:string = null): string {

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ export class CodeEditorWidget extends CommonCodeEditor implements editorBrowser.
4747
@IKeybindingService keybindingService: IKeybindingService,
4848
@ITelemetryService telemetryService: ITelemetryService
4949
) {
50-
this.domElement = domElement;
51-
5250
super(domElement, options, instantiationService, codeEditorService, keybindingService, telemetryService);
5351

5452
// track focus of the domElement and all its anchestors

src/vs/editor/common/core/selection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ export class Selection extends Range implements IEditorSelection {
1414
public positionColumn: number;
1515

1616
constructor(selectionStartLineNumber: number, selectionStartColumn: number, positionLineNumber: number, positionColumn: number) {
17+
super(selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn);
1718
this.selectionStartLineNumber = selectionStartLineNumber;
1819
this.selectionStartColumn = selectionStartColumn;
1920
this.positionLineNumber = positionLineNumber;
2021
this.positionColumn = positionColumn;
21-
super(selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn);
2222
}
2323

2424
public clone(): IEditorSelection {

src/vs/editor/common/diff/diffComputer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ class LineMarkerSequence extends MarkerSequence {
9595
endColumn = lines[i].length + 1;
9696

9797
if (shouldIgnoreTrimWhitespace) {
98-
startColumn = this._getFirstNonBlankColumn(lines[i], 1);
99-
endColumn = this._getLastNonBlankColumn(lines[i], 1);
98+
startColumn = LineMarkerSequence._getFirstNonBlankColumn(lines[i], 1);
99+
endColumn = LineMarkerSequence._getLastNonBlankColumn(lines[i], 1);
100100
}
101101

102102
startMarkers.push({
@@ -117,15 +117,15 @@ class LineMarkerSequence extends MarkerSequence {
117117
super(buffer, startMarkers, endMarkers);
118118
}
119119

120-
private _getFirstNonBlankColumn(txt:string, defaultValue:number): number {
120+
private static _getFirstNonBlankColumn(txt:string, defaultValue:number): number {
121121
var r = strings.firstNonWhitespaceIndex(txt);
122122
if (r === -1) {
123123
return defaultValue;
124124
}
125125
return r + 1;
126126
}
127127

128-
private _getLastNonBlankColumn(txt:string, defaultValue:number): number {
128+
private static _getLastNonBlankColumn(txt:string, defaultValue:number): number {
129129
var r = strings.lastNonWhitespaceIndex(txt);
130130
if (r === -1) {
131131
return defaultValue;

src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,16 @@ export class GoToTypeDeclarationActions extends GoToTypeAction {
143143
}
144144
}
145145

146-
export class GoToDeclarationAction extends GoToTypeAction {
147-
148-
public static ID = 'editor.action.goToDeclaration';
146+
export abstract class BaseGoToDeclarationAction extends GoToTypeAction {
149147

150148
constructor(
151149
descriptor: editorCommon.IEditorActionDescriptorData,
152150
editor: editorCommon.ICommonCodeEditor,
153-
@IMessageService messageService: IMessageService,
154-
@IEditorService editorService: IEditorService
151+
messageService: IMessageService,
152+
editorService: IEditorService,
153+
condition: Behaviour
155154
) {
156-
super(descriptor, editor, messageService, editorService, this.behaviour);
155+
super(descriptor, editor, messageService, editorService, condition);
157156
}
158157

159158
public getGroupId(): string {
@@ -179,38 +178,45 @@ export class GoToDeclarationAction extends GoToTypeAction {
179178
});
180179
}
181180

182-
protected get behaviour(): Behaviour {
183-
return DEFAULT_BEHAVIOR;
184-
}
185181

186182
protected _resolve(resource: URI, position: editorCommon.IPosition): TPromise<IReference[]> {
187183
return getDeclarationsAtPosition(this.editor.getModel(), this.editor.getPosition());
188184
}
189185
}
190186

191-
export class OpenDeclarationToTheSideAction extends GoToDeclarationAction {
187+
export class GoToDeclarationAction extends BaseGoToDeclarationAction {
192188

193-
public static ID = 'editor.action.openDeclarationToTheSide';
189+
public static ID = 'editor.action.goToDeclaration';
194190

195191
constructor(
196192
descriptor: editorCommon.IEditorActionDescriptorData,
197193
editor: editorCommon.ICommonCodeEditor,
198194
@IMessageService messageService: IMessageService,
199195
@IEditorService editorService: IEditorService
200196
) {
201-
super(descriptor, editor, messageService, editorService);
197+
super(descriptor, editor, messageService, editorService, DEFAULT_BEHAVIOR);
202198
}
199+
}
200+
201+
export class OpenDeclarationToTheSideAction extends BaseGoToDeclarationAction {
203202

204-
protected get behaviour(): Behaviour {
205-
return Behaviour.WidgetFocus | Behaviour.UpdateOnCursorPositionChange;
203+
public static ID = 'editor.action.openDeclarationToTheSide';
204+
205+
constructor(
206+
descriptor: editorCommon.IEditorActionDescriptorData,
207+
editor: editorCommon.ICommonCodeEditor,
208+
@IMessageService messageService: IMessageService,
209+
@IEditorService editorService: IEditorService
210+
) {
211+
super(descriptor, editor, messageService, editorService, Behaviour.WidgetFocus | Behaviour.UpdateOnCursorPositionChange);
206212
}
207213

208214
protected get openToTheSide(): boolean {
209215
return true;
210216
}
211217
}
212218

213-
export class PreviewDeclarationAction extends GoToDeclarationAction {
219+
export class PreviewDeclarationAction extends BaseGoToDeclarationAction {
214220

215221
public static ID = 'editor.action.previewDeclaration';
216222

@@ -220,7 +226,7 @@ export class PreviewDeclarationAction extends GoToDeclarationAction {
220226
@IMessageService messageService: IMessageService,
221227
@IEditorService editorService: IEditorService
222228
) {
223-
super(descriptor, editor, messageService, editorService);
229+
super(descriptor, editor, messageService, editorService, DEFAULT_BEHAVIOR);
224230
}
225231

226232
protected _showSingleReferenceInPeek() {

src/vs/editor/test/common/testModes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ export class NMode extends TestingMode {
277277
public tokenizationSupport: modes.ITokenizationSupport;
278278

279279
constructor(n:number) {
280-
this.n = n;
281280
super();
281+
this.n = n;
282282
this.tokenizationSupport = new TokenizationSupport(this, {
283283
getInitialState: () => new NState(this, this.n)
284284
}, false, false);

src/vs/platform/keybinding/browser/keybindingServiceImpl.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ export class KeybindingService extends AbstractKeybindingService implements IKey
138138

139139
protected _domNode: HTMLElement;
140140
private _toDispose: IDisposable;
141-
private _resolver: KeybindingResolver;
141+
private _cachedResolver: KeybindingResolver;
142+
private _firstTimeComputingResolver: boolean;
142143
private _currentChord: number;
143144
private _currentChordStatusMessage: IDisposable;
144145

@@ -148,14 +149,23 @@ export class KeybindingService extends AbstractKeybindingService implements IKey
148149
this._domNode = domNode;
149150
this._contexts = Object.create(null);
150151
this._contexts[String(this._myContextId)] = new KeybindingContext(this._myContextId, null);
152+
this._cachedResolver = null;
153+
this._firstTimeComputingResolver = true;
154+
this._currentChord = 0;
155+
this._currentChordStatusMessage = null;
156+
151157
this._toDispose = dom.addDisposableListener(this._domNode, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => {
152158
let keyEvent = new StandardKeyboardEvent(e);
153159
this._dispatch(keyEvent);
154160
});
161+
}
155162

156-
this._createOrUpdateResolver(true);
157-
this._currentChord = 0;
158-
this._currentChordStatusMessage = null;
163+
private _getResolver(): KeybindingResolver {
164+
if (!this._cachedResolver) {
165+
this._cachedResolver = new KeybindingResolver(KeybindingsRegistry.getDefaultKeybindings(), this._getExtraKeybindings(this._firstTimeComputingResolver));
166+
this._firstTimeComputingResolver = false;
167+
}
168+
return this._cachedResolver;
159169
}
160170

161171
public dispose(): void {
@@ -176,31 +186,27 @@ export class KeybindingService extends AbstractKeybindingService implements IKey
176186
}
177187

178188
protected updateResolver(): void {
179-
this._createOrUpdateResolver(false);
180-
}
181-
182-
private _createOrUpdateResolver(isFirstTime: boolean): void {
183-
this._resolver = new KeybindingResolver(KeybindingsRegistry.getDefaultKeybindings(), this._getExtraKeybindings(isFirstTime));
189+
this._cachedResolver = null;
184190
}
185191

186192
protected _getExtraKeybindings(isFirstTime: boolean): IKeybindingItem[] {
187193
return [];
188194
}
189195

190196
public getDefaultKeybindings(): string {
191-
return this._resolver.getDefaultKeybindings() + '\n\n' + this._getAllCommandsAsComment();
197+
return this._getResolver().getDefaultKeybindings() + '\n\n' + this._getAllCommandsAsComment();
192198
}
193199

194200
public customKeybindingsCount(): number {
195201
return 0;
196202
}
197203

198204
public lookupKeybindings(commandId: string): Keybinding[] {
199-
return this._resolver.lookupKeybinding(commandId);
205+
return this._getResolver().lookupKeybinding(commandId);
200206
}
201207

202208
private _getAllCommandsAsComment(): string {
203-
let boundCommands = this._resolver.getDefaultBoundCommands();
209+
let boundCommands = this._getResolver().getDefaultBoundCommands();
204210
let unboundCommands = Object.keys(KeybindingsRegistry.getCommands()).filter(commandId => commandId[0] !== '_' && !boundCommands[commandId]);
205211
unboundCommands.sort();
206212
let pretty = unboundCommands.join('\n// - ');
@@ -223,7 +229,7 @@ export class KeybindingService extends AbstractKeybindingService implements IKey
223229
let contextValue = context.getValue();
224230
// console.log(JSON.stringify(contextValue, null, '\t'));
225231

226-
let resolveResult = this._resolver.resolve(contextValue, this._currentChord, e.asKeybinding());
232+
let resolveResult = this._getResolver().resolve(contextValue, this._currentChord, e.asKeybinding());
227233

228234
if (resolveResult && resolveResult.enterChord) {
229235
e.preventDefault();

src/vs/workbench/api/node/extHostTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ export class Selection extends Range {
290290
throw new Error('Invalid arguments');
291291
}
292292

293+
super(anchor, active);
294+
293295
this._anchor = anchor;
294296
this._active = active;
295-
296-
super(anchor, active);
297297
}
298298

299299
get isReversed(): boolean {

0 commit comments

Comments
 (0)