Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS Server #2041

Merged
merged 46 commits into from
Feb 19, 2015
Merged

TS Server #2041

merged 46 commits into from
Feb 19, 2015

Conversation

mhegazy
Copy link
Contributor

@mhegazy mhegazy commented Feb 16, 2015

The basic LanguageService interface puts some requirements on the "host", such as an implementation of a ScriptSnapshot system to support incremental parsing, managing contexts, monitoring files on disk, scheduling diagnostic queries, maintaining line map for line/column for positions for files, etc.. Every editor plugin is required to implement the expected host functionality, possibly in different languages.

This change exposes a new interface to the Services layer (ts server), through a JSON-based communication protocol. Behind the protocol, the server supports all the common host functionality,:

  • A ScriptSnapshot management system with support for diffing script snapshots to allow efficient incremental parsing. A client would send a stream of text changes, and the server will maintain an updated version of the text in memory that can then be used to drive LS requests.
  • A Project management service that allows for figuring project structure a la VS Virtual Projects, allowing the client to ignore resolving references, and maintaining project structure. The project management service also should supports different modes e.g. lose files, ts config, /// references, and imports. The client just informs the server about open files, and the server takes the responsibility of figuring out what files are interesting to this context. the client then asks for operations like completions, quick info, etc.. directly on the file.
  • Managing closed file state without requiring the client to monitor them. The server adds file watches to all files in a project, and triggers re computation for errors and updates context once a file has changed on disk.
  • Diagnostics update scheduling, the client does not need to trigger diagnostics update requests; the server sends events with errors whenever this is needed.
  • A line/column interface with no need to keep a line map for all files. the server does not request any positions in its calls.

The server is mainly available as an IO process that a client would create in a separate process and communicates with it over stdin/stdout.

The change also adds a JS client implementation as a reference implementation to a client, and also used for tests.

The protocol definitions are all in protocol.d.ts.

Note: Reviewing the final change is probably easier.

if (info.defaultProject.getSourceFile(r)) {
// remove project rooted at r
this.inferredProjects =
copyListRemovingItem(r.defaultProject, this.inferredProjects);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get this onto the same line as the =

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awkward and a probably somewhat unnecessary.

steveluc added 3 commits February 18, 2015 00:14
the end of the deleted Range (inclusive).  DeleteLen was not always
accurate because editors normalize \r\n to \n in some cases, affecting
the length of ranges.  In Diagnostic response items, changed len field
to end to address the same range length issue.  Flattened
MessageDiagnosticChains in diagnostic message text, since clients expect
string there.  Renamed ts.server.protocol to simply protocol in
session.ts and client.ts since module name prefix is clear.

Based on protocol feedback: Changed LineCol to Location.  Changed
CodeLocation interface name prefix to FileLocation.  Changed DiagEvent
to DiagnosticEvent.  Removed anonymous types.
"completionEntryDetails".   This mirrors the function of the LS API and
increases performance of completion in large projects.
steveluc added a commit that referenced this pull request Feb 19, 2015
@steveluc steveluc merged commit 6d7045e into master Feb 19, 2015
@steveluc steveluc deleted the TSServer branch February 19, 2015 21:10
@basarat
Copy link
Contributor

basarat commented Mar 10, 2015

I reviewed the TSServer code today as it exists in https://github.com/Microsoft/TypeScript/tree/master/src/server

I think its really nicely done in that it takes the burden of watching files + efficient snapshoting off of editor package authors.

The limitations for us is that it does not (and cannot easily using stdout) expose getProgram. This means that for really advanced features we would either need to wait for them to become a part of languageService or reimplement the stuff from TSServer. Also I use a globbing that isn't there in TSServer.

I am okay with using TSServer as a reference implementation and copying all the good stuff over. But just wanted to leave this feedback about my reasons for doing so (and potentially other package authors might end up doing the same thing). Thanks again for the initiative ❤️

ref : Based on TypeStrong/atom-typescript#91 /cc @csnover

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants