{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/24779736","id":24779736,"diff_hunk":"@@ -0,0 +1,505 @@\n+/// <reference path=\"session.ts\" />\r\n+\r\n+module ts.server {\r\n+\r\n+    export interface SessionClientHost extends LanguageServiceHost {\r\n+        writeMessage(message: string): void;\r\n+    }\r\n+\r\n+    interface CompletionEntry extends CompletionInfo {\r\n+        fileName: string;\r\n+        position: number;\r\n+    }\r\n+\r\n+    interface RenameEntry extends RenameInfo {\r\n+        fileName: string;\r\n+        position: number;\r\n+        locations: RenameLocation[];\r\n+        findInStrings: boolean;\r\n+        findInComments: boolean;\r\n+    }\r\n+\r\n+    export class SessionClient implements LanguageService {\r\n+        private sequence: number = 0;\r\n+        private fileMapping: ts.Map<string> = {};\r\n+        private lineMaps: ts.Map<number[]> = {};\r\n+        private messages: string[] = [];\r\n+        private lastCompletionEntry: CompletionEntry;\r\n+        private lastRenameEntry: RenameEntry;\r\n+        \r\n+        constructor(private host: SessionClientHost) {\r\n+        }\r\n+\r\n+        public onMessage(message: string): void { \r\n+            this.messages.push(message);\r\n+        }\r\n+\r\n+        private writeMessage(message: string): void { \r\n+            this.host.writeMessage(message);\r\n+        }\r\n+\r\n+        private getLineMap(fileName: string): number[] { \r\n+            var lineMap = ts.lookUp(this.lineMaps, fileName);\r\n+            if (!lineMap) {\r\n+                var scriptSnapshot = this.host.getScriptSnapshot(fileName);\r\n+                lineMap  = this.lineMaps[fileName] = ts.computeLineStarts(scriptSnapshot.getText(0, scriptSnapshot.getLength()));\r\n+            }\r\n+            return lineMap;\r\n+        }\r\n+\r\n+        private lineColToPosition(fileName: string, lineCol: ts.server.protocol.LineCol): number {\r\n+            return ts.computePositionFromLineAndCharacter(this.getLineMap(fileName), lineCol.line, lineCol.col);\r\n+        }\r\n+\r\n+        private positionToOneBasedLineCol(fileName: string, position: number): ts.server.protocol.LineCol {\r\n+            var lineCol = ts.computeLineAndCharacterOfPosition(this.getLineMap(fileName), position);\r\n+            return {\r\n+                line: lineCol.line,\r\n+                col: lineCol.character\r\n+            };\r\n+        }\r\n+\r\n+        private convertCodeEditsToTextChange(fileName: string, codeEdit: ts.server.protocol.CodeEdit): ts.TextChange {\r\n+            var start = this.lineColToPosition(fileName, codeEdit.start);\r\n+            var end = this.lineColToPosition(fileName, codeEdit.end);\r\n+\r\n+            return {\r\n+                span: ts.createTextSpanFromBounds(start, end),\r\n+                newText: codeEdit.newText\r\n+            };\r\n+        }\r\n+\r\n+        private decodeEncodedFileId(fileId: ts.server.protocol.EncodedFile): string {\r\n+            var fileName: string;\r\n+            if (typeof fileId === \"object\") {\r\n+                fileName = (<ts.server.protocol.IdFile>fileId).file;\r\n+                this.fileMapping[(<ts.server.protocol.IdFile>fileId).id] = fileName;\r\n+            }\r\n+            else if (typeof fileId === \"number\") {\r\n+                fileName = ts.lookUp(this.fileMapping, fileId.toString());\r\n+                Debug.assert(!!fileName, \"Did not find filename in previous fileID mappings.\");\r\n+            }\r\n+            else {\r\n+                Debug.fail(\"Got unexpedted fileId type.\");\r","path":"src/server/client.ts","position":83,"original_position":83,"commit_id":"32e2f4d95d007667b827f34c8109be5b32b49ffe","original_commit_id":"32e2f4d95d007667b827f34c8109be5b32b49ffe","user":{"login":"CyrusNajmabadi","id":4564579,"avatar_url":"https://avatars.githubusercontent.com/u/4564579?v=3","gravatar_id":"","url":"https://api.github.com/users/CyrusNajmabadi","html_url":"https://github.com/CyrusNajmabadi","followers_url":"https://api.github.com/users/CyrusNajmabadi/followers","following_url":"https://api.github.com/users/CyrusNajmabadi/following{/other_user}","gists_url":"https://api.github.com/users/CyrusNajmabadi/gists{/gist_id}","starred_url":"https://api.github.com/users/CyrusNajmabadi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CyrusNajmabadi/subscriptions","organizations_url":"https://api.github.com/users/CyrusNajmabadi/orgs","repos_url":"https://api.github.com/users/CyrusNajmabadi/repos","events_url":"https://api.github.com/users/CyrusNajmabadi/events{/privacy}","received_events_url":"https://api.github.com/users/CyrusNajmabadi/received_events","type":"User","site_admin":false},"body":"mispelling.","created_at":"2015-02-16T22:20:07Z","updated_at":"2015-02-16T22:20:07Z","html_url":"https://github.com/Microsoft/TypeScript/pull/2041#discussion_r24779736","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/2041","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/24779736"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/2041#discussion_r24779736"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/2041"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/2041","id":29349408,"html_url":"https://github.com/Microsoft/TypeScript/pull/2041","diff_url":"https://github.com/Microsoft/TypeScript/pull/2041.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/2041.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2041","number":2041,"state":"open","locked":false,"title":"TS Server","user":{"login":"mhegazy","id":8000722,"avatar_url":"https://avatars.githubusercontent.com/u/8000722?v=3","gravatar_id":"","url":"https://api.github.com/users/mhegazy","html_url":"https://github.com/mhegazy","followers_url":"https://api.github.com/users/mhegazy/followers","following_url":"https://api.github.com/users/mhegazy/following{/other_user}","gists_url":"https://api.github.com/users/mhegazy/gists{/gist_id}","starred_url":"https://api.github.com/users/mhegazy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhegazy/subscriptions","organizations_url":"https://api.github.com/users/mhegazy/orgs","repos_url":"https://api.github.com/users/mhegazy/repos","events_url":"https://api.github.com/users/mhegazy/events{/privacy}","received_events_url":"https://api.github.com/users/mhegazy/received_events","type":"User","site_admin":false},"body":"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. \r\n\r\nThis 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,:\r\n- 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.\r\n- 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.\r\n- 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. \r\n- Diagnostics update scheduling, the client does not need to trigger diagnostics update requests; the server sends events with errors whenever this is needed.\r\n- 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.\r\n\r\nThe server is mainly available as an IO process that a client would create in a separate process and communicates with it over stdin/stdout.\r\n\r\nThe change also adds a JS client implementation as a reference implementation to a client, and also used for tests.\r\n\r\nThe protocol definitions are all in protocol.d.ts.\r\n\r\nNote: Reviewing the final change is probably easier.","created_at":"2015-02-16T04:28:24Z","updated_at":"2015-02-16T22:20:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6f8f706ef5ab636af1ba5ae55f9120c0b63262fd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/2041/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/2041/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2041/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/32e2f4d95d007667b827f34c8109be5b32b49ffe","head":{"label":"Microsoft:TSServer","ref":"TSServer","sha":"32e2f4d95d007667b827f34c8109be5b32b49ffe","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/{number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","created_at":"2014-06-17T15:28:39Z","updated_at":"2015-02-16T21:35:19Z","pushed_at":"2015-02-16T21:54:10Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":513544,"stargazers_count":3482,"watchers_count":3482,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":327,"mirror_url":null,"open_issues_count":513,"forks":327,"open_issues":513,"watchers":3482,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"9f7c252ee0719fe12928c44333270ad197559320","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/{number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","created_at":"2014-06-17T15:28:39Z","updated_at":"2015-02-16T21:35:19Z","pushed_at":"2015-02-16T21:54:10Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":513544,"stargazers_count":3482,"watchers_count":3482,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":327,"mirror_url":null,"open_issues_count":513,"forks":327,"open_issues":513,"watchers":3482,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/2041"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/2041"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/2041"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/2041/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/2041/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/2041/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript/statuses/32e2f4d95d007667b827f34c8109be5b32b49ffe"}}}}