-
Notifications
You must be signed in to change notification settings - Fork 78
Enable strictNullChecks in tsconfig.json #179
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,11 +267,11 @@ export default class AutocompleteAdapter { | |
// * `editor` An Atom {TextEditor} used to obtain the necessary text replacement. | ||
// * `suggestion` An {atom$AutocompleteSuggestion} to set the replacementPrefix and text properties of. | ||
public static applyTextEditToSuggestion( | ||
textEdit: TextEdit | null, | ||
textEdit: TextEdit | undefined, | ||
editor: TextEditor, | ||
suggestion: AutocompleteSuggestion, | ||
): void { | ||
if (textEdit != null) { | ||
if (textEdit) { | ||
suggestion.replacementPrefix = editor.getTextInBufferRange(Convert.lsRangeToAtomRange(textEdit.range)); | ||
suggestion.text = textEdit.newText; | ||
} | ||
|
@@ -296,7 +296,7 @@ export default class AutocompleteAdapter { | |
// | ||
// Returns a {String} containing the AutoComplete+ suggestion type equivalent | ||
// to the given completion kind. | ||
public static completionKindToSuggestionType(kind: number | null): string { | ||
public static completionKindToSuggestionType(kind: number | undefined): string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
switch (kind) { | ||
case CompletionItemKind.Constant: | ||
return 'constant'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ export default class CodeActionAdapter { | |
public static async getCodeActions( | ||
connection: LanguageClientConnection, | ||
serverCapabilities: ServerCapabilities, | ||
linterAdapter: LinterPushV2Adapter | null, | ||
linterAdapter: LinterPushV2Adapter | undefined , | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
editor: TextEditor, | ||
range: Range, | ||
diagnostics: atomIde.Diagnostic[], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,5 +88,8 @@ export default class DatatipAdapter { | |
value: markedString.value, | ||
}; | ||
} | ||
|
||
// Catch-all case | ||
return { type: 'markdown', value: markedString.toString() }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TypeScript compiler wouldn't let this method live without a catch-all case. Is there a better result value? |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ export default class DocumentSyncAdapter { | |
// indicating whether this adapter should care about the contents of the editor. | ||
constructor( | ||
connection: LanguageClientConnection, | ||
documentSyncKind: TextDocumentSyncOptions | number | null, | ||
documentSyncKind: TextDocumentSyncOptions | number | undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
editorSelector: (editor: TextEditor) => boolean, | ||
) { | ||
this._connection = connection; | ||
|
@@ -129,7 +129,7 @@ export default class DocumentSyncAdapter { | |
); | ||
} | ||
|
||
public getEditorSyncAdapter(editor: TextEditor): TextEditorSyncAdapter | null { | ||
public getEditorSyncAdapter(editor: TextEditor): TextEditorSyncAdapter | undefined { | ||
return this._editors.get(editor); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,13 +113,13 @@ export default class LinterPushV2Adapter { | |
if (path != null) { | ||
const diagnosticCodes = this._diagnosticCodes.get(path); | ||
if (diagnosticCodes != null) { | ||
return diagnosticCodes.get(getCodeKey(range, text)); | ||
return diagnosticCodes.get(getCodeKey(range, text)) || null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maps return |
||
} | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
function getCodeKey(range: atom.Range, text: string): string { | ||
return [].concat(...range.serialize(), text).join(','); | ||
return ([] as any[]).concat(...range.serialize(), text).join(','); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little hack to make the type system happy There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll give it a shot! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,24 +115,27 @@ export default class OutlineViewAdapter { | |
return null; | ||
} | ||
|
||
let parent = null; | ||
let parent: atomIde.OutlineTree | undefined; | ||
for (const candidate of candidates) { | ||
if ( | ||
candidate !== child && | ||
candidate.startPosition.isLessThanOrEqual(child.startPosition) && | ||
(candidate.endPosition == null || candidate.endPosition.isGreaterThanOrEqual(child.endPosition)) | ||
(candidate.endPosition === undefined || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
(child.endPosition && candidate.endPosition.isGreaterThanOrEqual(child.endPosition))) | ||
) { | ||
if ( | ||
parent == null || | ||
parent === undefined || | ||
(parent.startPosition.isLessThanOrEqual(candidate.startPosition) || | ||
(parent.endPosition != null && parent.endPosition.isGreaterThanOrEqual(candidate.endPosition))) | ||
(parent.endPosition != null && | ||
candidate.endPosition && | ||
parent.endPosition.isGreaterThanOrEqual(candidate.endPosition))) | ||
) { | ||
parent = candidate; | ||
} | ||
} | ||
} | ||
|
||
return parent; | ||
return parent || null; | ||
} | ||
|
||
// Public: Convert an individual {SymbolInformation} from the language server | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,8 @@ export default class SignatureHelpAdapter { | |
const {signatureHelpProvider} = this._capabilities; | ||
assert(signatureHelpProvider != null); | ||
|
||
let triggerCharacters = null; | ||
if (Array.isArray(signatureHelpProvider.triggerCharacters)) { | ||
let triggerCharacters: Set<string> | undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yet assigned, must use |
||
if (signatureHelpProvider && Array.isArray(signatureHelpProvider.triggerCharacters)) { | ||
triggerCharacters = new Set(signatureHelpProvider.triggerCharacters); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,13 @@ import * as rpc from 'vscode-jsonrpc'; | |
import * as path from 'path'; | ||
import * as atomIde from 'atom-ide'; | ||
import * as linter from 'atom-linter'; | ||
import * as stream from 'stream'; | ||
import { Socket } from 'net'; | ||
import { EventEmitter } from 'events'; | ||
import { ConsoleLogger, NullLogger, Logger } from './logger'; | ||
import { ServerManager, ActiveServer } from './server-manager.js'; | ||
import { LanguageServerProcess, ServerManager, ActiveServer } from './server-manager.js'; | ||
import Convert from './convert.js'; | ||
|
||
export { LanguageServerProcess }; | ||
|
||
import { | ||
AutocompleteDidInsert, | ||
AutocompleteProvider, | ||
|
@@ -39,21 +39,6 @@ import SignatureHelpAdapter from './adapters/signature-help-adapter'; | |
|
||
export type ConnectionType = 'stdio' | 'socket' | 'ipc'; | ||
|
||
// Public: Defines the minimum surface area for an object that resembles a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decided to move this to ServerManager's file because ServerManager was still using ChildProcess to refer to the language server process. |
||
// ChildProcess. This is used so that language packages with alternative | ||
// language server process hosting strategies can return something compatible | ||
// with AutoLanguageClient.startServerProcess. | ||
export interface LanguageServerProcess extends EventEmitter { | ||
stdin: stream.Writable; | ||
stdout: stream.Readable; | ||
stderr: stream.Readable; | ||
pid: number; | ||
|
||
kill(signal?: string): void; | ||
on(event: 'error', listener: (err: Error) => void): this; | ||
on(event: 'exit', listener: (code: number, signal: string) => void): this; | ||
} | ||
|
||
// Public: AutoLanguageClient provides a simple way to have all the supported | ||
// Atom-IDE services wired up entirely for you by just subclassing it and | ||
// implementing startServerProcess/getGrammarScopes/getLanguageName and | ||
|
@@ -62,7 +47,7 @@ export default class AutoLanguageClient { | |
private _disposable = new CompositeDisposable(); | ||
private _serverManager: ServerManager; | ||
private _linterDelegate: linter.V2IndieDelegate; | ||
private _signatureHelpRegistry: atomIde.SignatureHelpRegistry; | ||
private _signatureHelpRegistry: atomIde.SignatureHelpRegistry | null; | ||
private _lastAutocompleteRequest: AutocompleteRequest; | ||
private _isDeactivating: boolean; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,7 +159,7 @@ export default class Convert { | |
case 'deleted': | ||
return [{uri: Convert.pathToUri(fileEvent.path), type: ls.FileChangeType.Deleted}]; | ||
case 'renamed': { | ||
const results = []; | ||
const results: Array<{ uri: string, type: ls.FileChangeType }> = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TypeScript uses a type of |
||
if (fileEvent.oldPath) { | ||
results.push({uri: Convert.pathToUri(fileEvent.oldPath || ''), type: ls.FileChangeType.Deleted}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ export default (async function downloadFile( | |
throw Error('No response body'); | ||
} | ||
|
||
const finalLength = length || parseInt(response.headers.get('Content-Length' || '0'), 10); | ||
const finalLength = length || parseInt(response.headers.get('Content-Length') || '0', 10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug in the previous code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha, looks like it. Nice catch. |
||
const reader = body.getReader(); | ||
const writer = fs.createWriteStream(targetFile); | ||
|
||
|
@@ -72,7 +72,7 @@ async function streamWithProgress( | |
writer.write(Buffer.from(chunk)); | ||
if (progressCallback != null) { | ||
bytesDone += chunk.byteLength; | ||
const percent: number = length === 0 ? null : Math.floor(bytesDone / length * 100); | ||
const percent: number | undefined = length === 0 ? undefined : Math.floor(bytesDone / length * 100); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
progressCallback(bytesDone, percent); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ describe('AutoCompleteAdapter', () => { | |
capabilities: {completionProvider: { }}, | ||
connection: new ls.LanguageClientConnection(createSpyConnection()), | ||
disposable: new CompositeDisposable(), | ||
process: undefined, | ||
process: undefined as any, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type system hack to not have to mock a whole process |
||
projectPath: '/', | ||
}; | ||
} | ||
|
@@ -279,7 +279,7 @@ describe('AutoCompleteAdapter', () => { | |
|
||
it('does not do anything if there is no textEdit', () => { | ||
const completionItem: AutocompleteSuggestion = {}; | ||
AutoCompleteAdapter.applyTextEditToSuggestion(null, new TextEditor(), completionItem); | ||
AutoCompleteAdapter.applyTextEditToSuggestion(undefined, new TextEditor(), completionItem); | ||
expect(completionItem).deep.equals({}); | ||
}); | ||
|
||
|
@@ -315,7 +315,7 @@ describe('AutoCompleteAdapter', () => { | |
}); | ||
|
||
it('defaults to "value"', () => { | ||
const result = AutoCompleteAdapter.completionKindToSuggestionType(null); | ||
const result = AutoCompleteAdapter.completionKindToSuggestionType(undefined); | ||
expect(result).equals('value'); | ||
}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,8 +50,10 @@ describe('CodeHighlightAdapter', () => { | |
expect(highlightStub.called).to.be.true; | ||
|
||
invariant(result != null); | ||
expect(result.length).to.equal(1); | ||
expect(result[0].isEqual(new Range([0, 1], [0, 2]))).to.be.true; | ||
if (result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests required a bunch of null/undefined checks so that the compiler would be happy |
||
expect(result.length).to.equal(1); | ||
expect(result[0].isEqual(new Range([0, 1], [0, 2]))).to.be.true; | ||
} | ||
}); | ||
|
||
it('throws if document highlights are not supported', async () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This TextEdit comes from
CompletionItem.textEdit
which is typed asTextEdit | undefined
, makes more sense to useundefined
here