vscode-languageserver
Advanced tools
Comparing version 0.10.0-pre.29 to 0.10.0-pre.30
@@ -17,8 +17,2 @@ import { LanguageServerError, MessageKind } from './languageServerError'; | ||
} | ||
export interface TextDocumentHandler { | ||
incremental?: boolean; | ||
onDidOpenTextDocument(event: DidOpenTextDocumentParams): void; | ||
onDidChangeTextDocument(event: DidChangeTextDocumentParams): void; | ||
onDidCloseTextDocument(event: DidCloseTextDocumentParams): void; | ||
} | ||
export declare class TextDocumentChangeEvent { | ||
@@ -29,3 +23,2 @@ document: ITextDocument; | ||
private _documents; | ||
private _handler; | ||
_onDidContentChange: Emitter<TextDocumentChangeEvent>; | ||
@@ -37,3 +30,3 @@ constructor(); | ||
keys(): string[]; | ||
observe(connection: IConnection): void; | ||
listen(connection: IConnection): void; | ||
} | ||
@@ -63,3 +56,5 @@ export interface RemoteConsole { | ||
onDidChangeFiles(handler: INotificationHandler<DidChangeFilesParams>): void; | ||
onTextDocument(handler: TextDocumentHandler): void; | ||
onDidOpenTextDocument(handler: INotificationHandler<DidOpenTextDocumentParams>): void; | ||
onDidChangeTextDocument(handler: INotificationHandler<DidChangeTextDocumentParams>): void; | ||
onDidCloseTextDocument(handler: INotificationHandler<DidCloseTextDocumentParams>): void; | ||
publishDiagnostics(args: PublishDiagnosticsParams): void; | ||
@@ -66,0 +61,0 @@ onHover(handler: IRequestHandler<TextDocumentPosition, HoverResult, void>): void; |
113
lib/main.js
@@ -51,20 +51,4 @@ /*--------------------------------------------------------- | ||
function TextDocuments() { | ||
var _this = this; | ||
this._documents = Object.create(null); | ||
this._onDidContentChange = new events_1.Emitter(); | ||
this._handler = { | ||
onDidOpenTextDocument: function (event) { | ||
var document = new TextDocument(event.uri, event.text); | ||
_this._documents[event.uri] = document; | ||
_this._onDidContentChange.fire({ document: document }); | ||
}, | ||
onDidChangeTextDocument: function (event) { | ||
var document = _this._documents[event.uri]; | ||
document.update(event); | ||
_this._onDidContentChange.fire({ document: document }); | ||
}, | ||
onDidCloseTextDocument: function (event) { | ||
delete _this._documents[event.uri]; | ||
} | ||
}; | ||
} | ||
@@ -88,4 +72,18 @@ Object.defineProperty(TextDocuments.prototype, "onDidContentChange", { | ||
}; | ||
TextDocuments.prototype.observe = function (connection) { | ||
connection.onTextDocument(this._handler); | ||
TextDocuments.prototype.listen = function (connection) { | ||
var _this = this; | ||
connection.__incrementalTextDocumentSync = false; | ||
connection.onDidOpenTextDocument(function (event) { | ||
var document = new TextDocument(event.uri, event.text); | ||
_this._documents[event.uri] = document; | ||
_this._onDidContentChange.fire({ document: document }); | ||
}); | ||
connection.onDidChangeTextDocument(function (event) { | ||
var document = _this._documents[event.uri]; | ||
document.update(event); | ||
_this._onDidContentChange.fire({ document: document }); | ||
}); | ||
connection.onDidCloseTextDocument(function (event) { | ||
delete _this._documents[event.uri]; | ||
}); | ||
}; | ||
@@ -176,20 +174,30 @@ return TextDocuments; | ||
var shutdownHandler = null; | ||
connection.onRequest(protocol_1.ShutdownRequest.type, function (params) { | ||
shutdownReceived = true; | ||
if (shutdownHandler) { | ||
return shutdownHandler(params); | ||
} | ||
else { | ||
return undefined; | ||
} | ||
}); | ||
var incrementalSync = undefined; | ||
var initializeHandler = null; | ||
var protocolConnection = { | ||
listen: function () { return connection.listen(); }, | ||
onRequest: function (type, handler) { return connection.onRequest(type, handler); }, | ||
sendNotification: function (type, params) { return connection.sendNotification(type, params); }, | ||
onNotification: function (type, handler) { return connection.onNotification(type, handler); }, | ||
onInitialize: function (handler) { return connection.onRequest(protocol_1.InitializeRequest.type, handler); }, | ||
onShutdown: function (handler) { return shutdownHandler = handler; }, | ||
onExit: function (handler) { return connection.onNotification(protocol_1.ExitNotification.type, handler); }, | ||
get console() { return logger; }, | ||
get window() { return remoteWindow; }, | ||
onDidChangeConfiguration: function (handler) { return connection.onNotification(protocol_1.DidChangeConfigurationNotification.type, handler); }, | ||
onDidChangeFiles: function (handler) { return connection.onNotification(protocol_1.DidChangeFilesNotification.type, handler); }, | ||
__incrementalTextDocumentSync: undefined, | ||
onDidOpenTextDocument: function (handler) { return connection.onNotification(protocol_1.DidOpenTextDocumentNotification.type, handler); }, | ||
onDidChangeTextDocument: function (handler) { return connection.onNotification(protocol_1.DidChangeTextDocumentNotification.type, handler); }, | ||
onDidCloseTextDocument: function (handler) { return connection.onNotification(protocol_1.DidCloseTextDocumentNotification.type, handler); }, | ||
publishDiagnostics: function (params) { return connection.sendNotification(protocol_1.PublishDiagnosticsNotification.type, params); }, | ||
onHover: function (handler) { return connection.onRequest(protocol_1.HoverRequest.type, handler); }, | ||
dispose: function () { return connection.dispose(); } | ||
}; | ||
connection.onRequest(protocol_1.InitializeRequest.type, function (params) { | ||
if (initializeHandler) { | ||
var result_1 = initializeHandler(params); | ||
if (is.undefined(incrementalSync)) { | ||
return result_1; | ||
var result = initializeHandler(params); | ||
if (is.undefined(protocolConnection.__incrementalTextDocumentSync)) { | ||
return result; | ||
} | ||
return asThenable(result_1).then(function (value) { | ||
return asThenable(result).then(function (value) { | ||
if (value instanceof vscode_jsonrpc_1.ResponseError) { | ||
@@ -200,3 +208,3 @@ return value; | ||
if (capabilities) { | ||
capabilities.incrementalTextDocumentSync = incrementalSync; | ||
capabilities.incrementalTextDocumentSync = protocolConnection.__incrementalTextDocumentSync; | ||
} | ||
@@ -207,32 +215,17 @@ return value; | ||
else { | ||
var result_2 = { capabilities: { incrementalTextDocumentSync: false } }; | ||
return result_2; | ||
var result = { capabilities: { incrementalTextDocumentSync: false } }; | ||
return result; | ||
} | ||
}); | ||
var result = { | ||
listen: function () { return connection.listen(); }, | ||
onRequest: function (type, handler) { return connection.onRequest(type, handler); }, | ||
sendNotification: function (type, params) { return connection.sendNotification(type, params); }, | ||
onNotification: function (type, handler) { return connection.onNotification(type, handler); }, | ||
onInitialize: function (handler) { return connection.onRequest(protocol_1.InitializeRequest.type, handler); }, | ||
onShutdown: function (handler) { return shutdownHandler = handler; }, | ||
onExit: function (handler) { return connection.onNotification(protocol_1.ExitNotification.type, handler); }, | ||
get console() { return logger; }, | ||
get window() { return remoteWindow; }, | ||
onDidChangeConfiguration: function (handler) { return connection.onNotification(protocol_1.DidChangeConfigurationNotification.type, handler); }, | ||
onDidChangeFiles: function (handler) { return connection.onNotification(protocol_1.DidChangeFilesNotification.type, handler); }, | ||
onTextDocument: function (handler) { | ||
if (handler.incremental === true || handler.incremental === false) { | ||
incrementalSync = handler.incremental; | ||
} | ||
connection.onNotification(protocol_1.DidOpenTextDocumentNotification.type, handler.onDidOpenTextDocument); | ||
connection.onNotification(protocol_1.DidChangeTextDocumentNotification.type, handler.onDidChangeTextDocument); | ||
connection.onNotification(protocol_1.DidCloseTextDocumentNotification.type, handler.onDidCloseTextDocument); | ||
}, | ||
publishDiagnostics: function (params) { return connection.sendNotification(protocol_1.PublishDiagnosticsNotification.type, params); }, | ||
onHover: function (handler) { return connection.onRequest(protocol_1.HoverRequest.type, handler); }, | ||
dispose: function () { return connection.dispose(); } | ||
}; | ||
return result; | ||
connection.onRequest(protocol_1.ShutdownRequest.type, function (params) { | ||
shutdownReceived = true; | ||
if (shutdownHandler) { | ||
return shutdownHandler(params); | ||
} | ||
else { | ||
return undefined; | ||
} | ||
}); | ||
return protocolConnection; | ||
} | ||
exports.createConnection = createConnection; |
{ | ||
"name": "vscode-languageserver", | ||
"description": "Language server implementation for node", | ||
"version": "0.10.0-pre.29", | ||
"version": "0.10.0-pre.30", | ||
"author": "Microsoft Corporation", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
54423
1275