2014-07-19 01:55:11 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
2014-07-13 01:04:16 +02:00
|
|
|
|
2014-07-25 00:33:59 +02:00
|
|
|
/// <reference path='services.ts' />
|
|
|
|
|
2014-07-25 20:21:17 +02:00
|
|
|
var debugObjectHost = (<any>this);
|
|
|
|
|
2014-07-25 02:36:06 +02:00
|
|
|
module ts {
|
2014-07-25 01:03:48 +02:00
|
|
|
export interface ScriptSnapshotShim {
|
2014-09-25 00:27:17 +02:00
|
|
|
/** Gets a portion of the script snapshot specified by [start, end). */
|
2014-07-13 01:04:16 +02:00
|
|
|
getText(start: number, end: number): string;
|
|
|
|
|
2014-09-25 00:27:17 +02:00
|
|
|
/** Gets the length of this script snapshot. */
|
2014-07-13 01:04:16 +02:00
|
|
|
getLength(): number;
|
|
|
|
|
2014-09-25 00:27:17 +02:00
|
|
|
/** This call returns the JSON-encoded array of the type: number[] */
|
2014-07-13 01:04:16 +02:00
|
|
|
getLineStartPositions(): string;
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { span: { start: number; length: number }; newLength: number }
|
|
|
|
*
|
2014-09-25 00:27:17 +02:00
|
|
|
* Or undefined value if there was no change.
|
2014-09-24 21:55:27 +02:00
|
|
|
*/
|
2014-08-15 02:49:02 +02:00
|
|
|
getChangeRange(oldSnapshot: ScriptSnapshotShim): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/** Public interface of the host of a language service shim instance.*/
|
2014-07-25 01:01:51 +02:00
|
|
|
export interface LanguageServiceShimHost extends Logger {
|
2014-07-19 01:55:11 +02:00
|
|
|
getCompilationSettings(): string;
|
|
|
|
|
2014-09-25 00:27:17 +02:00
|
|
|
/** Returns a JSON-encoded value of the type: string[] */
|
2014-07-19 01:55:11 +02:00
|
|
|
getScriptFileNames(): string;
|
2014-08-15 02:49:02 +02:00
|
|
|
getScriptVersion(fileName: string): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
getScriptIsOpen(fileName: string): boolean;
|
2014-07-25 01:03:48 +02:00
|
|
|
getScriptSnapshot(fileName: string): ScriptSnapshotShim;
|
2014-07-19 01:55:11 +02:00
|
|
|
getLocalizedDiagnosticMessages(): string;
|
2014-07-25 21:18:12 +02:00
|
|
|
getCancellationToken(): CancellationToken;
|
2014-09-16 22:19:49 +02:00
|
|
|
getCurrentDirectory(): string;
|
2014-10-29 07:52:02 +01:00
|
|
|
getDefaultLibFilename(options: string): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-10-28 22:45:32 +01:00
|
|
|
///
|
|
|
|
/// Pre-processing
|
|
|
|
///
|
|
|
|
// Note: This is being using by the host (VS) and is marshaled back and forth.
|
|
|
|
// When changing this make sure the changes are reflected in the managed side as well
|
2014-10-29 21:58:27 +01:00
|
|
|
export interface IFileReference {
|
2014-10-28 22:45:32 +01:00
|
|
|
path: string;
|
|
|
|
position: number;
|
|
|
|
length: number;
|
|
|
|
}
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/** Public interface of a language service instance shim. */
|
2014-07-24 21:00:45 +02:00
|
|
|
export interface ShimFactory {
|
|
|
|
registerShim(shim: Shim): void;
|
|
|
|
unregisterShim(shim: Shim): void;
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
export interface Shim {
|
2014-07-19 01:55:11 +02:00
|
|
|
dispose(dummy: any): void;
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
export interface LanguageServiceShim extends Shim {
|
2014-07-24 20:57:18 +02:00
|
|
|
languageService: LanguageService;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
|
|
|
dispose(dummy: any): void;
|
|
|
|
|
|
|
|
refresh(throwOnError: boolean): void;
|
|
|
|
|
|
|
|
cleanupSemanticCache(): void;
|
|
|
|
|
|
|
|
getSyntacticDiagnostics(fileName: string): string;
|
|
|
|
getSemanticDiagnostics(fileName: string): string;
|
|
|
|
getCompilerOptionsDiagnostics(): string;
|
|
|
|
|
2014-09-13 02:19:48 +02:00
|
|
|
getSyntacticClassifications(fileName: string, start: number, length: number): string;
|
|
|
|
|
2014-12-08 22:00:46 +01:00
|
|
|
getCompletionsAtPosition(fileName: string, position: number): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
getCompletionEntryDetails(fileName: string, position: number, entryName: string): string;
|
|
|
|
|
2014-09-20 00:32:27 +02:00
|
|
|
getQuickInfoAtPosition(fileName: string, position: number): string;
|
2014-09-26 20:10:46 +02:00
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): string;
|
|
|
|
getBreakpointStatementAtPosition(fileName: string, position: number): string;
|
2014-08-15 01:51:16 +02:00
|
|
|
|
|
|
|
getSignatureHelpItems(fileName: string, position: number): string;
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { canRename: boolean, localizedErrorMessage: string, displayName: string, fullDisplayName: string, kind: string, kindModifiers: string, triggerSpan: { start; length } }
|
|
|
|
*/
|
2014-08-15 01:51:16 +02:00
|
|
|
getRenameInfo(fileName: string, position: number): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2014-10-03 23:53:50 +02:00
|
|
|
/**
|
|
|
|
* Returns a JSON-encoded value of the type:
|
|
|
|
* { fileName: string, textSpan: { start: number, length: number } }[]
|
|
|
|
*/
|
|
|
|
findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): string;
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { fileName: string; textSpan: { start: number; length: number}; kind: string; name: string; containerKind: string; containerName: string }
|
|
|
|
*
|
2014-09-25 00:27:17 +02:00
|
|
|
* Or undefined value if no definition can be found.
|
2014-09-24 21:55:27 +02:00
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
getDefinitionAtPosition(fileName: string, position: number): string;
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean }[]
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
getReferencesAtPosition(fileName: string, position: number): string;
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean }[]
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
getOccurrencesAtPosition(fileName: string, position: number): string;
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { name: string; kind: string; kindModifiers: string; containerName: string; containerKind: string; matchKind: string; fileName: string; textSpan: { start: number; length: number}; } [] = [];
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
getNavigateToItems(searchValue: string): string;
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { text: string; kind: string; kindModifiers: string; bolded: boolean; grayed: boolean; indent: number; spans: { start: number; length: number; }[]; childItems: <recursive use of this type>[] } [] = [];
|
|
|
|
*/
|
2014-08-15 01:51:16 +02:00
|
|
|
getNavigationBarItems(fileName: string): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { textSpan: { start: number, length: number }; hintSpan: { start: number, length: number }; bannerText: string; autoCollapse: boolean } [] = [];
|
|
|
|
*/
|
2014-08-15 01:51:16 +02:00
|
|
|
getOutliningSpans(fileName: string): string;
|
|
|
|
|
|
|
|
getTodoComments(fileName: string, todoCommentDescriptors: string): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
|
|
|
getBraceMatchingAtPosition(fileName: string, position: number): string;
|
|
|
|
getIndentationAtPosition(fileName: string, position: number, options: string/*Services.EditorOptions*/): string;
|
|
|
|
|
2014-08-15 01:51:16 +02:00
|
|
|
getFormattingEditsForRange(fileName: string, start: number, end: number, options: string/*Services.FormatCodeOptions*/): string;
|
|
|
|
getFormattingEditsForDocument(fileName: string, options: string/*Services.FormatCodeOptions*/): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: string/*Services.FormatCodeOptions*/): string;
|
|
|
|
|
|
|
|
getEmitOutput(fileName: string): string;
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
export interface ClassifierShim extends Shim {
|
2014-11-05 02:30:37 +01:00
|
|
|
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): string;
|
2014-07-24 20:57:18 +02:00
|
|
|
}
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
export interface CoreServicesShim extends Shim {
|
2014-11-18 02:01:23 +01:00
|
|
|
getPreProcessedFileInfo(fileName: string, sourceText: IScriptSnapshot): string;
|
2014-07-24 20:57:18 +02:00
|
|
|
getDefaultCompilationSettings(): string;
|
|
|
|
}
|
|
|
|
|
2014-07-25 01:01:51 +02:00
|
|
|
function logInternalError(logger: Logger, err: Error) {
|
2014-07-25 00:58:33 +02:00
|
|
|
logger.log("*INTERNAL ERROR* - Exception in typescript services: " + err.message);
|
|
|
|
}
|
|
|
|
|
2014-11-18 02:01:23 +01:00
|
|
|
class ScriptSnapshotShimAdapter implements IScriptSnapshot {
|
2014-07-13 01:04:16 +02:00
|
|
|
private lineStartPositions: number[] = null;
|
|
|
|
|
2014-07-25 01:03:48 +02:00
|
|
|
constructor(private scriptSnapshotShim: ScriptSnapshotShim) {
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getText(start: number, end: number): string {
|
|
|
|
return this.scriptSnapshotShim.getText(start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
public getLength(): number {
|
|
|
|
return this.scriptSnapshotShim.getLength();
|
|
|
|
}
|
|
|
|
|
2014-07-24 20:42:55 +02:00
|
|
|
public getLineStartPositions(): number[] {
|
2014-07-13 01:04:16 +02:00
|
|
|
if (this.lineStartPositions == null) {
|
|
|
|
this.lineStartPositions = JSON.parse(this.scriptSnapshotShim.getLineStartPositions());
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.lineStartPositions;
|
|
|
|
}
|
|
|
|
|
2014-11-18 02:01:23 +01:00
|
|
|
public getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange {
|
2014-08-15 02:49:02 +02:00
|
|
|
var oldSnapshotShim = <ScriptSnapshotShimAdapter>oldSnapshot;
|
|
|
|
var encoded = this.scriptSnapshotShim.getChangeRange(oldSnapshotShim.scriptSnapshotShim);
|
2014-07-13 01:04:16 +02:00
|
|
|
if (encoded == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var decoded: { span: { start: number; length: number; }; newLength: number; } = JSON.parse(encoded);
|
2014-11-18 02:01:23 +01:00
|
|
|
return new TextChangeRange(
|
|
|
|
new TextSpan(decoded.span.start, decoded.span.length), decoded.newLength);
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 02:49:02 +02:00
|
|
|
export class LanguageServiceShimHostAdapter implements LanguageServiceHost {
|
2014-07-24 21:00:45 +02:00
|
|
|
constructor(private shimHost: LanguageServiceShimHost) {
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-07-13 01:04:16 +02:00
|
|
|
public log(s: string): void {
|
|
|
|
this.shimHost.log(s);
|
|
|
|
}
|
|
|
|
|
2014-12-07 06:23:54 +01:00
|
|
|
public trace(s: string): void {
|
|
|
|
this.shimHost.trace(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
public error(s: string): void {
|
|
|
|
this.shimHost.error(s);
|
|
|
|
}
|
|
|
|
|
2014-07-25 21:18:12 +02:00
|
|
|
public getCompilationSettings(): CompilerOptions {
|
2014-07-13 01:04:16 +02:00
|
|
|
var settingsJson = this.shimHost.getCompilationSettings();
|
|
|
|
if (settingsJson == null || settingsJson == "") {
|
2014-07-19 01:55:11 +02:00
|
|
|
throw Error("LanguageServiceShimHostAdapter.getCompilationSettings: empty compilationSettings");
|
|
|
|
return null;
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
2014-12-10 18:03:12 +01:00
|
|
|
return <CompilerOptions>JSON.parse(<any>settingsJson);
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getScriptFileNames(): string[] {
|
|
|
|
var encoded = this.shimHost.getScriptFileNames();
|
|
|
|
return JSON.parse(encoded);
|
|
|
|
}
|
|
|
|
|
2014-11-18 02:01:23 +01:00
|
|
|
public getScriptSnapshot(fileName: string): IScriptSnapshot {
|
2014-07-13 01:04:16 +02:00
|
|
|
return new ScriptSnapshotShimAdapter(this.shimHost.getScriptSnapshot(fileName));
|
|
|
|
}
|
|
|
|
|
2014-08-15 02:49:02 +02:00
|
|
|
public getScriptVersion(fileName: string): string {
|
2014-07-13 01:04:16 +02:00
|
|
|
return this.shimHost.getScriptVersion(fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
public getScriptIsOpen(fileName: string): boolean {
|
|
|
|
return this.shimHost.getScriptIsOpen(fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
public getLocalizedDiagnosticMessages(): any {
|
|
|
|
var diagnosticMessagesJson = this.shimHost.getLocalizedDiagnosticMessages();
|
|
|
|
if (diagnosticMessagesJson == null || diagnosticMessagesJson == "") {
|
|
|
|
return null;
|
|
|
|
}
|
2014-10-03 02:58:05 +02:00
|
|
|
|
2014-07-13 01:04:16 +02:00
|
|
|
try {
|
|
|
|
return JSON.parse(diagnosticMessagesJson);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
this.log(e.description || "diagnosticMessages.generated.json has invalid JSON format");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-25 21:18:12 +02:00
|
|
|
public getCancellationToken(): CancellationToken {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.shimHost.getCancellationToken();
|
|
|
|
}
|
2014-09-16 22:19:49 +02:00
|
|
|
|
2014-10-29 07:52:02 +01:00
|
|
|
public getDefaultLibFilename(options: CompilerOptions): string {
|
|
|
|
return this.shimHost.getDefaultLibFilename(JSON.stringify(options));
|
2014-09-16 22:19:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getCurrentDirectory(): string {
|
|
|
|
return this.shimHost.getCurrentDirectory();
|
|
|
|
}
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-07-25 01:01:51 +02:00
|
|
|
function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any): any {
|
2014-07-19 01:55:11 +02:00
|
|
|
logger.log(actionDescription);
|
|
|
|
var start = Date.now();
|
|
|
|
var result = action();
|
|
|
|
var end = Date.now();
|
|
|
|
logger.log(actionDescription + " completed in " + (end - start) + " msec");
|
|
|
|
if (typeof (result) === "string") {
|
|
|
|
var str = <string>result;
|
|
|
|
if (str.length > 128) {
|
|
|
|
str = str.substring(0, 128) + "...";
|
|
|
|
}
|
|
|
|
logger.log(" result.length=" + str.length + ", result='" + JSON.stringify(str) + "'");
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-07-25 01:01:51 +02:00
|
|
|
function forwardJSONCall(logger: Logger, actionDescription: string, action: () => any): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
try {
|
|
|
|
var result = simpleForwardCall(logger, actionDescription, action);
|
|
|
|
return JSON.stringify({ result: result });
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
if (err instanceof OperationCanceledException) {
|
|
|
|
return JSON.stringify({ canceled: true });
|
|
|
|
}
|
2014-07-24 20:57:18 +02:00
|
|
|
logInternalError(logger, err);
|
2014-07-19 01:55:11 +02:00
|
|
|
err.description = actionDescription;
|
|
|
|
return JSON.stringify({ error: err });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
class ShimBase implements Shim {
|
|
|
|
constructor(private factory: ShimFactory) {
|
2014-07-24 20:57:18 +02:00
|
|
|
factory.registerShim(this);
|
|
|
|
}
|
|
|
|
public dispose(dummy: any): void {
|
|
|
|
this.factory.unregisterShim(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
class LanguageServiceShimObject extends ShimBase implements LanguageServiceShim {
|
2014-07-25 01:01:51 +02:00
|
|
|
private logger: Logger;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
constructor(factory: ShimFactory,
|
|
|
|
private host: LanguageServiceShimHost,
|
2014-07-24 20:57:18 +02:00
|
|
|
public languageService: LanguageService) {
|
2014-07-19 01:55:11 +02:00
|
|
|
super(factory);
|
|
|
|
this.logger = this.host;
|
|
|
|
}
|
|
|
|
|
2014-07-24 20:42:55 +02:00
|
|
|
public forwardJSONCall(actionDescription: string, action: () => any): string {
|
2014-07-24 20:57:18 +02:00
|
|
|
return forwardJSONCall(this.logger, actionDescription, action);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/// DISPOSE
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure (almost) deterministic release of internal Javascript resources when
|
|
|
|
* some external native objects holds onto us (e.g. Com/Interop).
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
public dispose(dummy: any): void {
|
|
|
|
this.logger.log("dispose()");
|
|
|
|
this.languageService.dispose();
|
|
|
|
this.languageService = null;
|
|
|
|
|
|
|
|
// force a GC
|
|
|
|
if (debugObjectHost && debugObjectHost.CollectGarbage) {
|
|
|
|
debugObjectHost.CollectGarbage();
|
|
|
|
this.logger.log("CollectGarbage()");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.logger = null;
|
|
|
|
|
|
|
|
super.dispose(dummy);
|
|
|
|
}
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/// REFRESH
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the list of scripts known to the compiler
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
public refresh(throwOnError: boolean): void {
|
|
|
|
this.forwardJSONCall(
|
|
|
|
"refresh(" + throwOnError + ")",
|
|
|
|
() => {
|
|
|
|
return <any>null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public cleanupSemanticCache(): void {
|
|
|
|
this.forwardJSONCall(
|
|
|
|
"cleanupSemanticCache()",
|
|
|
|
() => {
|
|
|
|
this.languageService.cleanupSemanticCache();
|
|
|
|
return <any>null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-07-25 21:18:12 +02:00
|
|
|
private static realizeDiagnostic(diagnostic: Diagnostic): { message: string; start: number; length: number; category: string; } {
|
2014-07-19 01:55:11 +02:00
|
|
|
return {
|
|
|
|
message: diagnostic.messageText,
|
|
|
|
start: diagnostic.start,
|
|
|
|
length: diagnostic.length,
|
|
|
|
/// TODO: no need for the tolowerCase call
|
2014-10-07 22:31:21 +02:00
|
|
|
category: DiagnosticCategory[diagnostic.category].toLowerCase(),
|
|
|
|
code: diagnostic.code
|
2014-07-19 01:55:11 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-09-13 02:19:48 +02:00
|
|
|
public getSyntacticClassifications(fileName: string, start: number, length: number): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
"getSyntacticClassifications('" + fileName + "', " + start + ", " + length + ")",
|
|
|
|
() => {
|
2014-11-18 02:01:23 +01:00
|
|
|
var classifications = this.languageService.getSyntacticClassifications(fileName, new TextSpan(start, length));
|
2014-09-13 02:19:48 +02:00
|
|
|
return classifications;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-09-13 03:28:54 +02:00
|
|
|
public getSemanticClassifications(fileName: string, start: number, length: number): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
"getSemanticClassifications('" + fileName + "', " + start + ", " + length + ")",
|
|
|
|
() => {
|
2014-11-18 02:01:23 +01:00
|
|
|
var classifications = this.languageService.getSemanticClassifications(fileName, new TextSpan(start, length));
|
2014-09-13 03:28:54 +02:00
|
|
|
return classifications;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
public getSyntacticDiagnostics(fileName: string): string {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getSyntacticDiagnostics('" + fileName + "')",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
|
|
|
var errors = this.languageService.getSyntacticDiagnostics(fileName);
|
2014-07-24 21:00:45 +02:00
|
|
|
return errors.map(LanguageServiceShimObject.realizeDiagnostic);
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public getSemanticDiagnostics(fileName: string): string {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getSemanticDiagnostics('" + fileName + "')",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
|
|
|
var errors = this.languageService.getSemanticDiagnostics(fileName);
|
2014-07-24 21:00:45 +02:00
|
|
|
return errors.map(LanguageServiceShimObject.realizeDiagnostic);
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public getCompilerOptionsDiagnostics(): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
"getCompilerOptionsDiagnostics()",
|
|
|
|
() => {
|
|
|
|
var errors = this.languageService.getCompilerOptionsDiagnostics();
|
2014-11-07 04:00:44 +01:00
|
|
|
return errors.map(LanguageServiceShimObject.realizeDiagnostic)
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// QUICKINFO
|
2014-09-24 21:55:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes a string representation of the type at the requested position
|
|
|
|
* in the active file.
|
|
|
|
*/
|
2014-09-20 00:32:27 +02:00
|
|
|
public getQuickInfoAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
"getQuickInfoAtPosition('" + fileName + "', " + position + ")",
|
|
|
|
() => {
|
|
|
|
var quickInfo = this.languageService.getQuickInfoAtPosition(fileName, position);
|
|
|
|
return quickInfo;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
/// NAMEORDOTTEDNAMESPAN
|
2014-09-24 21:55:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes span information of the name or dotted name at the requested position
|
|
|
|
* in the active file.
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
public getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getNameOrDottedNameSpan('" + fileName + "', " + startPos + ", " + endPos + ")",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
|
|
|
var spanInfo = this.languageService.getNameOrDottedNameSpan(fileName, startPos, endPos);
|
|
|
|
return spanInfo;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
|
|
|
* STATEMENTSPAN
|
|
|
|
* Computes span information of statement at the requested position in the active file.
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
public getBreakpointStatementAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getBreakpointStatementAtPosition('" + fileName + "', " + position + ")",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
|
|
|
var spanInfo = this.languageService.getBreakpointStatementAtPosition(fileName, position);
|
|
|
|
return spanInfo;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// SIGNATUREHELP
|
2014-08-15 01:51:16 +02:00
|
|
|
|
|
|
|
public getSignatureHelpItems(fileName: string, position: number): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getSignatureHelpItems('" + fileName + "', " + position + ")",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2014-08-15 01:51:16 +02:00
|
|
|
var signatureInfo = this.languageService.getSignatureHelpItems(fileName, position);
|
2014-07-19 01:55:11 +02:00
|
|
|
return signatureInfo;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GOTO DEFINITION
|
2014-09-24 21:55:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the definition location and file for the symbol
|
|
|
|
* at the requested position.
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
public getDefinitionAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getDefinitionAtPosition('" + fileName + "', " + position + ")",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
|
|
|
return this.languageService.getDefinitionAtPosition(fileName, position);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-08-15 01:51:16 +02:00
|
|
|
public getRenameInfo(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
"getRenameInfo('" + fileName + "', " + position + ")",
|
|
|
|
() => {
|
|
|
|
return this.languageService.getRenameInfo(fileName, position);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-10-03 23:53:50 +02:00
|
|
|
public findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
"findRenameLocations('" + fileName + "', " + position + ", " + findInStrings + ", " + findInComments + ")",
|
|
|
|
() => {
|
|
|
|
return this.languageService.findRenameLocations(fileName, position, findInStrings, findInComments);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
/// GET BRACE MATCHING
|
|
|
|
public getBraceMatchingAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getBraceMatchingAtPosition('" + fileName + "', " + position + ")",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
|
|
|
var textRanges = this.languageService.getBraceMatchingAtPosition(fileName, position);
|
|
|
|
return textRanges;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GET SMART INDENT
|
|
|
|
public getIndentationAtPosition(fileName: string, position: number, options: string /*Services.EditorOptions*/): string {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getIndentationAtPosition('" + fileName + "', " + position + ")",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2014-07-24 20:57:18 +02:00
|
|
|
var localOptions: EditorOptions = JSON.parse(options);
|
2014-08-16 00:06:23 +02:00
|
|
|
return this.languageService.getIndentationAtPosition(fileName, position, localOptions);
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GET REFERENCES
|
2014-09-24 21:55:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return references to a symbol at the requested position.
|
|
|
|
* References are separated by "\n".
|
|
|
|
* Each reference is a "fileindex min lim" sub-string.
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
public getReferencesAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getReferencesAtPosition('" + fileName + "', " + position + ")",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
|
|
|
return this.languageService.getReferencesAtPosition(fileName, position);
|
|
|
|
});
|
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
public getOccurrencesAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getOccurrencesAtPosition('" + fileName + "', " + position + ")",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
|
|
|
return this.languageService.getOccurrencesAtPosition(fileName, position);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// COMPLETION LISTS
|
2014-09-24 21:55:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a string based representation of the completions
|
|
|
|
* to provide at the given source position and providing a member completion
|
|
|
|
* list if requested.
|
|
|
|
*/
|
2014-12-08 22:00:46 +01:00
|
|
|
public getCompletionsAtPosition(fileName: string, position: number) {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2014-12-08 22:00:46 +01:00
|
|
|
"getCompletionsAtPosition('" + fileName + "', " + position + ")",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2014-12-08 22:00:46 +01:00
|
|
|
var completion = this.languageService.getCompletionsAtPosition(fileName, position);
|
2014-07-19 01:55:11 +02:00
|
|
|
return completion;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/** Get a string based representation of a completion list entry details */
|
2014-07-19 01:55:11 +02:00
|
|
|
public getCompletionEntryDetails(fileName: string, position: number, entryName: string) {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getCompletionEntryDetails('" + fileName + "', " + position + ", " + entryName + ")",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
|
|
|
var details = this.languageService.getCompletionEntryDetails(fileName, position, entryName);
|
|
|
|
return details;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-08-15 01:51:16 +02:00
|
|
|
public getFormattingEditsForRange(fileName: string, start: number, end: number, options: string/*Services.FormatCodeOptions*/): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getFormattingEditsForRange('" + fileName + "', " + start + ", " + end + ")",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2014-08-15 01:51:16 +02:00
|
|
|
var localOptions: ts.FormatCodeOptions = JSON.parse(options);
|
|
|
|
var edits = this.languageService.getFormattingEditsForRange(fileName, start, end, localOptions);
|
2014-07-19 01:55:11 +02:00
|
|
|
return edits;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-08-15 01:51:16 +02:00
|
|
|
public getFormattingEditsForDocument(fileName: string, options: string/*Services.FormatCodeOptions*/): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getFormattingEditsForDocument('" + fileName + "')",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2014-08-15 01:51:16 +02:00
|
|
|
var localOptions: ts.FormatCodeOptions = JSON.parse(options);
|
|
|
|
var edits = this.languageService.getFormattingEditsForDocument(fileName, localOptions);
|
2014-07-19 01:55:11 +02:00
|
|
|
return edits;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: string/*Services.FormatCodeOptions*/): string {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getFormattingEditsAfterKeystroke('" + fileName + "', " + position + ", '" + key + "')",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2014-08-15 01:51:16 +02:00
|
|
|
var localOptions: ts.FormatCodeOptions = JSON.parse(options);
|
2014-07-19 01:55:11 +02:00
|
|
|
var edits = this.languageService.getFormattingEditsAfterKeystroke(fileName, position, key, localOptions);
|
|
|
|
return edits;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// NAVIGATE TO
|
2014-09-24 21:55:27 +02:00
|
|
|
|
|
|
|
/** Return a list of symbols that are interesting to navigate to */
|
2014-07-19 01:55:11 +02:00
|
|
|
public getNavigateToItems(searchValue: string): string {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getNavigateToItems('" + searchValue + "')",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
|
|
|
var items = this.languageService.getNavigateToItems(searchValue);
|
2014-08-15 01:51:16 +02:00
|
|
|
return items;
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-08-15 01:51:16 +02:00
|
|
|
public getNavigationBarItems(fileName: string): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getNavigationBarItems('" + fileName + "')",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2014-08-15 01:51:16 +02:00
|
|
|
var items = this.languageService.getNavigationBarItems(fileName);
|
|
|
|
return items;
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-08-15 01:51:16 +02:00
|
|
|
public getOutliningSpans(fileName: string): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getOutliningSpans('" + fileName + "')",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2014-08-15 01:51:16 +02:00
|
|
|
var items = this.languageService.getOutliningSpans(fileName);
|
|
|
|
return items;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public getTodoComments(fileName: string, descriptors: string): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
"getTodoComments('" + fileName + "')",
|
|
|
|
() => {
|
|
|
|
var items = this.languageService.getTodoComments(fileName, JSON.parse(descriptors));
|
|
|
|
return items;
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Emit
|
|
|
|
public getEmitOutput(fileName: string): string {
|
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getEmitOutput('" + fileName + "')",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
|
|
|
var output = this.languageService.getEmitOutput(fileName);
|
|
|
|
return output;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
class ClassifierShimObject extends ShimBase implements ClassifierShim {
|
2014-07-24 20:57:18 +02:00
|
|
|
public classifier: Classifier;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2014-08-17 04:03:07 +02:00
|
|
|
constructor(factory: ShimFactory, public logger: Logger) {
|
2014-07-19 01:55:11 +02:00
|
|
|
super(factory);
|
2014-08-17 04:03:07 +02:00
|
|
|
this.classifier = createClassifier(this.logger);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// COLORIZATION
|
2014-11-05 02:30:37 +01:00
|
|
|
public getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): string {
|
|
|
|
var classification = this.classifier.getClassificationsForLine(text, lexState, classifyKeywordsInGenerics);
|
2014-07-19 01:55:11 +02:00
|
|
|
var items = classification.entries;
|
|
|
|
var result = "";
|
|
|
|
for (var i = 0; i < items.length; i++) {
|
|
|
|
result += items[i].length + "\n";
|
|
|
|
result += items[i].classification + "\n";
|
|
|
|
}
|
|
|
|
result += classification.finalLexState;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
class CoreServicesShimObject extends ShimBase implements CoreServicesShim {
|
2014-08-17 04:03:07 +02:00
|
|
|
constructor(factory: ShimFactory, public logger: Logger) {
|
2014-07-19 01:55:11 +02:00
|
|
|
super(factory);
|
|
|
|
}
|
|
|
|
|
2014-07-24 20:42:55 +02:00
|
|
|
private forwardJSONCall(actionDescription: string, action: () => any): any {
|
2014-08-17 04:03:07 +02:00
|
|
|
return forwardJSONCall(this.logger, actionDescription, action);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 02:01:23 +01:00
|
|
|
public getPreProcessedFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2014-08-15 01:51:16 +02:00
|
|
|
"getPreProcessedFileInfo('" + fileName + "')",
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2014-10-25 01:03:40 +02:00
|
|
|
var result = preProcessFile(sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()));
|
2014-10-28 22:45:32 +01:00
|
|
|
var convertResult = {
|
|
|
|
referencedFiles: <IFileReference[]>[],
|
|
|
|
importedFiles: <IFileReference[]>[],
|
|
|
|
isLibFile: result.isLibFile
|
|
|
|
};
|
|
|
|
|
|
|
|
forEach(result.referencedFiles, refFile => {
|
|
|
|
convertResult.referencedFiles.push({
|
2014-11-11 01:09:00 +01:00
|
|
|
path: normalizePath(refFile.filename),
|
2014-10-28 22:45:32 +01:00
|
|
|
position: refFile.pos,
|
|
|
|
length: refFile.end - refFile.pos
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
forEach(result.importedFiles, importedFile => {
|
|
|
|
convertResult.importedFiles.push({
|
2014-11-11 01:09:00 +01:00
|
|
|
path: normalizeSlashes(importedFile.filename),
|
2014-10-28 22:45:32 +01:00
|
|
|
position: importedFile.pos,
|
|
|
|
length: importedFile.end - importedFile.pos
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return convertResult;
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public getDefaultCompilationSettings(): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
"getDefaultCompilationSettings()",
|
|
|
|
() => {
|
2014-12-10 18:03:12 +01:00
|
|
|
return getDefaultCompilerOptions();
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
2014-07-24 20:42:55 +02:00
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
export class TypeScriptServicesFactory implements ShimFactory {
|
|
|
|
private _shims: Shim[] = [];
|
2014-07-25 20:21:17 +02:00
|
|
|
private documentRegistry: DocumentRegistry = createDocumentRegistry();
|
2014-07-24 20:42:55 +02:00
|
|
|
|
2014-12-07 08:04:17 +01:00
|
|
|
/*
|
|
|
|
* Returns script API version.
|
|
|
|
*/
|
2014-12-08 06:41:15 +01:00
|
|
|
public getServicesVersion(): string {
|
|
|
|
return servicesVersion;
|
2014-12-07 08:04:17 +01:00
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
public createLanguageServiceShim(host: LanguageServiceShimHost): LanguageServiceShim {
|
2014-07-24 20:42:55 +02:00
|
|
|
try {
|
|
|
|
var hostAdapter = new LanguageServiceShimHostAdapter(host);
|
2014-08-08 08:32:43 +02:00
|
|
|
var languageService = createLanguageService(hostAdapter, this.documentRegistry);
|
|
|
|
return new LanguageServiceShimObject(this, host, languageService);
|
2014-07-24 20:42:55 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
2014-07-24 20:57:18 +02:00
|
|
|
logInternalError(host, err);
|
2014-07-24 20:42:55 +02:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-17 04:03:07 +02:00
|
|
|
public createClassifierShim(logger: Logger): ClassifierShim {
|
2014-07-24 20:42:55 +02:00
|
|
|
try {
|
2014-08-17 04:20:40 +02:00
|
|
|
return new ClassifierShimObject(this, logger);
|
2014-07-24 20:42:55 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
2014-08-17 04:03:07 +02:00
|
|
|
logInternalError(logger, err);
|
2014-07-24 20:42:55 +02:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-17 04:03:07 +02:00
|
|
|
public createCoreServicesShim(logger: Logger): CoreServicesShim {
|
2014-07-24 20:42:55 +02:00
|
|
|
try {
|
2014-08-17 04:20:40 +02:00
|
|
|
return new CoreServicesShimObject(this, logger);
|
2014-07-24 20:42:55 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
2014-08-17 04:03:07 +02:00
|
|
|
logInternalError(logger, err);
|
2014-07-24 20:42:55 +02:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public close(): void {
|
|
|
|
// Forget all the registered shims
|
|
|
|
this._shims = [];
|
2014-07-25 20:21:17 +02:00
|
|
|
this.documentRegistry = createDocumentRegistry();
|
2014-07-24 20:42:55 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
public registerShim(shim: Shim): void {
|
2014-07-24 20:42:55 +02:00
|
|
|
this._shims.push(shim);
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
public unregisterShim(shim: Shim): void {
|
2014-07-24 20:42:55 +02:00
|
|
|
for (var i = 0, n = this._shims.length; i < n; i++) {
|
|
|
|
if (this._shims[i] === shim) {
|
|
|
|
delete this._shims[i];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 02:01:23 +01:00
|
|
|
throw new Error("Invalid operation");
|
2014-07-24 20:42:55 +02:00
|
|
|
}
|
|
|
|
}
|
2014-12-02 00:52:34 +01:00
|
|
|
|
2014-12-03 00:16:09 +01:00
|
|
|
// Here we expose the TypeScript services as an external module
|
|
|
|
// so that it may be consumed easily like a node module.
|
2014-12-02 00:52:34 +01:00
|
|
|
declare var module: any;
|
|
|
|
if (typeof module !== "undefined" && module.exports) {
|
|
|
|
module.exports = ts;
|
|
|
|
}
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
2014-07-24 20:42:55 +02:00
|
|
|
|
|
|
|
|
2014-09-10 02:41:34 +02:00
|
|
|
/// TODO: this is used by VS, clean this up on both sides of the interface
|
2014-07-25 02:36:06 +02:00
|
|
|
module TypeScript.Services {
|
|
|
|
export var TypeScriptServicesFactory = ts.TypeScriptServicesFactory;
|
2014-07-24 20:42:55 +02:00
|
|
|
}
|