vscode-languageclient
Advanced tools
Comparing version 0.10.0-pre.16 to 0.10.0-pre.17
import * as cp from 'child_process'; | ||
import ChildProcess = cp.ChildProcess; | ||
import { TextDocument, FileSystemWatcher, LanguageSelector } from 'vscode'; | ||
import { TextDocument, FileSystemWatcher } from 'vscode'; | ||
import { INotificationHandler, RequestType, NotificationType } from 'vscode-jsonrpc'; | ||
@@ -41,6 +41,6 @@ import { FileEvent } from './protocol'; | ||
} | NodeModule | (() => Thenable<ChildProcess | StreamInfo>); | ||
configuration: string | string[]; | ||
fileWatchers: FileSystemWatcher | FileSystemWatcher[]; | ||
syncTextDocument(textDocument: TextDocument): boolean; | ||
languageSelector: LanguageSelector; | ||
configuration?: string | string[]; | ||
fileWatchers?: FileSystemWatcher | FileSystemWatcher[]; | ||
languageSelector?: string | string[]; | ||
syncTextDocument?: (textDocument: TextDocument) => boolean; | ||
} | ||
@@ -60,5 +60,7 @@ export declare class LanguageClient { | ||
private _diagnostics; | ||
private _syncExpression; | ||
private _fileEvents; | ||
private _delayer; | ||
constructor(name: string, options: ClientOptions, forceDebug?: boolean); | ||
private computeSyncExpression(); | ||
sendRequest<P, R, E>(type: RequestType<P, R, E>, params?: P): Thenable<R>; | ||
@@ -65,0 +67,0 @@ sendNotification<P>(type: NotificationType<P>, params?: P): void; |
@@ -61,2 +61,40 @@ /*--------------------------------------------------------- | ||
})(ClientState || (ClientState = {})); | ||
var FalseSyncExpression = (function () { | ||
function FalseSyncExpression() { | ||
} | ||
FalseSyncExpression.prototype.evaluate = function (textDocument) { | ||
return false; | ||
}; | ||
return FalseSyncExpression; | ||
})(); | ||
var LanguageIdExpression = (function () { | ||
function LanguageIdExpression(_id) { | ||
this._id = _id; | ||
} | ||
LanguageIdExpression.prototype.evaluate = function (textDocument) { | ||
return this._id === textDocument.languageId; | ||
}; | ||
return LanguageIdExpression; | ||
})(); | ||
var FunctionSyncExpression = (function () { | ||
function FunctionSyncExpression(_func) { | ||
this._func = _func; | ||
} | ||
FunctionSyncExpression.prototype.evaluate = function (textDocument) { | ||
return this._func(textDocument); | ||
}; | ||
return FunctionSyncExpression; | ||
})(); | ||
var CompositeSyncExpression = (function () { | ||
function CompositeSyncExpression(values, func) { | ||
this._expression = values.map(function (value) { return new LanguageIdExpression(value); }); | ||
if (func) { | ||
this._expression.push(new FunctionSyncExpression(func)); | ||
} | ||
} | ||
CompositeSyncExpression.prototype.evaluate = function (textDocument) { | ||
return this._expression.some(function (exp) { return exp.evaluate(textDocument); }); | ||
}; | ||
return CompositeSyncExpression; | ||
})(); | ||
var LanguageClient = (function () { | ||
@@ -68,2 +106,3 @@ function LanguageClient(name, options, forceDebug) { | ||
this._options = options; | ||
this._syncExpression = this.computeSyncExpression(); | ||
this._forceDebug = forceDebug; | ||
@@ -82,2 +121,21 @@ this._state = ClientState.Stopped; | ||
} | ||
LanguageClient.prototype.computeSyncExpression = function () { | ||
if (!this._options.languageSelector && !this._options.syncTextDocument) { | ||
return new FalseSyncExpression(); | ||
} | ||
if (this._options.syncTextDocument && !this._options.languageSelector) { | ||
return new FunctionSyncExpression(this._options.syncTextDocument); | ||
} | ||
if (!this._options.syncTextDocument && this._options.languageSelector) { | ||
if (is.string(this._options.languageSelector)) { | ||
return new LanguageIdExpression(this._options.languageSelector); | ||
} | ||
else { | ||
return new CompositeSyncExpression(this._options.languageSelector); | ||
} | ||
} | ||
if (this._options.syncTextDocument && this._options.languageSelector) { | ||
return new CompositeSyncExpression(is.string(this._options.languageSelector) ? [this._options.languageSelector] : this._options.languageSelector, this._options.syncTextDocument); | ||
} | ||
}; | ||
LanguageClient.prototype.sendRequest = function (type, params) { | ||
@@ -254,3 +312,3 @@ var _this = this; | ||
LanguageClient.prototype.onDidOpenTextDoument = function (connection, textDocument) { | ||
if (!this._options.syncTextDocument(textDocument)) { | ||
if (!this._syncExpression.evaluate(textDocument)) { | ||
return; | ||
@@ -261,3 +319,3 @@ } | ||
LanguageClient.prototype.onDidChangeTextDocument = function (connection, event) { | ||
if (!this._options.syncTextDocument(event.document)) { | ||
if (!this._syncExpression.evaluate(event.document)) { | ||
return; | ||
@@ -274,3 +332,3 @@ } | ||
LanguageClient.prototype.onDidCloseTextDoument = function (connection, textDocument) { | ||
if (!this._options.syncTextDocument(textDocument)) { | ||
if (!this._syncExpression.evaluate(textDocument)) { | ||
return; | ||
@@ -277,0 +335,0 @@ } |
{ | ||
"name": "vscode-languageclient", | ||
"description": "VSCode Language client implementation", | ||
"version": "0.10.0-pre.16", | ||
"version": "0.10.0-pre.17", | ||
"author": "Visual Studio Code Team", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
62378
1509