Strict null check work for extHostTypes

This commit is contained in:
Matt Bierner
2019-02-07 21:25:44 -08:00
parent fdc710af64
commit 40c4d2b743
8 changed files with 65 additions and 53 deletions

View File

@@ -219,7 +219,7 @@ export function createApiFactory(
});
},
registerDiffInformationCommand: proposedApiFunction(extension, (id: string, callback: (diff: vscode.LineChange[], ...args: any[]) => any, thisArg?: any): vscode.Disposable => {
return extHostCommands.registerCommand(true, id, async (...args: any[]) => {
return extHostCommands.registerCommand(true, id, async (...args: any[]): Promise<any> => {
let activeTextEditor = extHostEditors.getActiveTextEditor();
if (!activeTextEditor) {
console.warn('Cannot execute ' + id + ' because there is no active text editor.');
@@ -242,9 +242,9 @@ export function createApiFactory(
const env: typeof vscode.env = Object.freeze({
get machineId() { return initData.telemetryInfo.machineId; },
get sessionId() { return initData.telemetryInfo.sessionId; },
get language() { return platform.language; },
get language() { return platform.language!; },
get appName() { return product.nameLong; },
get appRoot() { return initData.environment.appRoot.fsPath; },
get appRoot() { return initData.environment.appRoot!.fsPath; },
get logLevel() {
checkProposedApiEnabled(extension);
return typeConverters.LogLevel.to(extHostLogService.getLevel());
@@ -263,8 +263,8 @@ export function createApiFactory(
// namespace: extensions
const extensions: typeof vscode.extensions = {
getExtension(extensionId: string): Extension<any> {
let desc = extensionRegistry.getExtensionDescription(extensionId);
getExtension(extensionId: string): Extension<any> | undefined {
const desc = extensionRegistry.getExtensionDescription(extensionId);
if (desc) {
return new Extension(extensionService, desc);
}
@@ -443,7 +443,7 @@ export function createApiFactory(
return extHostMessageService.showMessage(extension, Severity.Error, message, first, rest);
},
showQuickPick(items: any, options: vscode.QuickPickOptions, token?: vscode.CancellationToken): any {
return extHostQuickOpen.showQuickPick(items, extension.enableProposedApi, options, token);
return extHostQuickOpen.showQuickPick(items, !!extension.enableProposedApi, options, token);
},
showWorkspaceFolderPick(options: vscode.WorkspaceFolderPickOptions) {
return extHostQuickOpen.showWorkspaceFolderPick(options);

View File

@@ -60,7 +60,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
// the actual implementation for #set
this._checkDisposed();
let toSync: vscode.Uri[];
let toSync: vscode.Uri[] = [];
let hasChanged = true;
if (first instanceof URI) {
@@ -81,7 +81,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
} else if (Array.isArray(first)) {
// update many rows
toSync = [];
let lastUri: vscode.Uri;
let lastUri: vscode.Uri | undefined;
// ensure stable-sort
mergeSort(first, DiagnosticCollection._compareIndexedTuplesByUri);
@@ -255,7 +255,7 @@ export class ExtHostDiagnostics implements ExtHostDiagnosticsShape {
this._proxy = mainContext.getProxy(MainContext.MainThreadDiagnostics);
}
createDiagnosticCollection(name: string): vscode.DiagnosticCollection {
createDiagnosticCollection(name?: string): vscode.DiagnosticCollection {
let { _collections, _proxy, _onDidChangeDiagnostics } = this;
let owner: string;
if (!name) {
@@ -272,7 +272,7 @@ export class ExtHostDiagnostics implements ExtHostDiagnosticsShape {
const result = new class extends DiagnosticCollection {
constructor() {
super(name, owner, ExtHostDiagnostics._maxDiagnosticsPerFile, _proxy, _onDidChangeDiagnostics);
super(name!, owner, ExtHostDiagnostics._maxDiagnosticsPerFile, _proxy, _onDidChangeDiagnostics);
_collections.set(owner, this);
}
dispose() {
@@ -286,6 +286,7 @@ export class ExtHostDiagnostics implements ExtHostDiagnosticsShape {
getDiagnostics(resource: vscode.Uri): vscode.Diagnostic[];
getDiagnostics(): [vscode.Uri, vscode.Diagnostic[]][];
getDiagnostics(resource?: vscode.Uri): vscode.Diagnostic[] | [vscode.Uri, vscode.Diagnostic[]][];
getDiagnostics(resource?: vscode.Uri): vscode.Diagnostic[] | [vscode.Uri, vscode.Diagnostic[]][] {
if (resource) {
return this._getDiagnostics(resource);

View File

@@ -42,7 +42,7 @@ export class ExtHostEditors implements ExtHostEditorsShape {
this._extHostDocumentsAndEditors.onDidChangeActiveTextEditor(e => this._onDidChangeActiveTextEditor.fire(e));
}
getActiveTextEditor(): ExtHostTextEditor {
getActiveTextEditor(): ExtHostTextEditor | undefined {
return this._extHostDocumentsAndEditors.activeEditor();
}

View File

@@ -28,6 +28,7 @@ import * as marked from 'vs/base/common/marked/marked';
import { parse } from 'vs/base/common/marshalling';
import { cloneAndChange } from 'vs/base/common/objects';
import { LogLevel as _MainLogLevel } from 'vs/platform/log/common/log';
import { coalesce } from 'vs/base/common/arrays';
export interface PositionLike {
line: number;
@@ -64,7 +65,10 @@ export namespace Selection {
}
export namespace Range {
export function from(range: RangeLike): IRange {
export function from(range: undefined): undefined;
export function from(range: RangeLike): IRange;
export function from(range: RangeLike | undefined): IRange | undefined;
export function from(range: RangeLike | undefined): IRange | undefined {
if (!range) {
return undefined;
}
@@ -77,7 +81,10 @@ export namespace Range {
};
}
export function to(range: IRange): types.Range {
export function to(range: undefined): types.Range;
export function to(range: IRange): types.Range;
export function to(range: IRange | undefined): types.Range | undefined;
export function to(range: IRange | undefined): types.Range | undefined {
if (!range) {
return undefined;
}
@@ -96,7 +103,7 @@ export namespace Position {
}
export namespace DiagnosticTag {
export function from(value: vscode.DiagnosticTag): MarkerTag {
export function from(value: vscode.DiagnosticTag): MarkerTag | undefined {
switch (value) {
case types.DiagnosticTag.Unnecessary:
return MarkerTag.Unnecessary;
@@ -114,7 +121,7 @@ export namespace Diagnostic {
code: isString(value.code) || isNumber(value.code) ? String(value.code) : undefined,
severity: DiagnosticSeverity.from(value.severity),
relatedInformation: value.relatedInformation && value.relatedInformation.map(DiagnosticRelatedInformation.from),
tags: Array.isArray(value.tags) ? value.tags.map(DiagnosticTag.from) : undefined,
tags: Array.isArray(value.tags) ? coalesce(value.tags.map(DiagnosticTag.from)) : undefined,
};
}
}
@@ -175,7 +182,7 @@ export namespace ViewColumn {
return ACTIVE_GROUP; // default is always the active group
}
export function to(position?: EditorViewColumn): vscode.ViewColumn {
export function to(position?: EditorViewColumn): vscode.ViewColumn | undefined {
if (typeof position === 'number' && position >= 0) {
return position + 1; // adjust to index (ViewColumn.ONE => 1)
}
@@ -226,13 +233,15 @@ export namespace MarkdownString {
}
// extract uris into a separate object
res.uris = Object.create(null);
const resUris: { [href: string]: UriComponents } = Object.create(null);
res.uris = resUris;
let renderer = new marked.Renderer();
renderer.image = renderer.link = (href: string): string => {
try {
let uri = URI.parse(href, true);
uri = uri.with({ query: _uriMassage(uri.query, res.uris) });
res.uris[href] = uri;
uri = uri.with({ query: _uriMassage(uri.query, resUris) });
resUris[href] = uri;
} catch (e) {
// ignore
}
@@ -284,10 +293,12 @@ export namespace MarkdownString {
export function fromRangeOrRangeWithMessage(ranges: vscode.Range[] | vscode.DecorationOptions[]): IDecorationOptions[] {
if (isDecorationOptionsArr(ranges)) {
return ranges.map(r => {
return ranges.map((r): IDecorationOptions => {
return {
range: Range.from(r.range),
hoverMessage: Array.isArray(r.hoverMessage) ? MarkdownString.fromMany(r.hoverMessage) : r.hoverMessage && MarkdownString.from(r.hoverMessage),
hoverMessage: Array.isArray(r.hoverMessage)
? MarkdownString.fromMany(r.hoverMessage)
: (r.hoverMessage ? MarkdownString.from(r.hoverMessage) : undefined),
renderOptions: <any> /* URI vs Uri */r.renderOptions
};
});
@@ -318,7 +329,7 @@ export namespace ThemableDecorationAttachmentRenderOptions {
}
return {
contentText: options.contentText,
contentIconPath: pathOrURIToURI(options.contentIconPath),
contentIconPath: options.contentIconPath ? pathOrURIToURI(options.contentIconPath) : undefined,
border: options.border,
borderColor: <string | types.ThemeColor>options.borderColor,
fontStyle: options.fontStyle,
@@ -357,11 +368,11 @@ export namespace ThemableDecorationRenderOptions {
color: <string | types.ThemeColor>options.color,
opacity: options.opacity,
letterSpacing: options.letterSpacing,
gutterIconPath: pathOrURIToURI(options.gutterIconPath),
gutterIconPath: options.gutterIconPath ? pathOrURIToURI(options.gutterIconPath) : undefined,
gutterIconSize: options.gutterIconSize,
overviewRulerColor: <string | types.ThemeColor>options.overviewRulerColor,
before: ThemableDecorationAttachmentRenderOptions.from(options.before),
after: ThemableDecorationAttachmentRenderOptions.from(options.after),
before: options.before ? ThemableDecorationAttachmentRenderOptions.from(options.before) : undefined,
after: options.after ? ThemableDecorationAttachmentRenderOptions.from(options.after) : undefined,
};
}
}
@@ -388,10 +399,10 @@ export namespace DecorationRenderOptions {
export function from(options: vscode.DecorationRenderOptions): IDecorationRenderOptions {
return {
isWholeLine: options.isWholeLine,
rangeBehavior: DecorationRangeBehavior.from(options.rangeBehavior),
rangeBehavior: options.rangeBehavior ? DecorationRangeBehavior.from(options.rangeBehavior) : undefined,
overviewRulerLane: options.overviewRulerLane,
light: ThemableDecorationRenderOptions.from(options.light),
dark: ThemableDecorationRenderOptions.from(options.dark),
light: options.light ? ThemableDecorationRenderOptions.from(options.light) : undefined,
dark: options.dark ? ThemableDecorationRenderOptions.from(options.dark) : undefined,
backgroundColor: <string | types.ThemeColor>options.backgroundColor,
outline: options.outline,
@@ -411,11 +422,11 @@ export namespace DecorationRenderOptions {
color: <string | types.ThemeColor>options.color,
opacity: options.opacity,
letterSpacing: options.letterSpacing,
gutterIconPath: pathOrURIToURI(options.gutterIconPath),
gutterIconPath: options.gutterIconPath ? pathOrURIToURI(options.gutterIconPath) : undefined,
gutterIconSize: options.gutterIconSize,
overviewRulerColor: <string | types.ThemeColor>options.overviewRulerColor,
before: ThemableDecorationAttachmentRenderOptions.from(options.before),
after: ThemableDecorationAttachmentRenderOptions.from(options.after),
before: options.before ? ThemableDecorationAttachmentRenderOptions.from(options.before) : undefined,
after: options.after ? ThemableDecorationAttachmentRenderOptions.from(options.after) : undefined,
};
}
}
@@ -432,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 = EndOfLine.to(edit.eol);
result.newEol = typeof edit.eol === 'undefined' ? undefined : EndOfLine.to(edit.eol);
return result;
}
}
@@ -724,9 +735,9 @@ export namespace CompletionItem {
result.preselect = suggestion.preselect;
result.commitCharacters = suggestion.commitCharacters;
result.range = Range.to(suggestion.range);
result.keepWhitespace = Boolean(suggestion.insertTextRules & modes.CompletionItemInsertTextRule.KeepWhitespace);
result.keepWhitespace = typeof suggestion.insertTextRules === 'undefined' ? false : Boolean(suggestion.insertTextRules & modes.CompletionItemInsertTextRule.KeepWhitespace);
// 'inserText'-logic
if (suggestion.insertTextRules & modes.CompletionItemInsertTextRule.InsertAsSnippet) {
if (typeof suggestion.insertTextRules !== 'undefined' && suggestion.insertTextRules & modes.CompletionItemInsertTextRule.InsertAsSnippet) {
result.insertText = new types.SnippetString(suggestion.insertText);
} else {
result.insertText = suggestion.insertText;
@@ -742,7 +753,7 @@ export namespace ParameterInformation {
export function from(info: types.ParameterInformation): modes.ParameterInformation {
return {
label: info.label,
documentation: MarkdownString.fromStrict(info.documentation)
documentation: info.documentation ? MarkdownString.fromStrict(info.documentation) : undefined
};
}
export function to(info: modes.ParameterInformation): types.ParameterInformation {
@@ -758,7 +769,7 @@ export namespace SignatureInformation {
export function from(info: types.SignatureInformation): modes.SignatureInformation {
return {
label: info.label,
documentation: MarkdownString.fromStrict(info.documentation),
documentation: info.documentation ? MarkdownString.fromStrict(info.documentation) : undefined,
parameters: info.parameters && info.parameters.map(ParameterInformation.from)
};
}
@@ -877,7 +888,7 @@ export namespace TextDocumentSaveReason {
export namespace EndOfLine {
export function from(eol: vscode.EndOfLine): EndOfLineSequence {
export function from(eol: vscode.EndOfLine): EndOfLineSequence | undefined {
if (eol === types.EndOfLine.CRLF) {
return EndOfLineSequence.CRLF;
} else if (eol === types.EndOfLine.LF) {
@@ -886,7 +897,7 @@ export namespace EndOfLine {
return undefined;
}
export function to(eol: EndOfLineSequence): vscode.EndOfLine {
export function to(eol: EndOfLineSequence): vscode.EndOfLine | undefined {
if (eol === EndOfLineSequence.CRLF) {
return types.EndOfLine.CRLF;
} else if (eol === EndOfLineSequence.LF) {
@@ -897,7 +908,7 @@ export namespace EndOfLine {
}
export namespace ProgressLocation {
export function from(loc: vscode.ProgressLocation): MainProgressLocation {
export function from(loc: vscode.ProgressLocation): MainProgressLocation | undefined {
switch (loc) {
case types.ProgressLocation.SourceControl: return MainProgressLocation.Scm;
case types.ProgressLocation.Window: return MainProgressLocation.Window;
@@ -935,7 +946,7 @@ export namespace FoldingRangeKind {
export namespace TextEditorOptions {
export function from(options?: vscode.TextDocumentShowOptions): ITextEditorOptions {
export function from(options?: vscode.TextDocumentShowOptions): ITextEditorOptions | undefined {
if (options) {
return {
pinned: typeof options.preview === 'boolean' ? !options.preview : undefined,
@@ -975,7 +986,7 @@ export namespace GlobPattern {
export namespace LanguageSelector {
export function from(selector: vscode.DocumentSelector): languageSelector.LanguageSelector {
export function from(selector: vscode.DocumentSelector): languageSelector.LanguageSelector | undefined {
if (!selector) {
return undefined;
} else if (Array.isArray(selector)) {

View File

@@ -1166,8 +1166,8 @@ export enum CompletionTriggerKind {
}
export interface CompletionContext {
triggerKind: CompletionTriggerKind;
triggerCharacter: string;
readonly triggerKind: CompletionTriggerKind;
readonly triggerCharacter?: string;
}
export enum CompletionItemKind {
@@ -1202,15 +1202,15 @@ export class CompletionItem implements vscode.CompletionItem {
label: string;
kind: CompletionItemKind | undefined;
detail: string;
documentation: string | MarkdownString;
sortText: string;
filterText: string;
preselect: boolean;
detail?: string;
documentation?: string | MarkdownString;
sortText?: string;
filterText?: string;
preselect?: boolean;
insertText: string | SnippetString;
keepWhitespace?: boolean;
range: Range;
commitCharacters: string[];
commitCharacters?: string[];
textEdit: TextEdit;
additionalTextEdits: TextEdit[];
command: vscode.Command;
@@ -1314,7 +1314,7 @@ export enum DecorationRangeBehavior {
}
export namespace TextEditorSelectionChangeKind {
export function fromValue(s: string) {
export function fromValue(s: string | undefined) {
switch (s) {
case 'keyboard': return TextEditorSelectionChangeKind.Keyboard;
case 'mouse': return TextEditorSelectionChangeKind.Mouse;