vscode-languageclient
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -12,2 +12,5 @@ import * as code from 'vscode'; | ||
export declare function asPosition(value: code.Position): proto.Position; | ||
export declare function asDiagnosticSeverity(value: code.DiagnosticSeverity): proto.DiagnosticSeverity; | ||
export declare function asDiagnostic(item: code.Diagnostic): proto.Diagnostic; | ||
export declare function asDiagnostics(items: code.Diagnostic[]): proto.Diagnostic[]; | ||
export declare function asCompletionItem(item: code.CompletionItem): proto.CompletionItem; | ||
@@ -18,1 +21,5 @@ export declare function asTextEdit(edit: code.TextEdit): proto.TextEdit; | ||
}): proto.ReferenceParams; | ||
export declare function asCodeActionContext(context: code.CodeActionContext): proto.CodeActionContext; | ||
export declare function asCommand(item: code.Command): proto.Command; | ||
export declare function asCodeLens(item: code.CodeLens): proto.CodeLens; | ||
export declare function asFormattingOptions(item: code.FormattingOptions): proto.FormattingOptions; |
@@ -6,4 +6,7 @@ /* -------------------------------------------------------------------------------------------- | ||
'use strict'; | ||
var code = require('vscode'); | ||
var proto = require('./protocol'); | ||
var is = require('./utils/is'); | ||
var protocolCompletionItem_1 = require('./protocolCompletionItem'); | ||
var protocolCodeLens_1 = require('./protocolCodeLens'); | ||
function asOpenTextDocumentParams(textDocument) { | ||
@@ -97,2 +100,29 @@ return { | ||
} | ||
function asDiagnosticSeverity(value) { | ||
switch (value) { | ||
case code.DiagnosticSeverity.Error: | ||
return proto.DiagnosticSeverity.Error; | ||
case code.DiagnosticSeverity.Warning: | ||
return proto.DiagnosticSeverity.Warning; | ||
case code.DiagnosticSeverity.Information: | ||
return proto.DiagnosticSeverity.Information; | ||
case code.DiagnosticSeverity.Hint: | ||
return proto.DiagnosticSeverity.Hint; | ||
} | ||
} | ||
exports.asDiagnosticSeverity = asDiagnosticSeverity; | ||
function asDiagnostic(item) { | ||
var result = proto.Diagnostic.create(asRange(item.range), item.message); | ||
set(item.severity, function () { return result.severity = asDiagnosticSeverity(item.severity); }); | ||
set(item.code, function () { return result.code = item.code; }); | ||
return result; | ||
} | ||
exports.asDiagnostic = asDiagnostic; | ||
function asDiagnostics(items) { | ||
if (is.undefined(items) || is.nil(items)) { | ||
return items; | ||
} | ||
return items.map(asDiagnostic); | ||
} | ||
exports.asDiagnostics = asDiagnostics; | ||
function asCompletionItem(item) { | ||
@@ -126,1 +156,30 @@ var result = { label: item.label }; | ||
exports.asReferenceParams = asReferenceParams; | ||
function asCodeActionContext(context) { | ||
if (is.undefined(context) || is.nil(context)) { | ||
return context; | ||
} | ||
return proto.CodeActionContext.create(asDiagnostics(context.diagnostics)); | ||
} | ||
exports.asCodeActionContext = asCodeActionContext; | ||
function asCommand(item) { | ||
var result = proto.Command.create(item.title, item.command); | ||
if (is.defined(item.arguments)) | ||
result.arguments = item.arguments; | ||
return result; | ||
} | ||
exports.asCommand = asCommand; | ||
function asCodeLens(item) { | ||
var result = proto.CodeLens.create(asRange(item.range)); | ||
if (is.defined(item.command)) | ||
result.command = asCommand(item.command); | ||
if (item instanceof protocolCodeLens_1.default) { | ||
if (is.defined(item.data)) | ||
result.data = item.data; | ||
} | ||
return result; | ||
} | ||
exports.asCodeLens = asCodeLens; | ||
function asFormattingOptions(item) { | ||
return { tabSize: item.tabSize, insertSpaces: item.insertSpaces }; | ||
} | ||
exports.asFormattingOptions = asFormattingOptions; |
@@ -5,4 +5,4 @@ import * as cp from 'child_process'; | ||
import { INotificationHandler, RequestType, NotificationType } from 'vscode-jsonrpc'; | ||
import { FileEvent } from './protocol'; | ||
export { RequestType, NotificationType, INotificationHandler }; | ||
import { Position, Range, Location, TextDocumentIdentifier, TextDocumentPosition, FileEvent } from './protocol'; | ||
export { RequestType, NotificationType, INotificationHandler, Position, Range, Location, TextDocumentIdentifier, TextDocumentPosition }; | ||
export interface StreamInfo { | ||
@@ -65,2 +65,3 @@ writer: NodeJS.WritableStream; | ||
private _childProcess; | ||
private _outputChannel; | ||
private _capabilites; | ||
@@ -77,2 +78,3 @@ private _listeners; | ||
sendRequest<P, R, E>(type: RequestType<P, R, E>, params?: P): Thenable<R>; | ||
private doSendRequest<P, R, E>(connection, type, params?); | ||
sendNotification<P>(type: NotificationType<P>, params?: P): void; | ||
@@ -110,2 +112,8 @@ onNotification<P>(type: NotificationType<P>, handler: INotificationHandler<P>): void; | ||
private hookWorkspaceSymbolProvider(connection); | ||
private hookCodeActionsProvider(documentSelector, connection); | ||
private hookCodeLensProvider(documentSelector, connection); | ||
private hookDocumentFormattingProvider(documentSelector, connection); | ||
private hookDocumentRangeFormattingProvider(documentSelector, connection); | ||
private hookDocumentOnTypeFormattingProvider(documentSelector, connection); | ||
private hookRenameProvider(documentSelector, connection); | ||
} | ||
@@ -112,0 +120,0 @@ export declare class SettingMonitor { |
244
lib/main.js
@@ -10,2 +10,7 @@ /* -------------------------------------------------------------------------------------------- | ||
var protocol_1 = require('./protocol'); | ||
exports.Position = protocol_1.Position; | ||
exports.Range = protocol_1.Range; | ||
exports.Location = protocol_1.Location; | ||
exports.TextDocumentIdentifier = protocol_1.TextDocumentIdentifier; | ||
exports.TextDocumentPosition = protocol_1.TextDocumentPosition; | ||
var c2p = require('./codeConverter'); | ||
@@ -120,2 +125,3 @@ var p2c = require('./protocolConverter'); | ||
this._childProcess = null; | ||
this._outputChannel = null; | ||
this._listeners = null; | ||
@@ -155,12 +161,15 @@ this._providers = null; | ||
return _this.resolveConnection().then(function (connection) { | ||
if (_this.isConnectionActive()) { | ||
_this.forceDocumentSync(); | ||
return connection.sendRequest(type, params); | ||
} | ||
else { | ||
return Promise.reject(new vscode_jsonrpc_1.ResponseError(vscode_jsonrpc_1.ErrorCodes.InternalError, 'Connection is already closed')); | ||
} | ||
return _this.doSendRequest(connection, type, params); | ||
}); | ||
}); | ||
}; | ||
LanguageClient.prototype.doSendRequest = function (connection, type, params) { | ||
if (this.isConnectionActive()) { | ||
this.forceDocumentSync(); | ||
return connection.sendRequest(type, params); | ||
} | ||
else { | ||
return Promise.reject(new vscode_jsonrpc_1.ResponseError(vscode_jsonrpc_1.ErrorCodes.InternalError, 'Connection is closed.')); | ||
} | ||
}; | ||
LanguageClient.prototype.sendNotification = function (type, params) { | ||
@@ -409,25 +418,23 @@ var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
var options = node.options || {}; | ||
var options = node.options || Object.create(null); | ||
options.execArgv = options.execArgv || []; | ||
options.cwd = options.cwd || vscode_1.workspace.rootPath; | ||
if (node.transport === TransportKind.ipc) { | ||
_this._childProcess = cp.fork(node.module, node.args || [], options); | ||
if (_this._childProcess.pid) { | ||
resolve(createConnection(new vscode_jsonrpc_1.IPCMessageReader(_this._childProcess), new vscode_jsonrpc_1.IPCMessageWriter(_this._childProcess))); | ||
electron.fork(node.module, node.args || [], options, function (error, cp) { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
reject(new Error("Unable to fork node using module " + node.module)); | ||
} | ||
} | ||
else { | ||
electron.fork(node.module, node.args || [], options, function (error, cp) { | ||
if (error) { | ||
reject(error); | ||
_this._childProcess = cp; | ||
if (node.transport === TransportKind.ipc) { | ||
_this._outputChannel = vscode_1.window.createOutputChannel(_this._name); | ||
cp.stdout.on('data', function (data) { | ||
_this._outputChannel.append(data.toString()); | ||
}); | ||
resolve(createConnection(new vscode_jsonrpc_1.IPCMessageReader(_this._childProcess), new vscode_jsonrpc_1.IPCMessageWriter(_this._childProcess))); | ||
} | ||
else { | ||
_this._childProcess = cp; | ||
resolve(createConnection(cp.stdout, cp.stdin)); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
@@ -555,2 +562,8 @@ } | ||
this.hookWorkspaceSymbolProvider(connection); | ||
this.hookCodeActionsProvider(documentSelector, connection); | ||
this.hookCodeLensProvider(documentSelector, connection); | ||
this.hookDocumentFormattingProvider(documentSelector, connection); | ||
this.hookDocumentRangeFormattingProvider(documentSelector, connection); | ||
this.hookDocumentOnTypeFormattingProvider(documentSelector, connection); | ||
this.hookRenameProvider(documentSelector, connection); | ||
}; | ||
@@ -564,23 +577,7 @@ LanguageClient.prototype.hookCompletionProvider = function (documentSelector, connection) { | ||
provideCompletionItems: function (document, position, token) { | ||
if (_this.isConnectionActive()) { | ||
_this.forceDocumentSync(); | ||
return connection.sendRequest(protocol_1.CompletionRequest.type, c2p.asTextDocumentPosition(document, position)).then(function (result) { | ||
return p2c.asCompletionItems(result); | ||
}); | ||
} | ||
else { | ||
return Promise.resolve([]); | ||
} | ||
return _this.doSendRequest(connection, protocol_1.CompletionRequest.type, c2p.asTextDocumentPosition(document, position)).then(p2c.asCompletionItems, function (error) { return Promise.resolve([]); }); | ||
}, | ||
resolveCompletionItem: this._capabilites.completionProvider.resolveProvider | ||
? function (item, token) { | ||
if (_this.isConnectionActive()) { | ||
_this.forceDocumentSync(); | ||
return connection.sendRequest(protocol_1.CompletionResolveRequest.type, c2p.asCompletionItem(item)).then(function (result) { | ||
return p2c.asCompletionItem(result); | ||
}); | ||
} | ||
else { | ||
return Promise.resolve(item); | ||
} | ||
return _this.doSendRequest(connection, protocol_1.CompletionResolveRequest.type, c2p.asCompletionItem(item)).then(p2c.asCompletionItem, function (error) { return Promise.resolve(item); }); | ||
} | ||
@@ -597,11 +594,3 @@ : undefined | ||
provideHover: function (document, position, token) { | ||
if (_this.isConnectionActive()) { | ||
_this.forceDocumentSync(); | ||
return connection.sendRequest(protocol_1.HoverRequest.type, c2p.asTextDocumentPosition(document, position)).then(function (result) { | ||
return p2c.asHover(result); | ||
}); | ||
} | ||
else { | ||
return Promise.reject(new Error('Connection is not active anymore')); | ||
} | ||
return _this.doSendRequest(connection, protocol_1.HoverRequest.type, c2p.asTextDocumentPosition(document, position)).then(p2c.asHover, function (error) { return Promise.resolve(null); }); | ||
} | ||
@@ -617,11 +606,3 @@ })); | ||
provideSignatureHelp: function (document, position, token) { | ||
if (_this.isConnectionActive()) { | ||
_this.forceDocumentSync(); | ||
return connection.sendRequest(protocol_1.SignatureHelpRequest.type, c2p.asTextDocumentPosition(document, position)).then(function (result) { | ||
return p2c.asSignatureHelp(result); | ||
}); | ||
} | ||
else { | ||
return Promise.resolve(null); | ||
} | ||
return _this.doSendRequest(connection, protocol_1.SignatureHelpRequest.type, c2p.asTextDocumentPosition(document, position)).then(p2c.asSignatureHelp, function (error) { return Promise.resolve(null); }); | ||
} | ||
@@ -637,11 +618,3 @@ }].concat(this._capabilites.signatureHelpProvider.triggerCharacters))); | ||
provideDefinition: function (document, position, token) { | ||
if (_this.isConnectionActive()) { | ||
_this.forceDocumentSync(); | ||
return connection.sendRequest(protocol_1.DefinitionRequest.type, c2p.asTextDocumentPosition(document, position)).then(function (result) { | ||
return p2c.asDefinitionResult(result); | ||
}); | ||
} | ||
else { | ||
return Promise.resolve(null); | ||
} | ||
return _this.doSendRequest(connection, protocol_1.DefinitionRequest.type, c2p.asTextDocumentPosition(document, position)).then(p2c.asDefinitionResult, function (error) { return Promise.resolve(null); }); | ||
} | ||
@@ -657,11 +630,3 @@ })); | ||
provideReferences: function (document, position, options, token) { | ||
if (_this.isConnectionActive()) { | ||
_this.forceDocumentSync(); | ||
return connection.sendRequest(protocol_1.ReferencesRequest.type, c2p.asReferenceParams(document, position, options)).then(function (result) { | ||
return p2c.asReferences(result); | ||
}); | ||
} | ||
else { | ||
return Promise.resolve(null); | ||
} | ||
return _this.doSendRequest(connection, protocol_1.ReferencesRequest.type, c2p.asReferenceParams(document, position, options)).then(p2c.asReferences, function (error) { return Promise.resolve([]); }); | ||
} | ||
@@ -677,11 +642,3 @@ })); | ||
provideDocumentHighlights: function (document, position, token) { | ||
if (_this.isConnectionActive()) { | ||
_this.forceDocumentSync(); | ||
return connection.sendRequest(protocol_1.DocumentHighlightRequest.type, c2p.asTextDocumentPosition(document, position)).then(function (result) { | ||
return p2c.asDocumentHighlights(result); | ||
}); | ||
} | ||
else { | ||
Promise.resolve(null); | ||
} | ||
return _this.doSendRequest(connection, protocol_1.DocumentHighlightRequest.type, c2p.asTextDocumentPosition(document, position)).then(p2c.asDocumentHighlights, function (error) { return Promise.resolve([]); }); | ||
} | ||
@@ -697,12 +654,3 @@ })); | ||
provideDocumentSymbols: function (document, token) { | ||
if (_this.isConnectionActive()) { | ||
_this.forceDocumentSync(); | ||
return connection.sendRequest(protocol_1.DocumentSymbolRequest.type, c2p.asTextDocumentIdentifier(document)).then(function (result) { | ||
return p2c.asSymbolInformations(result, document.uri); | ||
}); | ||
} | ||
else { | ||
Promise.resolve(null); | ||
} | ||
return null; | ||
return _this.doSendRequest(connection, protocol_1.DocumentSymbolRequest.type, c2p.asTextDocumentIdentifier(document)).then(p2c.asSymbolInformations, function (error) { return Promise.resolve([]); }); | ||
} | ||
@@ -718,15 +666,103 @@ })); | ||
provideWorkspaceSymbols: function (query, token) { | ||
if (_this.isConnectionActive()) { | ||
_this.forceDocumentSync(); | ||
return connection.sendRequest(protocol_1.WorkspaceSymbolRequest.type, { query: query }).then(function (result) { | ||
return p2c.asSymbolInformations(result); | ||
}); | ||
return _this.doSendRequest(connection, protocol_1.WorkspaceSymbolRequest.type, { query: query }).then(p2c.asSymbolInformations, function (error) { return Promise.resolve([]); }); | ||
} | ||
})); | ||
}; | ||
LanguageClient.prototype.hookCodeActionsProvider = function (documentSelector, connection) { | ||
var _this = this; | ||
if (!this._capabilites.codeActionProvider) { | ||
return; | ||
} | ||
this._providers.push(vscode_1.languages.registerCodeActionsProvider(documentSelector, { | ||
provideCodeActions: function (document, range, context, token) { | ||
var params = { | ||
textDocument: c2p.asTextDocumentIdentifier(document), | ||
range: c2p.asRange(range), | ||
context: c2p.asCodeActionContext(context) | ||
}; | ||
return _this.doSendRequest(connection, protocol_1.CodeActionRequest.type, params).then(p2c.asCommands, function (error) { return Promise.resolve([]); }); | ||
} | ||
})); | ||
}; | ||
LanguageClient.prototype.hookCodeLensProvider = function (documentSelector, connection) { | ||
var _this = this; | ||
if (!this._capabilites.codeLensProvider) { | ||
return; | ||
} | ||
this._providers.push(vscode_1.languages.registerCodeLensProvider(documentSelector, { | ||
provideCodeLenses: function (document, token) { | ||
return _this.doSendRequest(connection, protocol_1.CodeLensRequest.type, c2p.asTextDocumentIdentifier(document)).then(p2c.asCodeLenses, function (error) { return Promise.resolve([]); }); | ||
}, | ||
resolveCodeLens: (this._capabilites.codeLensProvider.resolveProvider) | ||
? function (codeLens, token) { | ||
return _this.doSendRequest(connection, protocol_1.CodeLensResolveRequest.type, c2p.asCodeLens(codeLens)).then(p2c.asCodeLens, function (error) { return codeLens; }); | ||
} | ||
else { | ||
Promise.resolve(null); | ||
} | ||
return null; | ||
: undefined | ||
})); | ||
}; | ||
LanguageClient.prototype.hookDocumentFormattingProvider = function (documentSelector, connection) { | ||
var _this = this; | ||
if (!this._capabilites.documentFormattingProvider) { | ||
return; | ||
} | ||
this._providers.push(vscode_1.languages.registerDocumentFormattingEditProvider(documentSelector, { | ||
provideDocumentFormattingEdits: function (document, options, token) { | ||
var params = { | ||
textDocument: c2p.asTextDocumentIdentifier(document), | ||
options: c2p.asFormattingOptions(options) | ||
}; | ||
return _this.doSendRequest(connection, protocol_1.DocumentFormattingRequest.type, params).then(p2c.asTextEdits, function (error) { return Promise.resolve([]); }); | ||
} | ||
})); | ||
}; | ||
LanguageClient.prototype.hookDocumentRangeFormattingProvider = function (documentSelector, connection) { | ||
var _this = this; | ||
if (!this._capabilites.documentRangeFormattingProvider) { | ||
return; | ||
} | ||
this._providers.push(vscode_1.languages.registerDocumentRangeFormattingEditProvider(documentSelector, { | ||
provideDocumentRangeFormattingEdits: function (document, range, options, token) { | ||
var params = { | ||
textDocument: c2p.asTextDocumentIdentifier(document), | ||
range: c2p.asRange(range), | ||
options: c2p.asFormattingOptions(options) | ||
}; | ||
return _this.doSendRequest(connection, protocol_1.DocumentRangeFormattingRequest.type, params).then(p2c.asTextEdits, function (error) { return Promise.resolve([]); }); | ||
} | ||
})); | ||
}; | ||
LanguageClient.prototype.hookDocumentOnTypeFormattingProvider = function (documentSelector, connection) { | ||
var _this = this; | ||
if (!this._capabilites.documentOnTypeFormattingProvider) { | ||
return; | ||
} | ||
var formatCapabilities = this._capabilites.documentOnTypeFormattingProvider; | ||
this._providers.push(vscode_1.languages.registerOnTypeFormattingEditProvider.apply(vscode_1.languages, [documentSelector, { | ||
provideOnTypeFormattingEdits: function (document, position, ch, options, token) { | ||
var params = { | ||
textDocument: c2p.asTextDocumentIdentifier(document), | ||
position: c2p.asPosition(position), | ||
ch: ch, | ||
options: c2p.asFormattingOptions(options) | ||
}; | ||
return _this.doSendRequest(connection, protocol_1.DocumentOnTypeFormattingRequest.type, params).then(p2c.asTextEdits, function (error) { return Promise.resolve([]); }); | ||
} | ||
}, formatCapabilities.firstTriggerCharacter].concat(formatCapabilities.moreTriggerCharacter))); | ||
}; | ||
LanguageClient.prototype.hookRenameProvider = function (documentSelector, connection) { | ||
var _this = this; | ||
if (!this._capabilites.renameProvider) { | ||
return; | ||
} | ||
this._providers.push(vscode_1.languages.registerRenameProvider(documentSelector, { | ||
provideRenameEdits: function (document, position, newName, token) { | ||
var params = { | ||
textDocument: c2p.asTextDocumentIdentifier(document), | ||
position: c2p.asPosition(position), | ||
newName: newName | ||
}; | ||
return _this.doSendRequest(connection, protocol_1.RenameRequest.type, params).then(p2c.asWorkspaceEdit, function (error) { return Promise.resolve(new Error(error.message)); }); | ||
} | ||
})); | ||
}; | ||
return LanguageClient; | ||
@@ -733,0 +769,0 @@ })(); |
@@ -29,3 +29,3 @@ import { RequestType, NotificationType } from 'vscode-jsonrpc'; | ||
/** | ||
* Completion options | ||
* Completion options. | ||
*/ | ||
@@ -44,3 +44,3 @@ export interface CompletionOptions { | ||
/** | ||
* Signature help options | ||
* Signature help options. | ||
*/ | ||
@@ -55,24 +55,88 @@ export interface SignatureHelpOptions { | ||
/** | ||
* Code Lens options. | ||
*/ | ||
export interface CodeLensOptions { | ||
/** | ||
* Code lens has a resolve provider as well. | ||
*/ | ||
resolveProvider?: boolean; | ||
} | ||
/** | ||
* Format document on type options | ||
*/ | ||
export interface DocumentOnTypeFormattingOptions { | ||
/** | ||
* A character on which formatting should be triggered, like `}`. | ||
*/ | ||
firstTriggerCharacter: string; | ||
/** | ||
* More trigger characters. | ||
*/ | ||
moreTriggerCharacter?: string[]; | ||
} | ||
/** | ||
* Defines the capabilities provided by the language | ||
* server | ||
* server. | ||
*/ | ||
export interface ServerCapabilities { | ||
/** Defines how text documents are synced. */ | ||
/** | ||
* Defines how text documents are synced. | ||
*/ | ||
textDocumentSync?: number; | ||
/** The server provides hover support. */ | ||
/** | ||
* The server provides hover support. | ||
*/ | ||
hoverProvider?: boolean; | ||
/** The server provides completion support. */ | ||
/** | ||
* The server provides completion support. | ||
*/ | ||
completionProvider?: CompletionOptions; | ||
/** The server provides signature help support. */ | ||
/** | ||
* The server provides signature help support. | ||
*/ | ||
signatureHelpProvider?: SignatureHelpOptions; | ||
/** The server provides goto definition support. */ | ||
/** | ||
* The server provides goto definition support. | ||
*/ | ||
definitionProvider?: boolean; | ||
/** The server provides find references support. */ | ||
/** | ||
* The server provides find references support. | ||
*/ | ||
referencesProvider?: boolean; | ||
/** The server provides document highlight support. */ | ||
/** | ||
* The server provides document highlight support. | ||
*/ | ||
documentHighlightProvider?: boolean; | ||
/** The server provides document symbol support. */ | ||
/** | ||
* The server provides document symbol support. | ||
*/ | ||
documentSymbolProvider?: boolean; | ||
/** The server provides workspace symbol support. */ | ||
/** | ||
* The server provides workspace symbol support. | ||
*/ | ||
workspaceSymbolProvider?: boolean; | ||
/** | ||
* The server provides code actions. | ||
*/ | ||
codeActionProvider?: boolean; | ||
/** | ||
* The server provides code lens. | ||
*/ | ||
codeLensProvider?: CodeLensOptions; | ||
/** | ||
* The server provides document formatting. | ||
*/ | ||
documentFormattingProvider?: boolean; | ||
/** | ||
* The server provides document range formatting. | ||
*/ | ||
documentRangeFormattingProvider?: boolean; | ||
/** | ||
* The server provides document formatting on typing. | ||
*/ | ||
documentOnTypeFormattingProvider?: DocumentOnTypeFormattingOptions; | ||
/** | ||
* The server provides rename support. | ||
*/ | ||
renameProvider?: boolean; | ||
} | ||
@@ -165,9 +229,17 @@ /** | ||
export declare enum MessageType { | ||
/** An error message. */ | ||
/** | ||
* An error message. | ||
*/ | ||
Error = 1, | ||
/** A warning message. */ | ||
/** | ||
* A warning message. | ||
*/ | ||
Warning = 2, | ||
/** An information message. */ | ||
/** | ||
* An information message. | ||
*/ | ||
Info = 3, | ||
/** A log message. */ | ||
/** | ||
* A log message. | ||
*/ | ||
Log = 4, | ||
@@ -229,2 +301,18 @@ } | ||
/** | ||
* The Position namespace provides helper functions to work with | ||
* [Position](#Position) literals. | ||
*/ | ||
export declare namespace Position { | ||
/** | ||
* Creates a new Position literal from the given line and character. | ||
* @param line The position's line. | ||
* @param character The position's character. | ||
*/ | ||
function create(line: number, character: number): Position; | ||
/** | ||
* Checks whether the given liternal conforms to the [Position](#Position) interface. | ||
*/ | ||
function is(value: any): value is Position; | ||
} | ||
/** | ||
* A range in a text document expressed as (zero-based) start and end positions. | ||
@@ -243,6 +331,30 @@ */ | ||
/** | ||
* The Range namespace provides helper functions to work with | ||
* [Range](#Range) literals. | ||
*/ | ||
export declare namespace Range { | ||
/** | ||
* Create a new Range liternal. | ||
* @param start The range's start position. | ||
* @param end The range's end position. | ||
*/ | ||
function create(start: Position, end: Position): Range; | ||
/** | ||
* Create a new Range liternal. | ||
* @param startLine The start line number. | ||
* @param startCharacter The start character. | ||
* @param endLine The end line number. | ||
* @param endCharacter The end character. | ||
*/ | ||
function create(startLine: number, startCharacter: number, endLine: number, endCharacter: number): Range; | ||
/** | ||
* Checks whether the given literal conforms to the [Range](#Range) interface. | ||
*/ | ||
function is(value: any): value is Range; | ||
} | ||
/** | ||
* Represents a location inside a resource, such as a line | ||
* inside a text file. | ||
*/ | ||
export declare class Location { | ||
export interface Location { | ||
uri: string; | ||
@@ -252,2 +364,18 @@ range: Range; | ||
/** | ||
* The Location namespace provides helper functions to work with | ||
* [Location](#Location) literals. | ||
*/ | ||
export declare namespace Location { | ||
/** | ||
* Creates a Location literal. | ||
* @param uri The location's uri. | ||
* @param range The location's range. | ||
*/ | ||
function create(uri: string, range: Range): Location; | ||
/** | ||
* Checks whether the given literal conforms to the [Location](#Location) interface. | ||
*/ | ||
function is(value: any): value is Location; | ||
} | ||
/** | ||
* A literal to identify a text document in the client. | ||
@@ -262,2 +390,17 @@ */ | ||
/** | ||
* The TextDocumentIdentifier namespace provides helper functions to work with | ||
* [TextDocumentIdentifier](#TextDocumentIdentifier) literals. | ||
*/ | ||
export declare namespace TextDocumentIdentifier { | ||
/** | ||
* Creates a new TextDocumentIdentifier literal. | ||
* @param uri The document's uri. | ||
*/ | ||
function create(uri: string): TextDocumentIdentifier; | ||
/** | ||
* Checks whether the given literal conforms to the [TextDocumentIdentifier](#TextDocumentIdentifier) interface. | ||
*/ | ||
function is(value: any): value is TextDocumentIdentifier; | ||
} | ||
/** | ||
* A literal to define the position in a text document. | ||
@@ -272,2 +415,18 @@ */ | ||
/** | ||
* The TextDocumentPosition namespace provides helper functions to work with | ||
* [TextDocumentPosition](#TextDocumentPosition) literals. | ||
*/ | ||
export declare namespace TextDocumentPosition { | ||
/** | ||
* Creates a new TextDocumentPosition | ||
* @param uri The document's uri. | ||
* @param position The position inside the document. | ||
*/ | ||
function create(uri: string, position: Position): TextDocumentPosition; | ||
/** | ||
* Checks whether the given literal conforms to the [TextDocumentPosition](#TextDocumentPosition) interface. | ||
*/ | ||
function is(value: any): value is TextDocumentPosition; | ||
} | ||
/** | ||
* The document open notification is sent from the client to the server to signal | ||
@@ -351,7 +510,13 @@ * newly opened text documents. The document's truth is now managed by the client | ||
export declare enum FileChangeType { | ||
/** The file got created. */ | ||
/** | ||
* The file got created. | ||
*/ | ||
Created = 1, | ||
/** The file got changed. */ | ||
/** | ||
* The file got changed. | ||
*/ | ||
Changed = 2, | ||
/** The file got deleted. */ | ||
/** | ||
* The file got deleted. | ||
*/ | ||
Deleted = 3, | ||
@@ -363,5 +528,9 @@ } | ||
export interface FileEvent { | ||
/** The file's uri. */ | ||
/** | ||
* The file's uri. | ||
*/ | ||
uri: string; | ||
/** teh change type. */ | ||
/** | ||
* The change type. | ||
*/ | ||
type: number; | ||
@@ -393,9 +562,17 @@ } | ||
export declare enum DiagnosticSeverity { | ||
/** Reports an error. */ | ||
/** | ||
* Reports an error. | ||
*/ | ||
Error = 1, | ||
/** Reports a warning. */ | ||
/** | ||
* Reports a warning. | ||
*/ | ||
Warning = 2, | ||
/** Reports an information. */ | ||
/** | ||
* Reports an information. | ||
*/ | ||
Information = 3, | ||
/** Reports a hint. */ | ||
/** | ||
* Reports a hint. | ||
*/ | ||
Hint = 4, | ||
@@ -426,2 +603,51 @@ } | ||
/** | ||
* The Diagnostic namespace provides helper functions to work with | ||
* [Diagnostic](#Diagnostic) literals. | ||
*/ | ||
export declare namespace Diagnostic { | ||
/** | ||
* Creates a new Diagnostic literal. | ||
*/ | ||
function create(range: Range, message: string, severity?: number, code?: number | string): Diagnostic; | ||
/** | ||
* Checks whether the given literal conforms to the [Diagnostic](#Diagnostic) interface. | ||
*/ | ||
function is(value: any): value is Diagnostic; | ||
} | ||
/** | ||
* Represents a reference to a command. Provides a title which | ||
* will be used to represent a command in the UI and, optionally, | ||
* an array of arguments which will be passed to the command handler | ||
* function when invoked. | ||
*/ | ||
export interface Command { | ||
/** | ||
* Title of the command, like `save`. | ||
*/ | ||
title: string; | ||
/** | ||
* The identifier of the actual command handler. | ||
*/ | ||
command: string; | ||
/** | ||
* Arguments that the command handler should be | ||
* invoked with. | ||
*/ | ||
arguments?: any[]; | ||
} | ||
/** | ||
* The Command namespace provides helper functions to work with | ||
* [Command](#Command) literals. | ||
*/ | ||
export declare namespace Command { | ||
/** | ||
* Creates a new Command literal. | ||
*/ | ||
function create(title: string, command: string, ...args: any[]): Command; | ||
/** | ||
* Checks whether the given literal conforms to the [Command](#Command) interface. | ||
*/ | ||
function is(value: any): value is Command; | ||
} | ||
/** | ||
* The kind of a completion entry. | ||
@@ -555,2 +781,67 @@ */ | ||
/** | ||
* A workspace edit represents changes to resource managed | ||
* in the workspace. | ||
*/ | ||
export interface WorkspaceEdit { | ||
/** | ||
* Holds changes to existing resources. | ||
*/ | ||
changes: { | ||
[uri: string]: TextEdit[]; | ||
}; | ||
} | ||
/** | ||
* A change to capture text edits for existing resources. | ||
*/ | ||
export interface TextEditChange { | ||
/** | ||
* Gets all text edits for this change. | ||
* | ||
* @return An array of text edits. | ||
*/ | ||
all(): TextEdit[]; | ||
/** | ||
* Clears the edits for this change. | ||
*/ | ||
clear(): void; | ||
/** | ||
* Insert the given text at the given position. | ||
* | ||
* @param position A position. | ||
* @param newText A string. | ||
*/ | ||
insert(position: Position, newText: string): void; | ||
/** | ||
* Replace the given range with given text for the given resource. | ||
* | ||
* @param range A range. | ||
* @param newText A string. | ||
*/ | ||
replace(range: Range, newText: string): void; | ||
/** | ||
* Delete the text at the given range. | ||
* | ||
* @param range A range. | ||
*/ | ||
delete(range: Range): void; | ||
} | ||
/** | ||
* A workspace change helps constructing changes to a workspace. | ||
*/ | ||
export declare class WorkspaceChange { | ||
private workspaceEdit; | ||
private textEditChanges; | ||
constructor(); | ||
/** | ||
* Returns the underlying [WorkspaceEdit](#WorkspaceEdit) literal | ||
* use to be returned from a workspace edit operation like rename. | ||
*/ | ||
edit: WorkspaceEdit; | ||
/** | ||
* Returns the [TextEditChange](#TextEditChange) to manage text edits | ||
* for resources. | ||
*/ | ||
getTextEditChange(uri: string): TextEditChange; | ||
} | ||
/** | ||
* Request to request completion at a given text document position. The request's | ||
@@ -851,1 +1142,212 @@ * parameter is of type [TextDocumentPosition](#TextDocumentPosition) the response | ||
} | ||
/** | ||
* Contains additional diagnostic information about the context in which | ||
* a [code action](#CodeActionProvider.provideCodeActions) is run. | ||
*/ | ||
export interface CodeActionContext { | ||
/** | ||
* An array of diagnostics. | ||
* | ||
* @readonly | ||
*/ | ||
diagnostics: Diagnostic[]; | ||
} | ||
/** | ||
* The CodeActionContext namespace provides helper functions to work with | ||
* [CodeActionContext](#CodeActionContext) literals. | ||
*/ | ||
export declare namespace CodeActionContext { | ||
/** | ||
* Creates a new CodeActionContext literal. | ||
*/ | ||
function create(diagnostics: Diagnostic[]): CodeActionContext; | ||
/** | ||
* Checks whether the given literal conforms to the [CodeActionContext](#CodeActionContext) interface. | ||
*/ | ||
function is(value: any): value is CodeActionContext; | ||
} | ||
/** | ||
* Params for the CodeActionRequest | ||
*/ | ||
export interface CodeActionParams { | ||
/** | ||
* The document in which the command was invoked. | ||
*/ | ||
textDocument: TextDocumentIdentifier; | ||
/** | ||
* The range for which the command was invoked. | ||
*/ | ||
range: Range; | ||
/** | ||
* Context carrying additional information. | ||
*/ | ||
context: CodeActionContext; | ||
} | ||
/** | ||
* A request to provide commands for the given text document and range. | ||
*/ | ||
export declare namespace CodeActionRequest { | ||
const type: RequestType<CodeActionParams, Command[], void>; | ||
} | ||
/** | ||
* A code lens represents a [command](#Command) that should be shown along with | ||
* source text, like the number of references, a way to run tests, etc. | ||
* | ||
* A code lens is _unresolved_ when no command is associated to it. For performance | ||
* reasons the creation of a code lens and resolving should be done to two stages. | ||
*/ | ||
export interface CodeLens { | ||
/** | ||
* The range in which this code lens is valid. Should only span a single line. | ||
*/ | ||
range: Range; | ||
/** | ||
* The command this code lens represents. | ||
*/ | ||
command?: Command; | ||
/** | ||
* An data entry field that is preserved on a code lens item between | ||
* a [CodeLensRequest](#CodeLensRequest) and a [CodeLensResolveRequest] | ||
* (#CodeLensResolveRequest) | ||
*/ | ||
data?: any; | ||
} | ||
/** | ||
* The CodeLens namespace provides helper functions to work with | ||
* [CodeLens](#CodeLens) literals. | ||
*/ | ||
export declare namespace CodeLens { | ||
/** | ||
* Creates a new CodeLens literal. | ||
*/ | ||
function create(range: Range, data?: any): CodeLens; | ||
/** | ||
* Checks whether the given literal conforms to the [CodeLens](#CodeLens) interface. | ||
*/ | ||
function is(value: any): value is CodeLens; | ||
} | ||
/** | ||
* A request to provide code lens for the given text document. | ||
*/ | ||
export declare namespace CodeLensRequest { | ||
const type: RequestType<TextDocumentIdentifier, CodeLens[], void>; | ||
} | ||
/** | ||
* A request to resolve a command for a given code lens. | ||
*/ | ||
export declare namespace CodeLensResolveRequest { | ||
const type: RequestType<CodeLens, CodeLens, void>; | ||
} | ||
/** | ||
* Value-object describing what options formatting should use. | ||
*/ | ||
export interface FormattingOptions { | ||
/** | ||
* Size of a tab in spaces. | ||
*/ | ||
tabSize: number; | ||
/** | ||
* Prefer spaces over tabs. | ||
*/ | ||
insertSpaces: boolean; | ||
/** | ||
* Signature for further properties. | ||
*/ | ||
[key: string]: boolean | number | string; | ||
} | ||
/** | ||
* The FormattingOptions namespace provides helper functions to work with | ||
* [FormattingOptions](#FormattingOptions) literals. | ||
*/ | ||
export declare namespace FormattingOptions { | ||
/** | ||
* Creates a new FormattingOptions literal. | ||
*/ | ||
function create(tabSize: number, insertSpaces: boolean): FormattingOptions; | ||
/** | ||
* Checks whether the given literal conforms to the [FormattingOptions](#FormattingOptions) interface. | ||
*/ | ||
function is(value: any): value is FormattingOptions; | ||
} | ||
export interface DocumentFormattingParams { | ||
/** | ||
* The document to format. | ||
*/ | ||
textDocument: TextDocumentIdentifier; | ||
/** | ||
* The format options | ||
*/ | ||
options: FormattingOptions; | ||
} | ||
/** | ||
* A request to to format a whole document. | ||
*/ | ||
export declare namespace DocumentFormattingRequest { | ||
const type: RequestType<DocumentFormattingParams, TextEdit[], void>; | ||
} | ||
export interface DocumentRangeFormattingParams { | ||
/** | ||
* The document to format. | ||
*/ | ||
textDocument: TextDocumentIdentifier; | ||
/** | ||
* The range to format | ||
*/ | ||
range: Range; | ||
/** | ||
* The format options | ||
*/ | ||
options: FormattingOptions; | ||
} | ||
/** | ||
* A request to to format a range in a document. | ||
*/ | ||
export declare namespace DocumentRangeFormattingRequest { | ||
const type: RequestType<DocumentRangeFormattingParams, TextEdit[], void>; | ||
} | ||
export interface DocumentOnTypeFormattingParams { | ||
/** | ||
* The document to format. | ||
*/ | ||
textDocument: TextDocumentIdentifier; | ||
/** | ||
* The position at which this request was send. | ||
*/ | ||
position: Position; | ||
/** | ||
* The character that has been typed. | ||
*/ | ||
ch: string; | ||
/** | ||
* The format options. | ||
*/ | ||
options: FormattingOptions; | ||
} | ||
/** | ||
* A request to format a document on type. | ||
*/ | ||
export declare namespace DocumentOnTypeFormattingRequest { | ||
const type: RequestType<DocumentOnTypeFormattingParams, TextEdit[], void>; | ||
} | ||
export interface RenameParams { | ||
/** | ||
* The document to format. | ||
*/ | ||
textDocument: TextDocumentIdentifier; | ||
/** | ||
* The position at which this request was send. | ||
*/ | ||
position: Position; | ||
/** | ||
* The new name of the symbol. If the given name is not valid the | ||
* request must return a [ResponseError](#ResponseError) with an | ||
* appropriate message set. | ||
*/ | ||
newName: string; | ||
} | ||
/** | ||
* A request to rename a symbol. | ||
*/ | ||
export declare namespace RenameRequest { | ||
const type: RequestType<RenameParams, WorkspaceEdit, void>; | ||
} |
@@ -6,3 +6,3 @@ /* -------------------------------------------------------------------------------------------- | ||
'use strict'; | ||
var is = require('./utils/is'); | ||
var Is = require('./utils/is'); | ||
/** | ||
@@ -77,9 +77,17 @@ * Defines how the host (editor) should sync | ||
(function (MessageType) { | ||
/** An error message. */ | ||
/** | ||
* An error message. | ||
*/ | ||
MessageType[MessageType["Error"] = 1] = "Error"; | ||
/** A warning message. */ | ||
/** | ||
* A warning message. | ||
*/ | ||
MessageType[MessageType["Warning"] = 2] = "Warning"; | ||
/** An information message. */ | ||
/** | ||
* An information message. | ||
*/ | ||
MessageType[MessageType["Info"] = 3] = "Info"; | ||
/** A log message. */ | ||
/** | ||
* A log message. | ||
*/ | ||
MessageType[MessageType["Log"] = 4] = "Log"; | ||
@@ -105,12 +113,124 @@ })(exports.MessageType || (exports.MessageType = {})); | ||
/** | ||
* Represents a location inside a resource, such as a line | ||
* inside a text file. | ||
* The Position namespace provides helper functions to work with | ||
* [Position](#Position) literals. | ||
*/ | ||
var Location = (function () { | ||
function Location() { | ||
var Position; | ||
(function (Position) { | ||
/** | ||
* Creates a new Position literal from the given line and character. | ||
* @param line The position's line. | ||
* @param character The position's character. | ||
*/ | ||
function create(line, character) { | ||
return { line: line, character: character }; | ||
} | ||
return Location; | ||
})(); | ||
exports.Location = Location; | ||
Position.create = create; | ||
/** | ||
* Checks whether the given liternal conforms to the [Position](#Position) interface. | ||
*/ | ||
function is(value) { | ||
var candidate = value; | ||
return Is.defined(candidate) && Is.number(candidate.line) && Is.number(candidate.character); | ||
} | ||
Position.is = is; | ||
})(Position = exports.Position || (exports.Position = {})); | ||
/** | ||
* The Range namespace provides helper functions to work with | ||
* [Range](#Range) literals. | ||
*/ | ||
var Range; | ||
(function (Range) { | ||
function create(one, two, three, four) { | ||
if (Is.number(one) && Is.number(two) && Is.number(three) && Is.number(four)) { | ||
return { start: Position.create(one, two), end: Position.create(three, four) }; | ||
} | ||
else if (Position.is(one) && Position.is(two)) { | ||
return { start: one, end: two }; | ||
} | ||
else { | ||
throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]"); | ||
} | ||
} | ||
Range.create = create; | ||
/** | ||
* Checks whether the given literal conforms to the [Range](#Range) interface. | ||
*/ | ||
function is(value) { | ||
var candidate = value; | ||
return Is.defined(candidate) && Position.is(candidate.start) && Position.is(candidate.end); | ||
} | ||
Range.is = is; | ||
})(Range = exports.Range || (exports.Range = {})); | ||
/** | ||
* The Location namespace provides helper functions to work with | ||
* [Location](#Location) literals. | ||
*/ | ||
var Location; | ||
(function (Location) { | ||
/** | ||
* Creates a Location literal. | ||
* @param uri The location's uri. | ||
* @param range The location's range. | ||
*/ | ||
function create(uri, range) { | ||
return { uri: uri, range: range }; | ||
} | ||
Location.create = create; | ||
/** | ||
* Checks whether the given literal conforms to the [Location](#Location) interface. | ||
*/ | ||
function is(value) { | ||
var candidate = value; | ||
return Is.defined(candidate) && Range.is(candidate) && (Is.string(candidate.uri) || Is.undefined(candidate.uri)); | ||
} | ||
Location.is = is; | ||
})(Location = exports.Location || (exports.Location = {})); | ||
/** | ||
* The TextDocumentIdentifier namespace provides helper functions to work with | ||
* [TextDocumentIdentifier](#TextDocumentIdentifier) literals. | ||
*/ | ||
var TextDocumentIdentifier; | ||
(function (TextDocumentIdentifier) { | ||
/** | ||
* Creates a new TextDocumentIdentifier literal. | ||
* @param uri The document's uri. | ||
*/ | ||
function create(uri) { | ||
return { uri: uri }; | ||
} | ||
TextDocumentIdentifier.create = create; | ||
/** | ||
* Checks whether the given literal conforms to the [TextDocumentIdentifier](#TextDocumentIdentifier) interface. | ||
*/ | ||
function is(value) { | ||
var candidate = value; | ||
return Is.defined(candidate) && Is.string(candidate.uri); | ||
} | ||
TextDocumentIdentifier.is = is; | ||
})(TextDocumentIdentifier = exports.TextDocumentIdentifier || (exports.TextDocumentIdentifier = {})); | ||
/** | ||
* The TextDocumentPosition namespace provides helper functions to work with | ||
* [TextDocumentPosition](#TextDocumentPosition) literals. | ||
*/ | ||
var TextDocumentPosition; | ||
(function (TextDocumentPosition) { | ||
/** | ||
* Creates a new TextDocumentPosition | ||
* @param uri The document's uri. | ||
* @param position The position inside the document. | ||
*/ | ||
function create(uri, position) { | ||
return { uri: uri, position: position }; | ||
} | ||
TextDocumentPosition.create = create; | ||
/** | ||
* Checks whether the given literal conforms to the [TextDocumentPosition](#TextDocumentPosition) interface. | ||
*/ | ||
function is(value) { | ||
var candidate = value; | ||
return Is.defined(candidate) && TextDocumentIdentifier.is(candidate) && Position.is(candidate.position); | ||
} | ||
TextDocumentPosition.is = is; | ||
})(TextDocumentPosition = exports.TextDocumentPosition || (exports.TextDocumentPosition = {})); | ||
/** | ||
* The document open notification is sent from the client to the server to signal | ||
@@ -157,7 +277,13 @@ * newly opened text documents. The document's truth is now managed by the client | ||
(function (FileChangeType) { | ||
/** The file got created. */ | ||
/** | ||
* The file got created. | ||
*/ | ||
FileChangeType[FileChangeType["Created"] = 1] = "Created"; | ||
/** The file got changed. */ | ||
/** | ||
* The file got changed. | ||
*/ | ||
FileChangeType[FileChangeType["Changed"] = 2] = "Changed"; | ||
/** The file got deleted. */ | ||
/** | ||
* The file got deleted. | ||
*/ | ||
FileChangeType[FileChangeType["Deleted"] = 3] = "Deleted"; | ||
@@ -173,3 +299,3 @@ })(exports.FileChangeType || (exports.FileChangeType = {})); | ||
(function (PublishDiagnosticsNotification) { | ||
PublishDiagnosticsNotification.type = { method: 'textDocument/publishDiagnostics' }; | ||
PublishDiagnosticsNotification.type = { get method() { return 'textDocument/publishDiagnostics'; } }; | ||
})(PublishDiagnosticsNotification = exports.PublishDiagnosticsNotification || (exports.PublishDiagnosticsNotification = {})); | ||
@@ -180,12 +306,83 @@ /** | ||
(function (DiagnosticSeverity) { | ||
/** Reports an error. */ | ||
/** | ||
* Reports an error. | ||
*/ | ||
DiagnosticSeverity[DiagnosticSeverity["Error"] = 1] = "Error"; | ||
/** Reports a warning. */ | ||
/** | ||
* Reports a warning. | ||
*/ | ||
DiagnosticSeverity[DiagnosticSeverity["Warning"] = 2] = "Warning"; | ||
/** Reports an information. */ | ||
/** | ||
* Reports an information. | ||
*/ | ||
DiagnosticSeverity[DiagnosticSeverity["Information"] = 3] = "Information"; | ||
/** Reports a hint. */ | ||
/** | ||
* Reports a hint. | ||
*/ | ||
DiagnosticSeverity[DiagnosticSeverity["Hint"] = 4] = "Hint"; | ||
})(exports.DiagnosticSeverity || (exports.DiagnosticSeverity = {})); | ||
var DiagnosticSeverity = exports.DiagnosticSeverity; | ||
/** | ||
* The Diagnostic namespace provides helper functions to work with | ||
* [Diagnostic](#Diagnostic) literals. | ||
*/ | ||
var Diagnostic; | ||
(function (Diagnostic) { | ||
/** | ||
* Creates a new Diagnostic literal. | ||
*/ | ||
function create(range, message, severity, code) { | ||
var result = { range: range, message: message }; | ||
if (Is.defined(severity)) { | ||
result.severity = severity; | ||
} | ||
if (Is.defined(code)) { | ||
result.code = code; | ||
} | ||
return result; | ||
} | ||
Diagnostic.create = create; | ||
/** | ||
* Checks whether the given literal conforms to the [Diagnostic](#Diagnostic) interface. | ||
*/ | ||
function is(value) { | ||
var candidate = value; | ||
return Is.defined(candidate) | ||
&& Range.is(candidate.range) | ||
&& Is.string(candidate.message) | ||
&& (Is.number(candidate.severity) || Is.undefined(candidate.severity)) | ||
&& (Is.number(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code)); | ||
} | ||
Diagnostic.is = is; | ||
})(Diagnostic = exports.Diagnostic || (exports.Diagnostic = {})); | ||
/** | ||
* The Command namespace provides helper functions to work with | ||
* [Command](#Command) literals. | ||
*/ | ||
var Command; | ||
(function (Command) { | ||
/** | ||
* Creates a new Command literal. | ||
*/ | ||
function create(title, command) { | ||
var args = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
args[_i - 2] = arguments[_i]; | ||
} | ||
var result = { title: title, command: command }; | ||
if (Is.defined(args) && args.length > 0) { | ||
result.arguments = args; | ||
} | ||
return result; | ||
} | ||
Command.create = create; | ||
/** | ||
* Checks whether the given literal conforms to the [Command](#Command) interface. | ||
*/ | ||
function is(value) { | ||
var candidate = value; | ||
return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.title); | ||
} | ||
Command.is = is; | ||
})(Command = exports.Command || (exports.Command = {})); | ||
//---- Completion Support -------------------------- | ||
@@ -265,2 +462,61 @@ /** | ||
/** | ||
* A workspace change helps constructing changes to a workspace. | ||
*/ | ||
var WorkspaceChange = (function () { | ||
function WorkspaceChange() { | ||
this.workspaceEdit = { | ||
changes: Object.create(null) | ||
}; | ||
this.textEditChanges = Object.create(null); | ||
} | ||
Object.defineProperty(WorkspaceChange.prototype, "edit", { | ||
/** | ||
* Returns the underlying [WorkspaceEdit](#WorkspaceEdit) literal | ||
* use to be returned from a workspace edit operation like rename. | ||
*/ | ||
get: function () { | ||
return this.workspaceEdit; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
* Returns the [TextEditChange](#TextEditChange) to manage text edits | ||
* for resources. | ||
*/ | ||
WorkspaceChange.prototype.getTextEditChange = function (uri) { | ||
var TextEditChangeImpl = (function () { | ||
function TextEditChangeImpl(edits) { | ||
this.edits = edits; | ||
} | ||
TextEditChangeImpl.prototype.insert = function (position, newText) { | ||
this.edits.push(TextEdit.insert(position, newText)); | ||
}; | ||
TextEditChangeImpl.prototype.replace = function (range, newText) { | ||
this.edits.push(TextEdit.replace(range, newText)); | ||
}; | ||
TextEditChangeImpl.prototype.delete = function (range) { | ||
this.edits.push(TextEdit.del(range)); | ||
}; | ||
TextEditChangeImpl.prototype.all = function () { | ||
return this.edits; | ||
}; | ||
TextEditChangeImpl.prototype.clear = function () { | ||
this.edits.splice(0, this.edits.length); | ||
}; | ||
return TextEditChangeImpl; | ||
})(); | ||
var result = this.textEditChanges[uri]; | ||
if (!result) { | ||
var edits = []; | ||
this.workspaceEdit.changes[uri] = edits; | ||
result = new TextEditChangeImpl(edits); | ||
this.textEditChanges[uri] = result; | ||
} | ||
return result; | ||
}; | ||
return WorkspaceChange; | ||
})(); | ||
exports.WorkspaceChange = WorkspaceChange; | ||
/** | ||
* Request to request completion at a given text document position. The request's | ||
@@ -272,3 +528,3 @@ * parameter is of type [TextDocumentPosition](#TextDocumentPosition) the response | ||
(function (CompletionRequest) { | ||
CompletionRequest.type = { method: 'textDocument/completion' }; | ||
CompletionRequest.type = { get method() { return 'textDocument/completion'; } }; | ||
})(CompletionRequest = exports.CompletionRequest || (exports.CompletionRequest = {})); | ||
@@ -282,3 +538,3 @@ /** | ||
(function (CompletionResolveRequest) { | ||
CompletionResolveRequest.type = { method: 'completionItem/resolve' }; | ||
CompletionResolveRequest.type = { get method() { return 'completionItem/resolve'; } }; | ||
})(CompletionResolveRequest = exports.CompletionResolveRequest || (exports.CompletionResolveRequest = {})); | ||
@@ -292,3 +548,3 @@ /** | ||
(function (HoverRequest) { | ||
HoverRequest.type = { method: 'textDocument/hover' }; | ||
HoverRequest.type = { get method() { return 'textDocument/hover'; } }; | ||
})(HoverRequest = exports.HoverRequest || (exports.HoverRequest = {})); | ||
@@ -325,6 +581,6 @@ /** | ||
var result = { label: label }; | ||
if (is.defined(documentation)) { | ||
if (Is.defined(documentation)) { | ||
result.documentation = documentation; | ||
} | ||
if (is.defined(parameters)) { | ||
if (Is.defined(parameters)) { | ||
result.parameters = parameters; | ||
@@ -341,3 +597,3 @@ } | ||
(function (SignatureHelpRequest) { | ||
SignatureHelpRequest.type = { method: 'textDocument/signatureHelp' }; | ||
SignatureHelpRequest.type = { get method() { return 'textDocument/signatureHelp'; } }; | ||
})(SignatureHelpRequest = exports.SignatureHelpRequest || (exports.SignatureHelpRequest = {})); | ||
@@ -352,3 +608,3 @@ /** | ||
(function (DefinitionRequest) { | ||
DefinitionRequest.type = { method: 'textDocument/definition' }; | ||
DefinitionRequest.type = { get method() { return 'textDocument/definition'; } }; | ||
})(DefinitionRequest = exports.DefinitionRequest || (exports.DefinitionRequest = {})); | ||
@@ -363,3 +619,3 @@ /** | ||
(function (ReferencesRequest) { | ||
ReferencesRequest.type = { method: 'textDocument/references' }; | ||
ReferencesRequest.type = { get method() { return 'textDocument/references'; } }; | ||
})(ReferencesRequest = exports.ReferencesRequest || (exports.ReferencesRequest = {})); | ||
@@ -397,3 +653,3 @@ //---- Document Highlight ---------------------------------- | ||
var result = { range: range }; | ||
if (is.number(kind)) { | ||
if (Is.number(kind)) { | ||
result.kind = kind; | ||
@@ -413,3 +669,3 @@ } | ||
(function (DocumentHighlightRequest) { | ||
DocumentHighlightRequest.type = { method: 'textDocument/documentHighlight' }; | ||
DocumentHighlightRequest.type = { get method() { return 'textDocument/documentHighlight'; } }; | ||
})(DocumentHighlightRequest = exports.DocumentHighlightRequest || (exports.DocumentHighlightRequest = {})); | ||
@@ -473,3 +729,3 @@ //---- Document Symbol Provider --------------------------- | ||
(function (DocumentSymbolRequest) { | ||
DocumentSymbolRequest.type = { method: 'textDocument/documentSymbol' }; | ||
DocumentSymbolRequest.type = { get method() { return 'textDocument/documentSymbol'; } }; | ||
})(DocumentSymbolRequest = exports.DocumentSymbolRequest || (exports.DocumentSymbolRequest = {})); | ||
@@ -484,3 +740,121 @@ /** | ||
(function (WorkspaceSymbolRequest) { | ||
WorkspaceSymbolRequest.type = { method: 'workspace/symbol' }; | ||
WorkspaceSymbolRequest.type = { get method() { return 'workspace/symbol'; } }; | ||
})(WorkspaceSymbolRequest = exports.WorkspaceSymbolRequest || (exports.WorkspaceSymbolRequest = {})); | ||
/** | ||
* The CodeActionContext namespace provides helper functions to work with | ||
* [CodeActionContext](#CodeActionContext) literals. | ||
*/ | ||
var CodeActionContext; | ||
(function (CodeActionContext) { | ||
/** | ||
* Creates a new CodeActionContext literal. | ||
*/ | ||
function create(diagnostics) { | ||
return { diagnostics: diagnostics }; | ||
} | ||
CodeActionContext.create = create; | ||
/** | ||
* Checks whether the given literal conforms to the [CodeActionContext](#CodeActionContext) interface. | ||
*/ | ||
function is(value) { | ||
var candidate = value; | ||
return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is); | ||
} | ||
CodeActionContext.is = is; | ||
})(CodeActionContext = exports.CodeActionContext || (exports.CodeActionContext = {})); | ||
/** | ||
* A request to provide commands for the given text document and range. | ||
*/ | ||
var CodeActionRequest; | ||
(function (CodeActionRequest) { | ||
CodeActionRequest.type = { get method() { return 'textDocument/codeAction'; } }; | ||
})(CodeActionRequest = exports.CodeActionRequest || (exports.CodeActionRequest = {})); | ||
/** | ||
* The CodeLens namespace provides helper functions to work with | ||
* [CodeLens](#CodeLens) literals. | ||
*/ | ||
var CodeLens; | ||
(function (CodeLens) { | ||
/** | ||
* Creates a new CodeLens literal. | ||
*/ | ||
function create(range, data) { | ||
var result = { range: range }; | ||
if (Is.defined(data)) | ||
result.data = data; | ||
return result; | ||
} | ||
CodeLens.create = create; | ||
/** | ||
* Checks whether the given literal conforms to the [CodeLens](#CodeLens) interface. | ||
*/ | ||
function is(value) { | ||
var candidate = value; | ||
return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command)); | ||
} | ||
CodeLens.is = is; | ||
})(CodeLens = exports.CodeLens || (exports.CodeLens = {})); | ||
/** | ||
* A request to provide code lens for the given text document. | ||
*/ | ||
var CodeLensRequest; | ||
(function (CodeLensRequest) { | ||
CodeLensRequest.type = { get method() { return 'textDocument/codeLens'; } }; | ||
})(CodeLensRequest = exports.CodeLensRequest || (exports.CodeLensRequest = {})); | ||
/** | ||
* A request to resolve a command for a given code lens. | ||
*/ | ||
var CodeLensResolveRequest; | ||
(function (CodeLensResolveRequest) { | ||
CodeLensResolveRequest.type = { get method() { return 'codeLens/resolve'; } }; | ||
})(CodeLensResolveRequest = exports.CodeLensResolveRequest || (exports.CodeLensResolveRequest = {})); | ||
/** | ||
* The FormattingOptions namespace provides helper functions to work with | ||
* [FormattingOptions](#FormattingOptions) literals. | ||
*/ | ||
var FormattingOptions; | ||
(function (FormattingOptions) { | ||
/** | ||
* Creates a new FormattingOptions literal. | ||
*/ | ||
function create(tabSize, insertSpaces) { | ||
return { tabSize: tabSize, insertSpaces: insertSpaces }; | ||
} | ||
FormattingOptions.create = create; | ||
/** | ||
* Checks whether the given literal conforms to the [FormattingOptions](#FormattingOptions) interface. | ||
*/ | ||
function is(value) { | ||
var candidate = value; | ||
return Is.defined(candidate) && Is.number(candidate.tabSize) && Is.boolean(candidate.insertSpaces); | ||
} | ||
FormattingOptions.is = is; | ||
})(FormattingOptions = exports.FormattingOptions || (exports.FormattingOptions = {})); | ||
/** | ||
* A request to to format a whole document. | ||
*/ | ||
var DocumentFormattingRequest; | ||
(function (DocumentFormattingRequest) { | ||
DocumentFormattingRequest.type = { get method() { return 'textDocument/formatting'; } }; | ||
})(DocumentFormattingRequest = exports.DocumentFormattingRequest || (exports.DocumentFormattingRequest = {})); | ||
/** | ||
* A request to to format a range in a document. | ||
*/ | ||
var DocumentRangeFormattingRequest; | ||
(function (DocumentRangeFormattingRequest) { | ||
DocumentRangeFormattingRequest.type = { get method() { return 'textDocument/rangeFormatting'; } }; | ||
})(DocumentRangeFormattingRequest = exports.DocumentRangeFormattingRequest || (exports.DocumentRangeFormattingRequest = {})); | ||
/** | ||
* A request to format a document on type. | ||
*/ | ||
var DocumentOnTypeFormattingRequest; | ||
(function (DocumentOnTypeFormattingRequest) { | ||
DocumentOnTypeFormattingRequest.type = { get method() { return 'textDocument/onTypeFormatting'; } }; | ||
})(DocumentOnTypeFormattingRequest = exports.DocumentOnTypeFormattingRequest || (exports.DocumentOnTypeFormattingRequest = {})); | ||
/** | ||
* A request to rename a symbol. | ||
*/ | ||
var RenameRequest; | ||
(function (RenameRequest) { | ||
RenameRequest.type = { get method() { return 'textDocument/rename'; } }; | ||
})(RenameRequest = exports.RenameRequest || (exports.RenameRequest = {})); |
@@ -13,2 +13,3 @@ import * as code from 'vscode'; | ||
export declare function asTextEdit(edit: proto.TextEdit): code.TextEdit; | ||
export declare function asTextEdits(items: proto.TextEdit[]): code.TextEdit[]; | ||
export declare function asSignatureHelp(item: proto.SignatureHelp): code.SignatureHelp; | ||
@@ -27,1 +28,6 @@ export declare function asSignatureInformations(items: proto.SignatureInformation[]): code.SignatureInformation[]; | ||
export declare function asSymbolInformation(item: proto.SymbolInformation, uri?: code.Uri): code.SymbolInformation; | ||
export declare function asCommand(item: proto.Command): code.Command; | ||
export declare function asCommands(items: proto.Command[]): code.Command[]; | ||
export declare function asCodeLens(item: proto.CodeLens): code.CodeLens; | ||
export declare function asCodeLenses(items: proto.CodeLens[]): code.CodeLens[]; | ||
export declare function asWorkspaceEdit(item: proto.WorkspaceEdit): code.WorkspaceEdit; |
@@ -10,2 +10,3 @@ /* -------------------------------------------------------------------------------------------- | ||
var protocolCompletionItem_1 = require('./protocolCompletionItem'); | ||
var protocolCodeLens_1 = require('./protocolCodeLens'); | ||
function asDiagnostics(diagnostics) { | ||
@@ -87,2 +88,6 @@ return diagnostics.map(asDiagnostic); | ||
exports.asTextEdit = asTextEdit; | ||
function asTextEdits(items) { | ||
return items.map(asTextEdit); | ||
} | ||
exports.asTextEdits = asTextEdits; | ||
function asSignatureHelp(item) { | ||
@@ -167,1 +172,31 @@ var result = new code.SignatureHelp(); | ||
exports.asSymbolInformation = asSymbolInformation; | ||
function asCommand(item) { | ||
var result = { title: item.title, command: item.command }; | ||
set(item.arguments, function () { return result.arguments = item.arguments; }); | ||
return result; | ||
} | ||
exports.asCommand = asCommand; | ||
function asCommands(items) { | ||
return items.map(asCommand); | ||
} | ||
exports.asCommands = asCommands; | ||
function asCodeLens(item) { | ||
var result = new protocolCodeLens_1.default(asRange(item.range)); | ||
if (is.defined(item.command)) | ||
result.command = asCommand(item.command); | ||
if (is.defined(item.data)) | ||
result.data = item.data; | ||
return result; | ||
} | ||
exports.asCodeLens = asCodeLens; | ||
function asCodeLenses(items) { | ||
return items.map(asCodeLens); | ||
} | ||
exports.asCodeLenses = asCodeLenses; | ||
function asWorkspaceEdit(item) { | ||
var result = new code.WorkspaceEdit(); | ||
var keys = Object.keys(item.changes); | ||
keys.forEach(function (key) { return result.set(code.Uri.parse(key), asTextEdits(item.changes[key])); }); | ||
return result; | ||
} | ||
exports.asWorkspaceEdit = asWorkspaceEdit; |
@@ -11,1 +11,3 @@ export declare function defined(value: any): boolean; | ||
export declare function stringArray(value: any): value is string[]; | ||
export declare function typedArray<T>(value: any, check: (value: any) => boolean): value is T[]; | ||
export declare function thenable<T>(value: any): value is Thenable<T>; |
@@ -47,1 +47,9 @@ /* -------------------------------------------------------------------------------------------- | ||
exports.stringArray = stringArray; | ||
function typedArray(value, check) { | ||
return Array.isArray(value) && value.every(check); | ||
} | ||
exports.typedArray = typedArray; | ||
function thenable(value) { | ||
return value && func(value.then); | ||
} | ||
exports.thenable = thenable; |
{ | ||
"name": "vscode-languageclient", | ||
"description": "VSCode Language client implementation", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"author": "Microsoft Corporation", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
159768
27
4027