diff --git a/Jakefile.js b/Jakefile.js
index f731cc5060c..933c58c7a39 100644
--- a/Jakefile.js
+++ b/Jakefile.js
@@ -101,7 +101,11 @@ var servicesSources = [
var serverCoreSources = [
"node.d.ts",
+ "utilities.ts",
"scriptVersionCache.ts",
+ "scriptInfo.ts",
+ "lsHost.ts",
+ "project.ts",
"editorServices.ts",
"protocol.d.ts",
"session.ts",
diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts
index 1c65db05b73..08014379345 100644
--- a/src/server/editorServices.ts
+++ b/src/server/editorServices.ts
@@ -1,749 +1,16 @@
///
///
///
+///
///
///
+///
+///
namespace ts.server {
- export interface Logger {
- close(): void;
- isVerbose(): boolean;
- loggingEnabled(): boolean;
- perftrc(s: string): void;
- info(s: string): void;
- startGroup(): void;
- endGroup(): void;
- msg(s: string, type?: string): void;
- }
-
- function getDefaultFormatCodeSettings(host: ServerHost): ts.FormatCodeSettings {
- return ts.clone({
- indentSize: 4,
- tabSize: 4,
- newLineCharacter: host.newLine || "\n",
- convertTabsToSpaces: true,
- indentStyle: ts.IndentStyle.Smart,
- insertSpaceAfterCommaDelimiter: true,
- insertSpaceAfterSemicolonInForStatements: true,
- insertSpaceBeforeAndAfterBinaryOperators: true,
- insertSpaceAfterKeywordsInControlFlowStatements: true,
- insertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
- insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
- insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
- insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
- placeOpenBraceOnNewLineForFunctions: false,
- placeOpenBraceOnNewLineForControlBlocks: false,
- });
- }
-
- function mergeMaps(target: Map, source: Map): void {
- for (const key in source) {
- if (hasProperty(source, key)) {
- target[key] = source[key];
- }
- }
- }
export const maxProgramSizeForNonTsFiles = 20 * 1024 * 1024;
- export class ScriptInfo {
- svc: ScriptVersionCache;
- defaultProject: Project; // project to use by default for file
- fileWatcher: FileWatcher;
- formatCodeSettings: ts.FormatCodeSettings;
- path: Path;
- scriptKind: ScriptKind;
-
- constructor(private host: ServerHost, public fileName: string, public content: string, public isOpen = false) {
- this.path = toPath(fileName, host.getCurrentDirectory(), createGetCanonicalFileName(host.useCaseSensitiveFileNames));
- this.svc = ScriptVersionCache.fromString(host, content);
- this.formatCodeSettings = getDefaultFormatCodeSettings(this.host);
- }
-
- setFormatOptions(formatSettings: protocol.FormatOptions): void {
- if (formatSettings) {
- mergeMaps(this.formatCodeSettings, formatSettings);
- }
- }
-
- close() {
- this.isOpen = false;
- }
-
- snap() {
- return this.svc.getSnapshot();
- }
-
- getLineInfo(line: number) {
- const snap = this.snap();
- return snap.index.lineNumberToInfo(line);
- }
-
- editContent(start: number, end: number, newText: string): void {
- this.svc.edit(start, end - start, newText);
- }
-
- /**
- * @param line 1 based index
- */
- lineToTextSpan(line: number) {
- const index = this.snap().index;
- const lineInfo = index.lineNumberToInfo(line + 1);
- let len: number;
- if (lineInfo.leaf) {
- len = lineInfo.leaf.text.length;
- }
- else {
- const nextLineInfo = index.lineNumberToInfo(line + 2);
- len = nextLineInfo.offset - lineInfo.offset;
- }
- return ts.createTextSpan(lineInfo.offset, len);
- }
-
- /**
- * @param line 1 based index
- * @param offset 1 based index
- */
- lineOffsetToPosition(line: number, offset: number): number {
- const index = this.snap().index;
-
- const lineInfo = index.lineNumberToInfo(line);
- // TODO: assert this offset is actually on the line
- return (lineInfo.offset + offset - 1);
- }
-
- /**
- * @param line 1-based index
- * @param offset 1-based index
- */
- positionToLineOffset(position: number): ILineInfo {
- const index = this.snap().index;
- const lineOffset = index.charOffsetToLineNumberAndPos(position);
- return { line: lineOffset.line, offset: lineOffset.offset + 1 };
- }
- }
-
-
- function throwLanguageServiceIsDisabledError() {;
- throw new Error("LanguageService is disabled");
- }
-
- const nullLanguageService: ts.LanguageService = {
- cleanupSemanticCache: (): any => throwLanguageServiceIsDisabledError(),
- getSyntacticDiagnostics: (): any => throwLanguageServiceIsDisabledError(),
- getSemanticDiagnostics: (): any => throwLanguageServiceIsDisabledError(),
- getCompilerOptionsDiagnostics: (): any => throwLanguageServiceIsDisabledError(),
- getSyntacticClassifications: (): any => throwLanguageServiceIsDisabledError(),
- getEncodedSyntacticClassifications: (): any => throwLanguageServiceIsDisabledError(),
- getSemanticClassifications: (): any => throwLanguageServiceIsDisabledError(),
- getEncodedSemanticClassifications: (): any => throwLanguageServiceIsDisabledError(),
- getCompletionsAtPosition: (): any => throwLanguageServiceIsDisabledError(),
- findReferences: (): any => throwLanguageServiceIsDisabledError(),
- getCompletionEntryDetails: (): any => throwLanguageServiceIsDisabledError(),
- getQuickInfoAtPosition: (): any => throwLanguageServiceIsDisabledError(),
- findRenameLocations: (): any => throwLanguageServiceIsDisabledError(),
- getNameOrDottedNameSpan: (): any => throwLanguageServiceIsDisabledError(),
- getBreakpointStatementAtPosition: (): any => throwLanguageServiceIsDisabledError(),
- getBraceMatchingAtPosition: (): any => throwLanguageServiceIsDisabledError(),
- getSignatureHelpItems: (): any => throwLanguageServiceIsDisabledError(),
- getDefinitionAtPosition: (): any => throwLanguageServiceIsDisabledError(),
- getRenameInfo: (): any => throwLanguageServiceIsDisabledError(),
- getTypeDefinitionAtPosition: (): any => throwLanguageServiceIsDisabledError(),
- getReferencesAtPosition: (): any => throwLanguageServiceIsDisabledError(),
- getDocumentHighlights: (): any => throwLanguageServiceIsDisabledError(),
- getOccurrencesAtPosition: (): any => throwLanguageServiceIsDisabledError(),
- getNavigateToItems: (): any => throwLanguageServiceIsDisabledError(),
- getNavigationBarItems: (): any => throwLanguageServiceIsDisabledError(),
- getOutliningSpans: (): any => throwLanguageServiceIsDisabledError(),
- getTodoComments: (): any => throwLanguageServiceIsDisabledError(),
- getIndentationAtPosition: (): any => throwLanguageServiceIsDisabledError(),
- getFormattingEditsForRange: (): any => throwLanguageServiceIsDisabledError(),
- getFormattingEditsForDocument: (): any => throwLanguageServiceIsDisabledError(),
- getFormattingEditsAfterKeystroke: (): any => throwLanguageServiceIsDisabledError(),
- getDocCommentTemplateAtPosition: (): any => throwLanguageServiceIsDisabledError(),
- isValidBraceCompletionAtPostion: (): any => throwLanguageServiceIsDisabledError(),
- getEmitOutput: (): any => throwLanguageServiceIsDisabledError(),
- getProgram: (): any => throwLanguageServiceIsDisabledError(),
- getNonBoundSourceFile: (): any => throwLanguageServiceIsDisabledError(),
- dispose: (): any => throwLanguageServiceIsDisabledError(),
- };
-
- interface ServerLanguageServiceHost {
- getCompilationSettings(): CompilerOptions;
- setCompilationSettings(options: CompilerOptions): void;
- removeRoot(info: ScriptInfo): void;
- removeReferencedFile(info: ScriptInfo): void;
- }
-
- const nullLanguageServiceHost: ServerLanguageServiceHost = {
- getCompilationSettings: () => undefined,
- setCompilationSettings: () => undefined,
- removeRoot: () => undefined,
- removeReferencedFile: () => undefined
- };
-
- export class LSHost implements ts.LanguageServiceHost, ModuleResolutionHost, ServerLanguageServiceHost {
- private compilationSettings: ts.CompilerOptions;
- private resolvedModuleNames: ts.FileMap