Enable `strict` typescript compilation

pull/2779/head
Alex Dima 3 years ago
parent a33b7cee5a
commit 4f03f6c4bf
No known key found for this signature in database
GPG Key ID: 39563C1504FDD0C9

@ -153,7 +153,7 @@ function toDiagnostics(resource: Uri, diag: lsTypes.Diagnostic): editor.IMarkerD
//#region CompletionAdapter
export interface ILanguageWorkerWithCompletions {
doComplete(uri: string, position: lsTypes.Position): Promise<lsTypes.CompletionList>;
doComplete(uri: string, position: lsTypes.Position): Promise<lsTypes.CompletionList | null>;
}
export class CompletionAdapter<T extends ILanguageWorkerWithCompletions>
@ -481,7 +481,7 @@ export class DocumentHighlightAdapter<T extends ILanguageWorkerWithDocumentHighl
model: editor.IReadOnlyModel,
position: Position,
token: CancellationToken
): Promise<languages.DocumentHighlight[]> {
): Promise<languages.DocumentHighlight[] | undefined> {
const resource = model.uri;
return this._worker(resource)
@ -501,7 +501,7 @@ export class DocumentHighlightAdapter<T extends ILanguageWorkerWithDocumentHighl
}
function toDocumentHighlightKind(
kind: lsTypes.DocumentHighlightKind
kind: lsTypes.DocumentHighlightKind | undefined
): languages.DocumentHighlightKind {
switch (kind) {
case lsTypes.DocumentHighlightKind.Read:
@ -519,7 +519,7 @@ function toDocumentHighlightKind(
//#region DefinitionAdapter
export interface ILanguageWorkerWithDefinitions {
findDefinition(uri: string, position: lsTypes.Position): Promise<lsTypes.Location>;
findDefinition(uri: string, position: lsTypes.Position): Promise<lsTypes.Location | null>;
}
export class DefinitionAdapter<T extends ILanguageWorkerWithDefinitions>
@ -531,7 +531,7 @@ export class DefinitionAdapter<T extends ILanguageWorkerWithDefinitions>
model: editor.IReadOnlyModel,
position: Position,
token: CancellationToken
): Promise<languages.Definition> {
): Promise<languages.Definition | undefined> {
const resource = model.uri;
return this._worker(resource)
@ -572,7 +572,7 @@ export class ReferenceAdapter<T extends ILanguageWorkerWithReferences>
position: Position,
context: languages.ReferenceContext,
token: CancellationToken
): Promise<languages.Location[]> {
): Promise<languages.Location[] | undefined> {
const resource = model.uri;
return this._worker(resource)
@ -597,7 +597,7 @@ export interface ILanguageWorkerWithRename {
uri: string,
position: lsTypes.Position,
newName: string
): Promise<lsTypes.WorkspaceEdit>;
): Promise<lsTypes.WorkspaceEdit | null>;
}
export class RenameAdapter<T extends ILanguageWorkerWithRename>
@ -610,7 +610,7 @@ export class RenameAdapter<T extends ILanguageWorkerWithRename>
position: Position,
newName: string,
token: CancellationToken
): Promise<languages.WorkspaceEdit> {
): Promise<languages.WorkspaceEdit | undefined> {
const resource = model.uri;
return this._worker(resource)
@ -623,7 +623,7 @@ export class RenameAdapter<T extends ILanguageWorkerWithRename>
}
}
function toWorkspaceEdit(edit: lsTypes.WorkspaceEdit): languages.WorkspaceEdit {
function toWorkspaceEdit(edit: lsTypes.WorkspaceEdit | null): languages.WorkspaceEdit | undefined {
if (!edit || !edit.changes) {
return void 0;
}
@ -743,7 +743,7 @@ export class DocumentLinkAdapter<T extends ILanguageWorkerWithDocumentLinks>
public provideLinks(
model: editor.IReadOnlyModel,
token: CancellationToken
): Promise<languages.ILinksList> {
): Promise<languages.ILinksList | undefined> {
const resource = model.uri;
return this._worker(resource)

@ -121,6 +121,6 @@ function asDisposable(disposables: IDisposable[]): IDisposable {
function disposeAll(disposables: IDisposable[]) {
while (disposables.length) {
disposables.pop().dispose();
disposables.pop()!.dispose();
}
}

@ -61,26 +61,44 @@ export class CSSWorker {
}
return Promise.resolve([]);
}
async doComplete(uri: string, position: cssService.Position): Promise<cssService.CompletionList> {
async doComplete(
uri: string,
position: cssService.Position
): Promise<cssService.CompletionList | null> {
let document = this._getTextDocument(uri);
if (!document) {
return null;
}
let stylesheet = this._languageService.parseStylesheet(document);
let completions = this._languageService.doComplete(document, position, stylesheet);
return Promise.resolve(completions);
}
async doHover(uri: string, position: cssService.Position): Promise<cssService.Hover> {
async doHover(uri: string, position: cssService.Position): Promise<cssService.Hover | null> {
let document = this._getTextDocument(uri);
if (!document) {
return null;
}
let stylesheet = this._languageService.parseStylesheet(document);
let hover = this._languageService.doHover(document, position, stylesheet);
return Promise.resolve(hover);
}
async findDefinition(uri: string, position: cssService.Position): Promise<cssService.Location> {
async findDefinition(
uri: string,
position: cssService.Position
): Promise<cssService.Location | null> {
let document = this._getTextDocument(uri);
if (!document) {
return null;
}
let stylesheet = this._languageService.parseStylesheet(document);
let definition = this._languageService.findDefinition(document, position, stylesheet);
return Promise.resolve(definition);
}
async findReferences(uri: string, position: cssService.Position): Promise<cssService.Location[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let stylesheet = this._languageService.parseStylesheet(document);
let references = this._languageService.findReferences(document, position, stylesheet);
return Promise.resolve(references);
@ -90,12 +108,18 @@ export class CSSWorker {
position: cssService.Position
): Promise<cssService.DocumentHighlight[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let stylesheet = this._languageService.parseStylesheet(document);
let highlights = this._languageService.findDocumentHighlights(document, position, stylesheet);
return Promise.resolve(highlights);
}
async findDocumentSymbols(uri: string): Promise<cssService.SymbolInformation[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let stylesheet = this._languageService.parseStylesheet(document);
let symbols = this._languageService.findDocumentSymbols(document, stylesheet);
return Promise.resolve(symbols);
@ -106,12 +130,18 @@ export class CSSWorker {
context: cssService.CodeActionContext
): Promise<cssService.Command[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let stylesheet = this._languageService.parseStylesheet(document);
let actions = this._languageService.doCodeActions(document, range, context, stylesheet);
return Promise.resolve(actions);
}
async findDocumentColors(uri: string): Promise<cssService.ColorInformation[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let stylesheet = this._languageService.parseStylesheet(document);
let colorSymbols = this._languageService.findDocumentColors(document, stylesheet);
return Promise.resolve(colorSymbols);
@ -122,6 +152,9 @@ export class CSSWorker {
range: cssService.Range
): Promise<cssService.ColorPresentation[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let stylesheet = this._languageService.parseStylesheet(document);
let colorPresentations = this._languageService.getColorPresentations(
document,
@ -136,6 +169,9 @@ export class CSSWorker {
context?: { rangeLimit?: number }
): Promise<cssService.FoldingRange[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let ranges = this._languageService.getFoldingRanges(document, context);
return Promise.resolve(ranges);
}
@ -144,6 +180,9 @@ export class CSSWorker {
positions: cssService.Position[]
): Promise<cssService.SelectionRange[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let stylesheet = this._languageService.parseStylesheet(document);
let ranges = this._languageService.getSelectionRanges(document, positions, stylesheet);
return Promise.resolve(ranges);
@ -152,13 +191,16 @@ export class CSSWorker {
uri: string,
position: cssService.Position,
newName: string
): Promise<cssService.WorkspaceEdit> {
): Promise<cssService.WorkspaceEdit | null> {
let document = this._getTextDocument(uri);
if (!document) {
return null;
}
let stylesheet = this._languageService.parseStylesheet(document);
let renames = this._languageService.doRename(document, position, newName, stylesheet);
return Promise.resolve(renames);
}
private _getTextDocument(uri: string): cssService.TextDocument {
private _getTextDocument(uri: string): cssService.TextDocument | null {
let models = this._ctx.getMirrorModels();
for (let model of models) {
if (model.uri.toString() === uri) {

@ -113,8 +113,8 @@ export type DiagnosticsOptions = Options;
class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
private _onDidChange = new Emitter<LanguageServiceDefaults>();
private _options: Options;
private _modeConfiguration: ModeConfiguration;
private _options!: Options;
private _modeConfiguration!: ModeConfiguration;
private _languageId: string;
constructor(languageId: string, options: Options, modeConfiguration: ModeConfiguration) {

@ -15,12 +15,13 @@ export class WorkerManager {
private _lastUsedTime: number;
private _configChangeListener: IDisposable;
private _worker: editor.MonacoWebWorker<CSSWorker>;
private _client: Promise<CSSWorker>;
private _worker: editor.MonacoWebWorker<CSSWorker> | null;
private _client: Promise<CSSWorker> | null;
constructor(defaults: LanguageServiceDefaults) {
this._defaults = defaults;
this._worker = null;
this._client = null;
this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 30 * 1000);
this._lastUsedTime = 0;
this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
@ -80,7 +81,9 @@ export class WorkerManager {
_client = client;
})
.then((_) => {
return this._worker.withSyncedResources(resources);
if (this._worker) {
return this._worker.withSyncedResources(resources);
}
})
.then((_) => _client);
}

@ -163,6 +163,6 @@ function asDisposable(disposables: IDisposable[]): IDisposable {
function disposeAll(disposables: IDisposable[]) {
while (disposables.length) {
disposables.pop().dispose();
disposables.pop()!.dispose();
}
}

@ -37,8 +37,11 @@ export class HTMLWorker {
async doComplete(
uri: string,
position: htmlService.Position
): Promise<htmlService.CompletionList> {
): Promise<htmlService.CompletionList | null> {
let document = this._getTextDocument(uri);
if (!document) {
return null;
}
let htmlDocument = this._languageService.parseHTMLDocument(document);
return Promise.resolve(
this._languageService.doComplete(
@ -55,12 +58,18 @@ export class HTMLWorker {
options: htmlService.FormattingOptions
): Promise<htmlService.TextEdit[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let formattingOptions = { ...this._languageSettings.format, ...options };
let textEdits = this._languageService.format(document, range, formattingOptions);
return Promise.resolve(textEdits);
}
async doHover(uri: string, position: htmlService.Position): Promise<htmlService.Hover> {
async doHover(uri: string, position: htmlService.Position): Promise<htmlService.Hover | null> {
let document = this._getTextDocument(uri);
if (!document) {
return null;
}
let htmlDocument = this._languageService.parseHTMLDocument(document);
let hover = this._languageService.doHover(document, position, htmlDocument);
return Promise.resolve(hover);
@ -70,17 +79,26 @@ export class HTMLWorker {
position: htmlService.Position
): Promise<htmlService.DocumentHighlight[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let htmlDocument = this._languageService.parseHTMLDocument(document);
let highlights = this._languageService.findDocumentHighlights(document, position, htmlDocument);
return Promise.resolve(highlights);
}
async findDocumentLinks(uri: string): Promise<htmlService.DocumentLink[]> {
let document = this._getTextDocument(uri);
let links = this._languageService.findDocumentLinks(document, null);
if (!document) {
return [];
}
let links = this._languageService.findDocumentLinks(document, null! /*TODO@aeschli*/);
return Promise.resolve(links);
}
async findDocumentSymbols(uri: string): Promise<htmlService.SymbolInformation[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let htmlDocument = this._languageService.parseHTMLDocument(document);
let symbols = this._languageService.findDocumentSymbols(document, htmlDocument);
return Promise.resolve(symbols);
@ -90,6 +108,9 @@ export class HTMLWorker {
context?: { rangeLimit?: number }
): Promise<htmlService.FoldingRange[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let ranges = this._languageService.getFoldingRanges(document, context);
return Promise.resolve(ranges);
}
@ -98,6 +119,9 @@ export class HTMLWorker {
positions: htmlService.Position[]
): Promise<htmlService.SelectionRange[]> {
let document = this._getTextDocument(uri);
if (!document) {
return [];
}
let ranges = this._languageService.getSelectionRanges(document, positions);
return Promise.resolve(ranges);
}
@ -105,13 +129,16 @@ export class HTMLWorker {
uri: string,
position: htmlService.Position,
newName: string
): Promise<htmlService.WorkspaceEdit> {
): Promise<htmlService.WorkspaceEdit | null> {
let document = this._getTextDocument(uri);
if (!document) {
return null;
}
let htmlDocument = this._languageService.parseHTMLDocument(document);
let renames = this._languageService.doRename(document, position, newName, htmlDocument);
return Promise.resolve(renames);
}
private _getTextDocument(uri: string): htmlService.TextDocument {
private _getTextDocument(uri: string): htmlService.TextDocument | null {
let models = this._ctx.getMirrorModels();
for (let model of models) {
if (model.uri.toString() === uri) {

@ -14,7 +14,7 @@ export interface HTMLFormatConfiguration {
readonly contentUnformatted: string;
readonly indentInnerHtml: boolean;
readonly preserveNewLines: boolean;
readonly maxPreserveNewLines: number;
readonly maxPreserveNewLines: number | undefined;
readonly indentHandlebars: boolean;
readonly endWithNewline: boolean;
readonly extraLiners: string;
@ -114,8 +114,8 @@ export interface LanguageServiceDefaults {
class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
private _onDidChange = new Emitter<LanguageServiceDefaults>();
private _options: Options;
private _modeConfiguration: ModeConfiguration;
private _options!: Options;
private _modeConfiguration!: ModeConfiguration;
private _languageId: string;
constructor(languageId: string, options: Options, modeConfiguration: ModeConfiguration) {
@ -160,7 +160,7 @@ const formatDefaults: Required<HTMLFormatConfiguration> = {
contentUnformatted: 'pre',
indentInnerHtml: false,
preserveNewLines: true,
maxPreserveNewLines: null,
maxPreserveNewLines: undefined,
indentHandlebars: false,
endWithNewline: false,
extraLiners: 'head, body, /html',

@ -15,12 +15,13 @@ export class WorkerManager {
private _lastUsedTime: number;
private _configChangeListener: IDisposable;
private _worker: editor.MonacoWebWorker<HTMLWorker>;
private _client: Promise<HTMLWorker>;
private _worker: editor.MonacoWebWorker<HTMLWorker> | null;
private _client: Promise<HTMLWorker> | null;
constructor(defaults: LanguageServiceDefaults) {
this._defaults = defaults;
this._worker = null;
this._client = null;
this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 30 * 1000);
this._lastUsedTime = 0;
this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());

@ -1,10 +1,11 @@
{
"compilerOptions": {
"declaration": true,
"lib": ["dom", "es5", "es2015.collection", "es2015.promise", "es2015.iterable"],
"module": "amd",
"moduleResolution": "node",
"outDir": "../out/amd",
"declaration": true,
"target": "es5",
"lib": ["dom", "es5", "es2015.collection", "es2015.promise", "es2015.iterable"]
"strict": true,
"target": "es5"
}
}

@ -7594,7 +7594,7 @@ declare namespace monaco.languages.html {
readonly contentUnformatted: string;
readonly indentInnerHtml: boolean;
readonly preserveNewLines: boolean;
readonly maxPreserveNewLines: number;
readonly maxPreserveNewLines: number | undefined;
readonly indentHandlebars: boolean;
readonly endWithNewline: boolean;
readonly extraLiners: string;

@ -7594,7 +7594,7 @@ declare namespace monaco.languages.html {
readonly contentUnformatted: string;
readonly indentInnerHtml: boolean;
readonly preserveNewLines: boolean;
readonly maxPreserveNewLines: number;
readonly maxPreserveNewLines: number | undefined;
readonly indentHandlebars: boolean;
readonly endWithNewline: boolean;
readonly extraLiners: string;

Loading…
Cancel
Save