Convert atom-languageclient to TypeScript#175
Conversation
lib/convert.ts
Outdated
| import * as ls from './languageclient'; | ||
| import {Point, Range} from 'atom'; | ||
| import {Point, ProjectFileEvent, Range, TextEditor} from 'atom'; | ||
| import {Diagnostic, DiagnosticType, TextEdit} from '../typings/atom-ide'; |
There was a problem hiding this comment.
Ideally we wouldn't import from ../typings/atom-ide but instead from a "fake" atom-ide module provided by a @types/atom-ide package.
lib/convert.ts
Outdated
| return ls.DiagnosticSeverity.Information; | ||
| default: | ||
| (type: empty); | ||
| // (type: empty); |
There was a problem hiding this comment.
This line gave an error in the TypeScript compiler, not sure what purpose it serves.
There was a problem hiding this comment.
Assuming that the purpose was to assert that the switch was exhaustive over DiagnosticType, one way of writing this in typescript is:
const never: never = type;
throw Error(`Unexpected diagnostic type ${never}`);The never type is a type with no legal values, so that assignment will fail if type inference thinks that there are any legal values for type at that point in the program.
(Using never instead of types in the error ensures that it doesn't look like never is an unused variable when linting or compiling)
typings/atom-ide/index.d.ts
Outdated
|
|
||
| /* declare module 'atom-ide' {*/ | ||
|
|
||
| export type OutlineProvider = { |
There was a problem hiding this comment.
This file is a conversion of the flowtype definitions for Atom-IDE and isn't finished yet. There are some type system differences that I still need to account for.
lib/convert.ts
Outdated
| return ls.DiagnosticSeverity.Information; | ||
| default: | ||
| (type: empty); | ||
| // (type: empty); |
There was a problem hiding this comment.
Assuming that the purpose was to assert that the switch was exhaustive over DiagnosticType, one way of writing this in typescript is:
const never: never = type;
throw Error(`Unexpected diagnostic type ${never}`);The never type is a type with no legal values, so that assignment will fail if type inference thinks that there are any legal values for type at that point in the program.
(Using never instead of types in the error ensures that it doesn't look like never is an unused variable when linting or compiling)
lib/convert.ts
Outdated
| // | ||
| // Returns an {Array} of Atom {TextEdit} objects. | ||
| static convertLsTextEdits(textEdits: ?Array<ls.TextEdit>): Array<atomIde$TextEdit> { | ||
| static convertLsTextEdits(textEdits: Array<ls.TextEdit>): Array<TextEdit> { |
There was a problem hiding this comment.
The TypeScript representation of ?Array<ls.TextEdit> is Array<ls.TextEdit> | null | undefined I think (unless you're not compiling with strict null checks)
There was a problem hiding this comment.
Thanks for pointing that out!
| "outDir": "build", | ||
| "lib": ["es6", "dom"], | ||
| "inlineSources": true, | ||
| "inlineSourceMap": true, |
There was a problem hiding this comment.
"strict": true, will catch many more errors, though it also has more false positives
There was a problem hiding this comment.
Thanks! I think we'll turn on strictness once we make a bit more progress
|
Thanks for the help @rictic! |
|
All files are converted now and tests (except for one commented out file) are passing! Next steps are to finish up some small conversion tasks and then start cleaning up the code based on tslint results. |
|
This PR is ready to be reviewed! I'll sit down with @damieng when he's back and go over everything since this is a pretty big change. Everyone else should feel free to ask questions! |
|
I'm going to have some time this morning so let's do it then! I'll schedule with you on slack. |
lib/adapters/apply-edit-adapter.ts
Outdated
| // Sort edits in reverse order to prevent edit conflicts. | ||
| edits.sort((edit1, edit2) => -edit1.oldRange.compare(edit2.oldRange)); | ||
| const buffer = editor.getBuffer(); | ||
| const buffer = (editor as any).getBuffer() as TextBuffer; |
There was a problem hiding this comment.
Need to make this public in Atom APIs
There was a problem hiding this comment.
Turns out it is public and in the Atom type defs, fixable on our side
| suggestion.descriptionMarkdown = item.documentation; | ||
|
|
||
| if (typeof item.documentation === 'object') { | ||
| suggestion.descriptionMarkdown = item.documentation.value; |
There was a problem hiding this comment.
Check issues to see if this was done based on an issue filed
| return []; | ||
| } | ||
| invariant(serverCapabilities.codeActionProvider, 'Must have the textDocument/codeAction capability'); | ||
| assert(serverCapabilities.codeActionProvider, 'Must have the textDocument/codeAction capability'); |
There was a problem hiding this comment.
File issue for using assert(canAdapt) more broadly in adapters
lib/adapters/datatip-adapter.ts
Outdated
| if (typeof markedString === 'string') { | ||
| return { type: 'markdown', value: markedString }; | ||
| } | ||
| else { |
There was a problem hiding this comment.
Get rid of unnecessary elses
lib/auto-languageclient.ts
Outdated
| // 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 { |
There was a problem hiding this comment.
Do this in a separate PR
lib/download-file.ts
Outdated
| // | ||
| // Returns a {Promise} that will accept when complete. | ||
| export default (async function downloadFile( | ||
| export default (async function DownloadFile( |
There was a problem hiding this comment.
Change this back to lower case
| } | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
Move DiagnosticCode here
lib/logger.ts
Outdated
| } | ||
|
|
||
| public warn(...args: any[]) { | ||
| // tslint:disable-next-line:no-console |
There was a problem hiding this comment.
Can we disable this at file level?
lib/main.ts
Outdated
| LinterPushV2Adapter, | ||
| }; | ||
| export * from './auto-languageclient'; | ||
| export { AutoLanguageClient, DownloadFile, Convert }; |
| } | ||
| } | ||
| ], | ||
| "atomTestRunner": "./build/test/runner", |
There was a problem hiding this comment.
Make sure this works in Atom test runner
|
Updated the PR based on feedback and got tests running inside of Atom again. Let me know if there's anything else you'd like me to do before merging! |
|
|
||
| // Public: Retrieves signature help for a given editor and position. | ||
| getSignatureHelp(editor: atom$TextEditor, point: atom$Point): Promise<?atomIde$SignatureHelp> { | ||
| public getSignatureHelp(editor: TextEditor, point: Point): SignatureHelp | Promise<SignatureHelp> { |
There was a problem hiding this comment.
Shouldn't it be Promise<lsp.SignatureHelp | null>?
There was a problem hiding this comment.
Good catch, thanks!
|
Could you clarify why all types |
|
I suppose |
|
Cool! I just read about |
|
Yep, I'm about 80% of the way through updating the codebase to be checked with that :) |
|
We only return null from these methods. I don't think we need undefined.
…On Wed, Feb 14, 2018, 3:55 PM David Wilson ***@***.***> wrote:
Yep, I'm about 80% of the way to updating the codebase to be checked with
that :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#175 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAHQp-JlD_TWQZ3b5Z_bbYtx5M56fMZPks5tU3KCgaJpZM4R9I6->
.
|
|
Yep, I'm not adding |
This PR is an experiment to see how much effort it'd be to convert the codebase to TypeScript. Using TypeScript here would help us dogfood the ide-typescript package.