mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-10 00:35:30 +01:00
Strict null checks
This commit is contained in:
@@ -90,7 +90,6 @@
|
||||
"./vs/code/electron-browser/issue/issueReporterModel.ts",
|
||||
"./vs/code/electron-browser/issue/issueReporterPage.ts",
|
||||
"./vs/code/electron-browser/issue/issueReporterUtil.ts",
|
||||
"./vs/code/electron-browser/processExplorer/processExplorerMain.ts",
|
||||
"./vs/code/electron-main/auth.ts",
|
||||
"./vs/code/electron-main/keyboard.ts",
|
||||
"./vs/code/electron-main/theme.ts",
|
||||
@@ -257,6 +256,7 @@
|
||||
"./vs/editor/contrib/caretOperations/transpose.ts",
|
||||
"./vs/editor/contrib/clipboard/clipboard.ts",
|
||||
"./vs/editor/contrib/codeAction/codeAction.ts",
|
||||
"./vs/editor/contrib/codeAction/codeActionModel.ts",
|
||||
"./vs/editor/contrib/codeAction/codeActionTrigger.ts",
|
||||
"./vs/editor/contrib/colorPicker/color.ts",
|
||||
"./vs/editor/contrib/colorPicker/colorDetector.ts",
|
||||
@@ -445,9 +445,11 @@
|
||||
"./vs/platform/theme/common/themeService.ts",
|
||||
"./vs/platform/theme/test/common/testThemeService.ts",
|
||||
"./vs/platform/update/common/update.ts",
|
||||
"./vs/platform/update/electron-main/abstractUpdateService.ts",
|
||||
"./vs/platform/update/node/update.config.contribution.ts",
|
||||
"./vs/platform/url/common/url.ts",
|
||||
"./vs/platform/url/common/urlService.ts",
|
||||
"./vs/platform/url/electron-main/electronUrlListener.ts",
|
||||
"./vs/platform/widget/common/contextScopedWidget.ts",
|
||||
"./vs/platform/windows/common/windows.ts",
|
||||
"./vs/platform/windows/electron-browser/windowService.ts",
|
||||
@@ -524,6 +526,7 @@
|
||||
"./vs/workbench/parts/surveys/electron-browser/nps.contribution.ts",
|
||||
"./vs/workbench/parts/tasks/common/problemCollectors.ts",
|
||||
"./vs/workbench/parts/tasks/common/problemMatcher.ts",
|
||||
"./vs/workbench/parts/tasks/common/taskService.ts",
|
||||
"./vs/workbench/parts/tasks/common/taskSystem.ts",
|
||||
"./vs/workbench/parts/tasks/common/taskTemplates.ts",
|
||||
"./vs/workbench/parts/tasks/common/tasks.ts",
|
||||
|
||||
@@ -98,7 +98,7 @@ export class SharedProcess implements ISharedProcess {
|
||||
logLevel: this.logService.getLevel()
|
||||
});
|
||||
|
||||
ipcMain.once('handshake:im ready', () => c(null));
|
||||
ipcMain.once('handshake:im ready', () => c(void 0));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -49,8 +49,12 @@ export class CodeActionOracle {
|
||||
}
|
||||
|
||||
private _onMarkerChanges(resources: URI[]): void {
|
||||
const { uri } = this._editor.getModel();
|
||||
if (resources.some(resource => resource.toString() === uri.toString())) {
|
||||
const model = this._editor.getModel();
|
||||
if (!model) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (resources.some(resource => resource.toString() === model.uri.toString())) {
|
||||
this._autoTriggerTimer.cancelAndSet(() => {
|
||||
this.trigger({ type: 'auto' });
|
||||
}, this._delay);
|
||||
@@ -63,8 +67,11 @@ export class CodeActionOracle {
|
||||
}, this._delay);
|
||||
}
|
||||
|
||||
private _getRangeOfMarker(selection: Selection): Range {
|
||||
private _getRangeOfMarker(selection: Selection): Range | undefined {
|
||||
const model = this._editor.getModel();
|
||||
if (!model) {
|
||||
return undefined;
|
||||
}
|
||||
for (const marker of this._markerService.read({ resource: model.uri })) {
|
||||
if (Range.intersectRanges(marker, selection)) {
|
||||
return Range.lift(marker);
|
||||
@@ -76,7 +83,7 @@ export class CodeActionOracle {
|
||||
private _getRangeOfSelectionUnlessWhitespaceEnclosed(trigger: CodeActionTrigger): Selection | undefined {
|
||||
const model = this._editor.getModel();
|
||||
const selection = this._editor.getSelection();
|
||||
if (selection.isEmpty() && !(trigger.filter && trigger.filter.includeSourceActions)) {
|
||||
if (model && selection && selection.isEmpty() && !(trigger.filter && trigger.filter.includeSourceActions)) {
|
||||
const { lineNumber, column } = selection.getPosition();
|
||||
const line = model.getLineContent(lineNumber);
|
||||
if (line.length === 0) {
|
||||
@@ -99,7 +106,7 @@ export class CodeActionOracle {
|
||||
}
|
||||
}
|
||||
}
|
||||
return selection;
|
||||
return selection ? selection : undefined;
|
||||
}
|
||||
|
||||
private _createEventAndSignalChange(trigger: CodeActionTrigger, selection: Selection | undefined): Thenable<CodeAction[] | undefined> {
|
||||
@@ -114,6 +121,17 @@ export class CodeActionOracle {
|
||||
return Promise.resolve(undefined);
|
||||
} else {
|
||||
const model = this._editor.getModel();
|
||||
if (!model) {
|
||||
// cancel
|
||||
this._signalChange({
|
||||
trigger,
|
||||
rangeOrSelection: undefined,
|
||||
position: undefined,
|
||||
actions: undefined,
|
||||
});
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
const markerRange = this._getRangeOfMarker(selection);
|
||||
const position = markerRange ? markerRange.getStartPosition() : selection.getStartPosition();
|
||||
const actions = createCancelablePromise(token => getCodeActions(model, selection, trigger, token));
|
||||
@@ -135,16 +153,16 @@ export class CodeActionOracle {
|
||||
|
||||
export interface CodeActionsComputeEvent {
|
||||
trigger: CodeActionTrigger;
|
||||
rangeOrSelection: Range | Selection;
|
||||
position: Position;
|
||||
actions: CancelablePromise<CodeAction[]>;
|
||||
rangeOrSelection: Range | Selection | undefined;
|
||||
position: Position | undefined;
|
||||
actions: CancelablePromise<CodeAction[]> | undefined;
|
||||
}
|
||||
|
||||
export class CodeActionModel {
|
||||
|
||||
private _editor: ICodeEditor;
|
||||
private _markerService: IMarkerService;
|
||||
private _codeActionOracle: CodeActionOracle;
|
||||
private _codeActionOracle?: CodeActionOracle;
|
||||
private _onDidChangeFixes = new Emitter<CodeActionsComputeEvent>();
|
||||
private _disposables: IDisposable[] = [];
|
||||
private readonly _supportedCodeActions: IContextKey<string>;
|
||||
@@ -179,12 +197,13 @@ export class CodeActionModel {
|
||||
this._onDidChangeFixes.fire(undefined);
|
||||
}
|
||||
|
||||
if (this._editor.getModel()
|
||||
&& CodeActionProviderRegistry.has(this._editor.getModel())
|
||||
const model = this._editor.getModel();
|
||||
if (model
|
||||
&& CodeActionProviderRegistry.has(model)
|
||||
&& !this._editor.getConfiguration().readOnly) {
|
||||
|
||||
const supportedActions: string[] = [];
|
||||
for (const provider of CodeActionProviderRegistry.all(this._editor.getModel())) {
|
||||
for (const provider of CodeActionProviderRegistry.all(model)) {
|
||||
if (Array.isArray(provider.providedCodeActionKinds)) {
|
||||
supportedActions.push(...provider.providedCodeActionKinds);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
|
||||
readonly onClick: Event<{ x: number, y: number }> = this._onClick.event;
|
||||
|
||||
private _position: IContentWidgetPosition;
|
||||
private _model: CodeActionsComputeEvent;
|
||||
private _position: IContentWidgetPosition | null;
|
||||
private _model: CodeActionsComputeEvent | null;
|
||||
private _futureFixes = new CancellationTokenSource();
|
||||
|
||||
constructor(editor: ICodeEditor) {
|
||||
@@ -40,7 +40,7 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
this._disposables.push(this._editor.onDidChangeModelLanguage(_ => this._futureFixes.cancel()));
|
||||
this._disposables.push(this._editor.onDidChangeModelContent(_ => {
|
||||
// cancel when the line in question has been removed
|
||||
if (this._model && this.model.position.lineNumber >= this._editor.getModel().getLineCount()) {
|
||||
if (this._model && (!this.model.position || this.model.position.lineNumber >= this._editor.getModel().getLineCount())) {
|
||||
this._futureFixes.cancel();
|
||||
}
|
||||
}));
|
||||
@@ -96,7 +96,7 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
return this._domNode;
|
||||
}
|
||||
|
||||
getPosition(): IContentWidgetPosition {
|
||||
getPosition(): IContentWidgetPosition | null {
|
||||
return this._position;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
} else {
|
||||
this.hide();
|
||||
}
|
||||
}).catch(err => {
|
||||
}).catch(() => {
|
||||
this.hide();
|
||||
});
|
||||
}
|
||||
@@ -148,6 +148,9 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
|
||||
if (!config.contribInfo.lightbulbEnabled) {
|
||||
return;
|
||||
}
|
||||
if (!this._model.position) {
|
||||
return;
|
||||
}
|
||||
const { lineNumber, column } = this._model.position;
|
||||
const model = this._editor.getModel();
|
||||
if (!model) {
|
||||
|
||||
@@ -74,12 +74,12 @@ export abstract class AbstractUpdateService implements IUpdateService {
|
||||
this.setState(State.Idle(this.getUpdateType()));
|
||||
|
||||
// Start checking for updates after 30 seconds
|
||||
this.scheduleCheckForUpdates(30 * 1000).then(null, err => this.logService.error(err));
|
||||
this.scheduleCheckForUpdates(30 * 1000).then(undefined, err => this.logService.error(err));
|
||||
}
|
||||
|
||||
private getProductQuality(): string {
|
||||
private getProductQuality(): string | undefined {
|
||||
const quality = this.configurationService.getValue<string>('update.channel');
|
||||
return quality === 'none' ? null : product.quality;
|
||||
return quality === 'none' ? undefined : product.quality;
|
||||
}
|
||||
|
||||
private scheduleCheckForUpdates(delay = 60 * 60 * 1000): Thenable<void> {
|
||||
@@ -95,7 +95,7 @@ export abstract class AbstractUpdateService implements IUpdateService {
|
||||
this.logService.trace('update#checkForUpdates, state = ', this.state.type);
|
||||
|
||||
if (this.state.type !== StateType.Idle) {
|
||||
return TPromise.as(null);
|
||||
return TPromise.as(void 0);
|
||||
}
|
||||
|
||||
return this.throttler.queue(() => TPromise.as(this.doCheckForUpdates(context)));
|
||||
@@ -105,35 +105,35 @@ export abstract class AbstractUpdateService implements IUpdateService {
|
||||
this.logService.trace('update#downloadUpdate, state = ', this.state.type);
|
||||
|
||||
if (this.state.type !== StateType.AvailableForDownload) {
|
||||
return TPromise.as(null);
|
||||
return TPromise.as(void 0);
|
||||
}
|
||||
|
||||
return this.doDownloadUpdate(this.state);
|
||||
}
|
||||
|
||||
protected doDownloadUpdate(state: AvailableForDownload): TPromise<void> {
|
||||
return TPromise.as(null);
|
||||
return TPromise.as(void 0);
|
||||
}
|
||||
|
||||
applyUpdate(): TPromise<void> {
|
||||
this.logService.trace('update#applyUpdate, state = ', this.state.type);
|
||||
|
||||
if (this.state.type !== StateType.Downloaded) {
|
||||
return TPromise.as(null);
|
||||
return TPromise.as(void 0);
|
||||
}
|
||||
|
||||
return this.doApplyUpdate();
|
||||
}
|
||||
|
||||
protected doApplyUpdate(): TPromise<void> {
|
||||
return TPromise.as(null);
|
||||
return TPromise.as(void 0);
|
||||
}
|
||||
|
||||
quitAndInstall(): TPromise<void> {
|
||||
this.logService.trace('update#quitAndInstall, state = ', this.state.type);
|
||||
|
||||
if (this.state.type !== StateType.Ready) {
|
||||
return TPromise.as(null);
|
||||
return TPromise.as(void 0);
|
||||
}
|
||||
|
||||
this.logService.trace('update#quitAndInstall(): before lifecycle quit()');
|
||||
@@ -148,7 +148,7 @@ export abstract class AbstractUpdateService implements IUpdateService {
|
||||
this.doQuitAndInstall();
|
||||
});
|
||||
|
||||
return TPromise.as(null);
|
||||
return TPromise.as(void 0);
|
||||
}
|
||||
|
||||
isLatestVersion(): TPromise<boolean | undefined> {
|
||||
|
||||
@@ -36,7 +36,11 @@ export class ElectronURLListener {
|
||||
];
|
||||
|
||||
const buffer = rawBuffer.map(uriFromRawUrl).filter(uri => !!uri);
|
||||
const flush = () => buffer.forEach(uri => urlService.open(uri));
|
||||
const flush = () => buffer.forEach(uri => {
|
||||
if (uri) {
|
||||
urlService.open(uri);
|
||||
}
|
||||
});
|
||||
|
||||
app.setAsDefaultProtocolClient(product.urlProtocol, process.execPath, ['--open-url', '--']);
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ export class NotificationsModel extends Disposable implements INotificationsMode
|
||||
}
|
||||
}
|
||||
|
||||
private findNotification(item: INotificationViewItem): INotificationViewItem {
|
||||
private findNotification(item: INotificationViewItem): INotificationViewItem | undefined {
|
||||
for (let i = 0; i < this._notifications.length; i++) {
|
||||
const notification = this._notifications[i];
|
||||
if (notification.equals(item)) {
|
||||
@@ -136,7 +136,7 @@ export class NotificationsModel extends Disposable implements INotificationsMode
|
||||
return void 0;
|
||||
}
|
||||
|
||||
private createViewItem(notification: INotification): INotificationViewItem {
|
||||
private createViewItem(notification: INotification): INotificationViewItem | null {
|
||||
const item = NotificationViewItem.create(notification);
|
||||
if (!item) {
|
||||
return null;
|
||||
@@ -340,7 +340,7 @@ export class NotificationViewItem extends Disposable implements INotificationVie
|
||||
private readonly _onDidLabelChange: Emitter<INotificationViewItemLabelChangeEvent> = this._register(new Emitter<INotificationViewItemLabelChangeEvent>());
|
||||
get onDidLabelChange(): Event<INotificationViewItemLabelChangeEvent> { return this._onDidLabelChange.event; }
|
||||
|
||||
static create(notification: INotification): INotificationViewItem {
|
||||
static create(notification: INotification): INotificationViewItem | null {
|
||||
if (!notification || !notification.message || isPromiseCanceledError(notification.message)) {
|
||||
return null; // we need a message to show
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user