提交 6d973fef 编写于 作者: M Matt Bierner

Strict null work on main thread

上级 f9687fc5
......@@ -23,6 +23,6 @@ export interface IBulkEditResult {
export interface IBulkEditService {
_serviceBrand: any;
apply(edit: WorkspaceEdit, options: IBulkEditOptions): Promise<IBulkEditResult>;
apply(edit: WorkspaceEdit, options?: IBulkEditOptions): Promise<IBulkEditResult>;
}
......@@ -576,7 +576,7 @@ export class SimpleBulkEditService implements IBulkEditService {
//
}
apply(workspaceEdit: WorkspaceEdit, options: IBulkEditOptions): Promise<IBulkEditResult> {
apply(workspaceEdit: WorkspaceEdit, options?: IBulkEditOptions): Promise<IBulkEditResult> {
let edits = new Map<ITextModel, TextEdit[]>();
......
......@@ -419,7 +419,7 @@ export interface IBaseStat {
* A unique identifier thet represents the
* current state of the file or directory.
*/
etag: string;
etag?: string;
/**
* The resource is readonly.
......
......@@ -109,13 +109,17 @@ export class MainThreadDecorations implements MainThreadDecorationsShape {
}
$onDidChange(handle: number, resources: UriComponents[]): void {
const [emitter] = this._provider.get(handle);
emitter.fire(resources && resources.map(URI.revive));
const provider = this._provider.get(handle);
if (provider) {
const [emitter] = provider;
emitter.fire(resources && resources.map(URI.revive));
}
}
$unregisterDecorationProvider(handle: number): void {
if (this._provider.has(handle)) {
dispose(this._provider.get(handle));
const provider = this._provider.get(handle);
if (provider) {
dispose(provider);
this._provider.delete(handle);
}
}
......
......@@ -130,14 +130,14 @@ export class MainThreadDocuments implements MainThreadDocumentsShape {
private _shouldHandleFileEvent(e: TextFileModelChangeEvent): boolean {
const model = this._modelService.getModel(e.resource);
return model && shouldSynchronizeModel(model);
return !!model && shouldSynchronizeModel(model);
}
private _onModelAdded(model: ITextModel): void {
// Same filter as in mainThreadEditorsTracker
if (!shouldSynchronizeModel(model)) {
// don't synchronize too large models
return null;
return;
}
let modelUrl = model.uri;
this._modelIsSynced[modelUrl.toString()] = true;
......
......@@ -7,7 +7,7 @@ import { Emitter, Event } from 'vs/base/common/event';
import { IDisposable, combinedDisposable, dispose } from 'vs/base/common/lifecycle';
import { values } from 'vs/base/common/map';
import { URI } from 'vs/base/common/uri';
import { ICodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser';
import { ICodeEditor, isCodeEditor, isDiffEditor, IActiveCodeEditor } from 'vs/editor/browser/editorBrowser';
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { IEditor } from 'vs/editor/common/editorCommon';
......@@ -70,7 +70,7 @@ class TextEditorSnapshot {
readonly id: string;
constructor(
readonly editor: ICodeEditor,
readonly editor: IActiveCodeEditor,
) {
this.id = `${editor.getId()},${editor.getModel().id}`;
}
......@@ -85,8 +85,8 @@ class DocumentAndEditorStateDelta {
readonly addedDocuments: ITextModel[],
readonly removedEditors: TextEditorSnapshot[],
readonly addedEditors: TextEditorSnapshot[],
readonly oldActiveEditor: string,
readonly newActiveEditor: string,
readonly oldActiveEditor: string | undefined,
readonly newActiveEditor: string | undefined,
) {
this.isEmpty = this.removedDocuments.length === 0
&& this.addedDocuments.length === 0
......@@ -131,7 +131,7 @@ class DocumentAndEditorState {
constructor(
readonly documents: Set<ITextModel>,
readonly textEditors: Map<string, TextEditorSnapshot>,
readonly activeEditor: string,
readonly activeEditor: string | undefined,
) {
//
}
......@@ -230,14 +230,14 @@ class MainThreadDocumentAndEditorStateComputer {
// editor: only take those that have a not too large model
const editors = new Map<string, TextEditorSnapshot>();
let activeEditor: string | null = null;
let activeEditor: string | undefined = undefined;
for (const editor of this._codeEditorService.listCodeEditors()) {
if (editor.isSimpleWidget) {
continue;
}
const model = editor.getModel();
if (model && shouldSynchronizeModel(model)
if (editor.hasModel() && model && shouldSynchronizeModel(model)
&& !model.isDisposed() // model disposed
&& Boolean(this._modelService.getModel(model.uri)) // model disposing, the flag didn't flip yet but the model service already removed it
) {
......@@ -282,7 +282,7 @@ class MainThreadDocumentAndEditorStateComputer {
}
}
private _getActiveEditorFromPanel(): IEditor {
private _getActiveEditorFromPanel(): IEditor | undefined {
let panel = this._panelService.getActivePanel();
if (panel instanceof BaseTextEditor && isCodeEditor(panel.getControl())) {
return panel.getControl();
......@@ -444,8 +444,8 @@ export class MainThreadDocumentsAndEditors {
};
}
private _findEditorPosition(editor: MainThreadTextEditor): EditorViewColumn {
for (let workbenchEditor of this._editorService.visibleControls) {
private _findEditorPosition(editor: MainThreadTextEditor): EditorViewColumn | undefined {
for (const workbenchEditor of this._editorService.visibleControls) {
if (editor.matches(workbenchEditor)) {
return editorGroupToViewColumn(this._editorGroupService, workbenchEditor.group);
}
......@@ -453,8 +453,8 @@ export class MainThreadDocumentsAndEditors {
return undefined;
}
findTextEditorIdFor(editor: IWorkbenchEditor): string {
for (let id in this._textEditors) {
findTextEditorIdFor(editor: IWorkbenchEditor): string | undefined {
for (const id in this._textEditors) {
if (this._textEditors[id].matches(editor)) {
return id;
}
......
......@@ -187,7 +187,7 @@ export class MainThreadTextEditor {
private _focusTracker: IFocusTracker;
private _codeEditorListeners: IDisposable[];
private _properties: MainThreadTextEditorProperties | null;
private _properties: MainThreadTextEditorProperties;
private readonly _onPropertiesChanged: Emitter<IEditorPropertiesChangeData>;
constructor(
......@@ -204,7 +204,6 @@ export class MainThreadTextEditor {
this._modelService = modelService;
this._codeEditorListeners = [];
this._properties = null;
this._onPropertiesChanged = new Emitter<IEditorPropertiesChangeData>();
this._modelListeners = [];
......@@ -300,7 +299,7 @@ export class MainThreadTextEditor {
return !!this._codeEditor;
}
public getProperties(): MainThreadTextEditorProperties | null {
public getProperties(): MainThreadTextEditorProperties {
return this._properties;
}
......@@ -316,7 +315,7 @@ export class MainThreadTextEditor {
const newSelections = selections.map(Selection.liftSelection);
this._setProperties(
new MainThreadTextEditorProperties(newSelections, this._properties!.options, this._properties!.visibleRanges),
new MainThreadTextEditorProperties(newSelections, this._properties.options, this._properties.visibleRanges),
null
);
}
......
......@@ -36,7 +36,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
private _documentsAndEditors: MainThreadDocumentsAndEditors;
private _toDispose: IDisposable[];
private _textEditorsListenersMap: { [editorId: string]: IDisposable[]; };
private _editorPositionData: ITextEditorPositionData;
private _editorPositionData: ITextEditorPositionData | null;
private _registeredDecorationTypes: { [decorationType: string]: boolean; };
constructor(
......@@ -145,7 +145,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
options: { preserveFocus: false }
}, viewColumnToEditorGroup(this._editorGroupService, position)).then(() => { return; });
}
return undefined;
return Promise.resolve();
}
$tryHideEditor(id: string): Promise<void> {
......@@ -158,7 +158,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
}
}
}
return undefined;
return Promise.resolve();
}
$trySetSelections(id: string, selections: ISelection[]): Promise<void> {
......@@ -192,7 +192,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
return Promise.reject(disposed(`TextEditor(${id})`));
}
this._documentsAndEditors.getEditor(id).revealRange(range, revealType);
return undefined;
return Promise.resolve();
}
$trySetOptions(id: string, options: ITextEditorConfigurationUpdate): Promise<void> {
......
......@@ -198,7 +198,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
$registerHoverProvider(handle: number, selector: ISerializedDocumentFilter[]): void {
this._registrations[handle] = modes.HoverProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.HoverProvider>{
provideHover: (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.Hover> => {
provideHover: (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.Hover | undefined> => {
return this._proxy.$provideHover(handle, model.uri, position, token);
}
});
......@@ -208,7 +208,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
$registerDocumentHighlightProvider(handle: number, selector: ISerializedDocumentFilter[]): void {
this._registrations[handle] = modes.DocumentHighlightProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.DocumentHighlightProvider>{
provideDocumentHighlights: (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.DocumentHighlight[]> => {
provideDocumentHighlights: (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.DocumentHighlight[] | undefined> => {
return this._proxy.$provideDocumentHighlights(handle, model.uri, position, token);
}
});
......@@ -243,7 +243,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
$registerDocumentFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], displayName: string): void {
this._registrations[handle] = modes.DocumentFormattingEditProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.DocumentFormattingEditProvider>{
displayName,
provideDocumentFormattingEdits: (model: ITextModel, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[]> => {
provideDocumentFormattingEdits: (model: ITextModel, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[] | undefined> => {
return this._proxy.$provideDocumentFormattingEdits(handle, model.uri, options, token);
}
});
......@@ -252,7 +252,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
$registerRangeFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], displayName: string): void {
this._registrations[handle] = modes.DocumentRangeFormattingEditProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.DocumentRangeFormattingEditProvider>{
displayName,
provideDocumentRangeFormattingEdits: (model: ITextModel, range: EditorRange, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[]> => {
provideDocumentRangeFormattingEdits: (model: ITextModel, range: EditorRange, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[] | undefined> => {
return this._proxy.$provideDocumentRangeFormattingEdits(handle, model.uri, range, options, token);
}
});
......@@ -263,7 +263,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
autoFormatTriggerCharacters,
provideOnTypeFormattingEdits: (model: ITextModel, position: EditorPosition, ch: string, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[]> => {
provideOnTypeFormattingEdits: (model: ITextModel, position: EditorPosition, ch: string, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[] | undefined> => {
return this._proxy.$provideOnTypeFormattingEdits(handle, model.uri, position, ch, options, token);
}
});
......@@ -272,7 +272,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
// --- navigate type
$registerNavigateTypeSupport(handle: number): void {
let lastResultId: number;
let lastResultId: number | undefined;
this._registrations[handle] = search.WorkspaceSymbolProviderRegistry.register(<search.IWorkspaceSymbolProvider>{
provideWorkspaceSymbols: (search: string, token: CancellationToken): Promise<search.IWorkspaceSymbol[]> => {
return this._proxy.$provideWorkspaceSymbols(handle, search, token).then(result => {
......@@ -298,7 +298,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
return this._proxy.$provideRenameEdits(handle, model.uri, position, newName, token).then(reviveWorkspaceEditDto);
},
resolveRenameLocation: supportResolveLocation
? (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.RenameLocation> => this._proxy.$resolveRenameLocation(handle, model.uri, position, token)
? (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.RenameLocation | undefined> => this._proxy.$resolveRenameLocation(handle, model.uri, position, token)
: undefined
});
}
......
......@@ -45,7 +45,10 @@ export class MainThreadTreeViews extends Disposable implements MainThreadTreeVie
return this.viewsService.openView(treeViewId, options.focus)
.then(() => {
const viewer = this.getTreeView(treeViewId);
return this.reveal(viewer, this._dataProviders.get(treeViewId), item, parentChain, options);
if (viewer) {
return this.reveal(viewer, this._dataProviders.get(treeViewId)!, item, parentChain, options);
}
return undefined;
});
}
......@@ -56,7 +59,7 @@ export class MainThreadTreeViews extends Disposable implements MainThreadTreeVie
const itemsToRefresh = dataProvider.getItemsToRefresh(itemsToRefreshByHandle);
return viewer.refresh(itemsToRefresh.length ? itemsToRefresh : undefined);
}
return null;
return Promise.resolve();
}
$setMessage(treeViewId: string, message: string | IMarkdownString): void {
......
......@@ -68,14 +68,14 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
handle: WebviewPanelHandle,
viewType: string,
title: string,
showOptions: { viewColumn: EditorViewColumn | null, preserveFocus: boolean },
showOptions: { viewColumn?: EditorViewColumn, preserveFocus?: boolean },
options: WebviewInputOptions,
extensionId: ExtensionIdentifier,
extensionLocation: UriComponents
): void {
const mainThreadShowOptions: ICreateWebViewShowOptions = Object.create(null);
if (showOptions) {
mainThreadShowOptions.preserveFocus = showOptions.preserveFocus;
mainThreadShowOptions.preserveFocus = !!showOptions.preserveFocus;
mainThreadShowOptions.group = viewColumnToEditorGroup(this._editorGroupService, showOptions.viewColumn);
}
......@@ -129,7 +129,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
const targetGroup = this._editorGroupService.getGroup(viewColumnToEditorGroup(this._editorGroupService, showOptions.viewColumn));
this._webviewService.revealWebview(webview, targetGroup || this._editorGroupService.activeGroup, showOptions.preserveFocus);
this._webviewService.revealWebview(webview, targetGroup || this._editorGroupService.activeGroup, !!showOptions.preserveFocus);
}
public $postMessage(handle: WebviewPanelHandle, message: any): Promise<boolean> {
......@@ -137,7 +137,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
const editors = this._editorService.visibleControls
.filter(e => e instanceof WebviewEditor)
.map(e => e as WebviewEditor)
.filter(e => e.input.matches(webview));
.filter(e => e.input!.matches(webview));
for (const editor of editors) {
editor.sendMessage(message);
......@@ -216,7 +216,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
let newActiveWebview: { input: WebviewEditorInput, handle: WebviewPanelHandle } | undefined = undefined;
if (activeEditor && activeEditor.input instanceof WebviewEditorInput) {
for (const handle of map.keys(this._webviews)) {
const input = this._webviews.get(handle);
const input = this._webviews.get(handle)!;
if (input.matches(activeEditor.input)) {
newActiveWebview = { input, handle };
break;
......@@ -240,7 +240,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
if (oldActiveWebview) {
this._proxy.$onDidChangeWebviewPanelViewState(this._activeWebview, {
active: false,
visible: this._editorService.visibleControls.some(editor => editor.input && editor.input.matches(oldActiveWebview)),
visible: this._editorService.visibleControls.some(editor => !!editor.input && editor.input.matches(oldActiveWebview)),
position: editorGroupToViewColumn(this._editorGroupService, oldActiveWebview.group),
});
}
......
......@@ -443,7 +443,7 @@ export namespace TextEdit {
export function to(edit: modes.TextEdit): types.TextEdit {
const result = new types.TextEdit(Range.to(edit.range), edit.text);
result.newEol = typeof edit.eol === 'undefined' ? undefined : EndOfLine.to(edit.eol);
result.newEol = (typeof edit.eol === 'undefined' ? undefined : EndOfLine.to(edit.eol))!;
return result;
}
}
......@@ -457,7 +457,7 @@ export namespace WorkspaceEdit {
const [uri, uriOrEdits] = entry;
if (Array.isArray(uriOrEdits)) {
// text edits
const doc = documents ? documents.getDocument(uri.toString()) : undefined;
const doc = documents && uri ? documents.getDocument(uri.toString()) : undefined;
result.edits.push(<ResourceTextEditDto>{ resource: uri, modelVersionId: doc && doc.version, edits: uriOrEdits.map(TextEdit.from) });
} else {
// resource edits
......@@ -986,6 +986,9 @@ export namespace GlobPattern {
export namespace LanguageSelector {
export function from(selector: undefined): undefined;
export function from(selector: vscode.DocumentSelector): languageSelector.LanguageSelector;
export function from(selector: vscode.DocumentSelector | undefined): languageSelector.LanguageSelector | undefined;
export function from(selector: vscode.DocumentSelector | undefined): languageSelector.LanguageSelector | undefined {
if (!selector) {
return undefined;
......@@ -997,7 +1000,7 @@ export namespace LanguageSelector {
return <languageSelector.LanguageFilter>{
language: selector.language,
scheme: selector.scheme,
pattern: GlobPattern.from(selector.pattern),
pattern: typeof selector.pattern === 'undefined' ? undefined : GlobPattern.from(selector.pattern),
exclusive: selector.exclusive
};
}
......
......@@ -948,9 +948,9 @@ export class SymbolInformation {
kind: SymbolKind;
containerName: string | undefined;
constructor(name: string, kind: SymbolKind, containerName: string, location: Location);
constructor(name: string, kind: SymbolKind, containerName: string | undefined, location: Location);
constructor(name: string, kind: SymbolKind, range: Range, uri?: URI, containerName?: string);
constructor(name: string, kind: SymbolKind, rangeOrContainer: string | Range, locationOrUri?: Location | URI, containerName?: string) {
constructor(name: string, kind: SymbolKind, rangeOrContainer: string | undefined | Range, locationOrUri?: Location | URI, containerName?: string) {
this.name = name;
this.kind = kind;
this.containerName = containerName;
......
......@@ -27,7 +27,7 @@ export interface IResourceDescriptor {
readonly resource: URI;
readonly name: string;
readonly size: number;
readonly etag: string;
readonly etag?: string;
readonly mime: string;
}
......
......@@ -16,7 +16,7 @@ export class BinaryEditorModel extends EditorModel {
private name: string;
private resource: URI;
private size: number;
private etag: string;
private etag?: string;
private mime: string;
constructor(
......@@ -70,7 +70,7 @@ export class BinaryEditorModel extends EditorModel {
/**
* The etag of the binary resource if known.
*/
getETag(): string {
getETag(): string | undefined {
return this.etag;
}
......
......@@ -31,7 +31,7 @@ export interface IDecoration {
export interface IDecorationsProvider {
readonly label: string;
readonly onDidChange: Event<URI[]>;
provideDecorations(uri: URI, token: CancellationToken): IDecorationData | Promise<IDecorationData> | undefined;
provideDecorations(uri: URI, token: CancellationToken): IDecorationData | Promise<IDecorationData | undefined> | undefined;
}
export interface IResourceDecorationChangeEvent {
......
......@@ -301,7 +301,7 @@ class DecorationProviderWrapper {
const source = new CancellationTokenSource();
const dataOrThenable = this._provider.provideDecorations(uri, source.token);
if (!isThenable(dataOrThenable)) {
if (!isThenable<IDecorationData | Promise<IDecorationData | undefined> | undefined>(dataOrThenable)) {
// sync -> we have a result now
return this._keepItem(uri, dataOrThenable);
......
......@@ -37,13 +37,13 @@ const NO_OP_VOID_PROMISE = Promise.resolve<void>(undefined);
schema.properties.engines.properties.vscode.default = `^${pkg.version}`;
let productAllowProposedApi: Set<string> = null;
let productAllowProposedApi: Set<string> | null = null;
function allowProposedApiFromProduct(id: ExtensionIdentifier): boolean {
// create set if needed
if (productAllowProposedApi === null) {
if (!productAllowProposedApi) {
productAllowProposedApi = new Set<string>();
if (isNonEmptyArray(product.extensionAllowedProposedApi)) {
product.extensionAllowedProposedApi.forEach((id) => productAllowProposedApi.add(ExtensionIdentifier.toKey(id)));
product.extensionAllowedProposedApi.forEach((id) => productAllowProposedApi!.add(ExtensionIdentifier.toKey(id)));
}
}
return productAllowProposedApi.has(ExtensionIdentifier.toKey(id));
......@@ -167,7 +167,7 @@ export class ExtensionService extends Disposable implements IExtensionService {
}
while (this._deltaExtensionsQueue.length > 0) {
const item = this._deltaExtensionsQueue.shift();
const item = this._deltaExtensionsQueue.shift()!;
try {
this._inHandleDeltaExtensions = true;
await this._deltaExtensions(item.toAdd, item.toRemove);
......@@ -856,7 +856,7 @@ export class ExtensionService extends Disposable implements IExtensionService {
if (!this._extensionsMessages.has(extensionKey)) {
this._extensionsMessages.set(extensionKey, []);
}
this._extensionsMessages.get(extensionKey).push({
this._extensionsMessages.get(extensionKey)!.push({
type: severity,
message: message,
extensionId: null,
......
......@@ -189,8 +189,8 @@ export class ExtensionDescriptionRegistry {
return this._extensionsArr.slice(0);
}
public getExtensionDescription(extensionId: ExtensionIdentifier | string): IExtensionDescription | null {
public getExtensionDescription(extensionId: ExtensionIdentifier | string): IExtensionDescription | undefined {
const extension = this._extensionsMap.get(ExtensionIdentifier.toKey(extensionId));
return extension ? extension : null;
return extension ? extension : undefined;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册