Skip to content

Commit 6d973fe

Browse files
committed
Strict null work on main thread
1 parent f9687fc commit 6d973fe

19 files changed

Lines changed: 70 additions & 61 deletions

File tree

src/vs/editor/browser/services/bulkEditService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ export interface IBulkEditResult {
2323
export interface IBulkEditService {
2424
_serviceBrand: any;
2525

26-
apply(edit: WorkspaceEdit, options: IBulkEditOptions): Promise<IBulkEditResult>;
26+
apply(edit: WorkspaceEdit, options?: IBulkEditOptions): Promise<IBulkEditResult>;
2727
}
2828

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ export class SimpleBulkEditService implements IBulkEditService {
576576
//
577577
}
578578

579-
apply(workspaceEdit: WorkspaceEdit, options: IBulkEditOptions): Promise<IBulkEditResult> {
579+
apply(workspaceEdit: WorkspaceEdit, options?: IBulkEditOptions): Promise<IBulkEditResult> {
580580

581581
let edits = new Map<ITextModel, TextEdit[]>();
582582

src/vs/platform/files/common/files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ export interface IBaseStat {
419419
* A unique identifier thet represents the
420420
* current state of the file or directory.
421421
*/
422-
etag: string;
422+
etag?: string;
423423

424424
/**
425425
* The resource is readonly.

src/vs/workbench/api/electron-browser/mainThreadDecorations.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,17 @@ export class MainThreadDecorations implements MainThreadDecorationsShape {
109109
}
110110

111111
$onDidChange(handle: number, resources: UriComponents[]): void {
112-
const [emitter] = this._provider.get(handle);
113-
emitter.fire(resources && resources.map(URI.revive));
112+
const provider = this._provider.get(handle);
113+
if (provider) {
114+
const [emitter] = provider;
115+
emitter.fire(resources && resources.map(URI.revive));
116+
}
114117
}
115118

116119
$unregisterDecorationProvider(handle: number): void {
117-
if (this._provider.has(handle)) {
118-
dispose(this._provider.get(handle));
120+
const provider = this._provider.get(handle);
121+
if (provider) {
122+
dispose(provider);
119123
this._provider.delete(handle);
120124
}
121125
}

src/vs/workbench/api/electron-browser/mainThreadDocuments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ export class MainThreadDocuments implements MainThreadDocumentsShape {
130130

131131
private _shouldHandleFileEvent(e: TextFileModelChangeEvent): boolean {
132132
const model = this._modelService.getModel(e.resource);
133-
return model && shouldSynchronizeModel(model);
133+
return !!model && shouldSynchronizeModel(model);
134134
}
135135

136136
private _onModelAdded(model: ITextModel): void {
137137
// Same filter as in mainThreadEditorsTracker
138138
if (!shouldSynchronizeModel(model)) {
139139
// don't synchronize too large models
140-
return null;
140+
return;
141141
}
142142
let modelUrl = model.uri;
143143
this._modelIsSynced[modelUrl.toString()] = true;

src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Emitter, Event } from 'vs/base/common/event';
77
import { IDisposable, combinedDisposable, dispose } from 'vs/base/common/lifecycle';
88
import { values } from 'vs/base/common/map';
99
import { URI } from 'vs/base/common/uri';
10-
import { ICodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser';
10+
import { ICodeEditor, isCodeEditor, isDiffEditor, IActiveCodeEditor } from 'vs/editor/browser/editorBrowser';
1111
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
1212
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
1313
import { IEditor } from 'vs/editor/common/editorCommon';
@@ -70,7 +70,7 @@ class TextEditorSnapshot {
7070
readonly id: string;
7171

7272
constructor(
73-
readonly editor: ICodeEditor,
73+
readonly editor: IActiveCodeEditor,
7474
) {
7575
this.id = `${editor.getId()},${editor.getModel().id}`;
7676
}
@@ -85,8 +85,8 @@ class DocumentAndEditorStateDelta {
8585
readonly addedDocuments: ITextModel[],
8686
readonly removedEditors: TextEditorSnapshot[],
8787
readonly addedEditors: TextEditorSnapshot[],
88-
readonly oldActiveEditor: string,
89-
readonly newActiveEditor: string,
88+
readonly oldActiveEditor: string | undefined,
89+
readonly newActiveEditor: string | undefined,
9090
) {
9191
this.isEmpty = this.removedDocuments.length === 0
9292
&& this.addedDocuments.length === 0
@@ -131,7 +131,7 @@ class DocumentAndEditorState {
131131
constructor(
132132
readonly documents: Set<ITextModel>,
133133
readonly textEditors: Map<string, TextEditorSnapshot>,
134-
readonly activeEditor: string,
134+
readonly activeEditor: string | undefined,
135135
) {
136136
//
137137
}
@@ -230,14 +230,14 @@ class MainThreadDocumentAndEditorStateComputer {
230230

231231
// editor: only take those that have a not too large model
232232
const editors = new Map<string, TextEditorSnapshot>();
233-
let activeEditor: string | null = null;
233+
let activeEditor: string | undefined = undefined;
234234

235235
for (const editor of this._codeEditorService.listCodeEditors()) {
236236
if (editor.isSimpleWidget) {
237237
continue;
238238
}
239239
const model = editor.getModel();
240-
if (model && shouldSynchronizeModel(model)
240+
if (editor.hasModel() && model && shouldSynchronizeModel(model)
241241
&& !model.isDisposed() // model disposed
242242
&& Boolean(this._modelService.getModel(model.uri)) // model disposing, the flag didn't flip yet but the model service already removed it
243243
) {
@@ -282,7 +282,7 @@ class MainThreadDocumentAndEditorStateComputer {
282282
}
283283
}
284284

285-
private _getActiveEditorFromPanel(): IEditor {
285+
private _getActiveEditorFromPanel(): IEditor | undefined {
286286
let panel = this._panelService.getActivePanel();
287287
if (panel instanceof BaseTextEditor && isCodeEditor(panel.getControl())) {
288288
return panel.getControl();
@@ -444,17 +444,17 @@ export class MainThreadDocumentsAndEditors {
444444
};
445445
}
446446

447-
private _findEditorPosition(editor: MainThreadTextEditor): EditorViewColumn {
448-
for (let workbenchEditor of this._editorService.visibleControls) {
447+
private _findEditorPosition(editor: MainThreadTextEditor): EditorViewColumn | undefined {
448+
for (const workbenchEditor of this._editorService.visibleControls) {
449449
if (editor.matches(workbenchEditor)) {
450450
return editorGroupToViewColumn(this._editorGroupService, workbenchEditor.group);
451451
}
452452
}
453453
return undefined;
454454
}
455455

456-
findTextEditorIdFor(editor: IWorkbenchEditor): string {
457-
for (let id in this._textEditors) {
456+
findTextEditorIdFor(editor: IWorkbenchEditor): string | undefined {
457+
for (const id in this._textEditors) {
458458
if (this._textEditors[id].matches(editor)) {
459459
return id;
460460
}

src/vs/workbench/api/electron-browser/mainThreadEditor.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class MainThreadTextEditor {
187187
private _focusTracker: IFocusTracker;
188188
private _codeEditorListeners: IDisposable[];
189189

190-
private _properties: MainThreadTextEditorProperties | null;
190+
private _properties: MainThreadTextEditorProperties;
191191
private readonly _onPropertiesChanged: Emitter<IEditorPropertiesChangeData>;
192192

193193
constructor(
@@ -204,7 +204,6 @@ export class MainThreadTextEditor {
204204
this._modelService = modelService;
205205
this._codeEditorListeners = [];
206206

207-
this._properties = null;
208207
this._onPropertiesChanged = new Emitter<IEditorPropertiesChangeData>();
209208

210209
this._modelListeners = [];
@@ -300,7 +299,7 @@ export class MainThreadTextEditor {
300299
return !!this._codeEditor;
301300
}
302301

303-
public getProperties(): MainThreadTextEditorProperties | null {
302+
public getProperties(): MainThreadTextEditorProperties {
304303
return this._properties;
305304
}
306305

@@ -316,7 +315,7 @@ export class MainThreadTextEditor {
316315

317316
const newSelections = selections.map(Selection.liftSelection);
318317
this._setProperties(
319-
new MainThreadTextEditorProperties(newSelections, this._properties!.options, this._properties!.visibleRanges),
318+
new MainThreadTextEditorProperties(newSelections, this._properties.options, this._properties.visibleRanges),
320319
null
321320
);
322321
}

src/vs/workbench/api/electron-browser/mainThreadEditors.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
3636
private _documentsAndEditors: MainThreadDocumentsAndEditors;
3737
private _toDispose: IDisposable[];
3838
private _textEditorsListenersMap: { [editorId: string]: IDisposable[]; };
39-
private _editorPositionData: ITextEditorPositionData;
39+
private _editorPositionData: ITextEditorPositionData | null;
4040
private _registeredDecorationTypes: { [decorationType: string]: boolean; };
4141

4242
constructor(
@@ -145,7 +145,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
145145
options: { preserveFocus: false }
146146
}, viewColumnToEditorGroup(this._editorGroupService, position)).then(() => { return; });
147147
}
148-
return undefined;
148+
return Promise.resolve();
149149
}
150150

151151
$tryHideEditor(id: string): Promise<void> {
@@ -158,7 +158,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
158158
}
159159
}
160160
}
161-
return undefined;
161+
return Promise.resolve();
162162
}
163163

164164
$trySetSelections(id: string, selections: ISelection[]): Promise<void> {
@@ -192,7 +192,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
192192
return Promise.reject(disposed(`TextEditor(${id})`));
193193
}
194194
this._documentsAndEditors.getEditor(id).revealRange(range, revealType);
195-
return undefined;
195+
return Promise.resolve();
196196
}
197197

198198
$trySetOptions(id: string, options: ITextEditorConfigurationUpdate): Promise<void> {

src/vs/workbench/api/electron-browser/mainThreadLanguageFeatures.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
198198

199199
$registerHoverProvider(handle: number, selector: ISerializedDocumentFilter[]): void {
200200
this._registrations[handle] = modes.HoverProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.HoverProvider>{
201-
provideHover: (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.Hover> => {
201+
provideHover: (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.Hover | undefined> => {
202202
return this._proxy.$provideHover(handle, model.uri, position, token);
203203
}
204204
});
@@ -208,7 +208,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
208208

209209
$registerDocumentHighlightProvider(handle: number, selector: ISerializedDocumentFilter[]): void {
210210
this._registrations[handle] = modes.DocumentHighlightProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.DocumentHighlightProvider>{
211-
provideDocumentHighlights: (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.DocumentHighlight[]> => {
211+
provideDocumentHighlights: (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.DocumentHighlight[] | undefined> => {
212212
return this._proxy.$provideDocumentHighlights(handle, model.uri, position, token);
213213
}
214214
});
@@ -243,7 +243,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
243243
$registerDocumentFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], displayName: string): void {
244244
this._registrations[handle] = modes.DocumentFormattingEditProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.DocumentFormattingEditProvider>{
245245
displayName,
246-
provideDocumentFormattingEdits: (model: ITextModel, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[]> => {
246+
provideDocumentFormattingEdits: (model: ITextModel, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[] | undefined> => {
247247
return this._proxy.$provideDocumentFormattingEdits(handle, model.uri, options, token);
248248
}
249249
});
@@ -252,7 +252,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
252252
$registerRangeFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], displayName: string): void {
253253
this._registrations[handle] = modes.DocumentRangeFormattingEditProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.DocumentRangeFormattingEditProvider>{
254254
displayName,
255-
provideDocumentRangeFormattingEdits: (model: ITextModel, range: EditorRange, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[]> => {
255+
provideDocumentRangeFormattingEdits: (model: ITextModel, range: EditorRange, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[] | undefined> => {
256256
return this._proxy.$provideDocumentRangeFormattingEdits(handle, model.uri, range, options, token);
257257
}
258258
});
@@ -263,7 +263,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
263263

264264
autoFormatTriggerCharacters,
265265

266-
provideOnTypeFormattingEdits: (model: ITextModel, position: EditorPosition, ch: string, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[]> => {
266+
provideOnTypeFormattingEdits: (model: ITextModel, position: EditorPosition, ch: string, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[] | undefined> => {
267267
return this._proxy.$provideOnTypeFormattingEdits(handle, model.uri, position, ch, options, token);
268268
}
269269
});
@@ -272,7 +272,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
272272
// --- navigate type
273273

274274
$registerNavigateTypeSupport(handle: number): void {
275-
let lastResultId: number;
275+
let lastResultId: number | undefined;
276276
this._registrations[handle] = search.WorkspaceSymbolProviderRegistry.register(<search.IWorkspaceSymbolProvider>{
277277
provideWorkspaceSymbols: (search: string, token: CancellationToken): Promise<search.IWorkspaceSymbol[]> => {
278278
return this._proxy.$provideWorkspaceSymbols(handle, search, token).then(result => {
@@ -298,7 +298,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
298298
return this._proxy.$provideRenameEdits(handle, model.uri, position, newName, token).then(reviveWorkspaceEditDto);
299299
},
300300
resolveRenameLocation: supportResolveLocation
301-
? (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.RenameLocation> => this._proxy.$resolveRenameLocation(handle, model.uri, position, token)
301+
? (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.RenameLocation | undefined> => this._proxy.$resolveRenameLocation(handle, model.uri, position, token)
302302
: undefined
303303
});
304304
}

src/vs/workbench/api/electron-browser/mainThreadTreeViews.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export class MainThreadTreeViews extends Disposable implements MainThreadTreeVie
4545
return this.viewsService.openView(treeViewId, options.focus)
4646
.then(() => {
4747
const viewer = this.getTreeView(treeViewId);
48-
return this.reveal(viewer, this._dataProviders.get(treeViewId), item, parentChain, options);
48+
if (viewer) {
49+
return this.reveal(viewer, this._dataProviders.get(treeViewId)!, item, parentChain, options);
50+
}
51+
return undefined;
4952
});
5053
}
5154

@@ -56,7 +59,7 @@ export class MainThreadTreeViews extends Disposable implements MainThreadTreeVie
5659
const itemsToRefresh = dataProvider.getItemsToRefresh(itemsToRefreshByHandle);
5760
return viewer.refresh(itemsToRefresh.length ? itemsToRefresh : undefined);
5861
}
59-
return null;
62+
return Promise.resolve();
6063
}
6164

6265
$setMessage(treeViewId: string, message: string | IMarkdownString): void {

0 commit comments

Comments
 (0)