From 8b44ce2fd7bc70a89721db3dd5db3b1ec0e6ea0d Mon Sep 17 00:00:00 2001 From: Joel Day Date: Sat, 31 Dec 2016 17:37:51 -0800 Subject: [PATCH 1/3] Emitting tsserverlibrary as an external module. --- Gulpfile.ts | 3 ++ Jakefile.js | 38 +++++++++---------- src/server/shared.ts | 2 +- src/server/tsconfig.library.json | 14 ++++--- src/server/{types.d.ts => types.ts} | 0 src/server/typingsInstaller/tsconfig.json | 2 +- .../typingsInstaller/typingsInstaller.ts | 2 +- src/server/utilities.ts | 2 +- 8 files changed, 35 insertions(+), 28 deletions(-) rename src/server/{types.d.ts => types.ts} (100%) diff --git a/Gulpfile.ts b/Gulpfile.ts index 054e99c8003..2eec5c22045 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -472,6 +472,9 @@ gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => { .pipe(sourcemaps.write(".")) .pipe(gulp.dest(".")), dts.pipe(prependCopyright()) + .pipe(insert.transform((content) => { + return content + "\r\nexport = ts;"; + })) .pipe(gulp.dest(".")) ]); }); diff --git a/Jakefile.js b/Jakefile.js index 3c26003fdf0..801ac924027 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -183,8 +183,8 @@ var servicesSources = [ return path.join(servicesDirectory, f); })); -var serverCoreSources = [ - "types.d.ts", +var baseServerCoreSources = [ + "types.ts", "shared.ts", "utilities.ts", "scriptVersionCache.ts", @@ -195,11 +195,16 @@ var serverCoreSources = [ "editorServices.ts", "protocol.ts", "session.ts", - "server.ts" ].map(function (f) { return path.join(serverDirectory, f); }); +var serverCoreSources = [ + "server.ts" +].map(function (f) { + return path.join(serverDirectory, f); +}).concat(baseServerCoreSources); + var cancellationTokenSources = [ "cancellationToken.ts" ].map(function (f) { @@ -207,7 +212,7 @@ var cancellationTokenSources = [ }); var typingsInstallerSources = [ - "../types.d.ts", + "../types.ts", "../shared.ts", "typingsInstaller.ts", "nodeTypingsInstaller.ts" @@ -216,20 +221,7 @@ var typingsInstallerSources = [ }); var serverSources = serverCoreSources.concat(servicesSources); - -var languageServiceLibrarySources = [ - "protocol.ts", - "utilities.ts", - "scriptVersionCache.ts", - "scriptInfo.ts", - "lsHost.ts", - "project.ts", - "editorServices.ts", - "session.ts", - -].map(function (f) { - return path.join(serverDirectory, f); -}).concat(servicesSources); +var languageServiceLibrarySources = baseServerCoreSources.concat(servicesSources); var harnessCoreSources = [ "harness.ts", @@ -727,7 +719,15 @@ compileFile( [builtLocalDirectory, copyright, builtLocalCompiler].concat(languageServiceLibrarySources).concat(libraryTargets), /*prefixes*/[copyright], /*useBuiltCompiler*/ true, - { noOutFile: false, generateDeclarations: true }); + { noOutFile: false, generateDeclarations: true }, + /*callback*/ function () { + + prependFile(copyright, tsserverLibraryDefinitionFile); + + // Appending 'export = ts;' at the end of the server library file to turn it into an external module + var tsserverLibraryDefinitionFileContents = fs.readFileSync(tsserverLibraryDefinitionFile).toString() + "\r\nexport = ts;"; + fs.writeFileSync(tsserverLibraryDefinitionFile, tsserverLibraryDefinitionFileContents); + }); // Local target to build the language service server library desc("Builds language service server library"); diff --git a/src/server/shared.ts b/src/server/shared.ts index c56d4098e75..77f66fc5a2d 100644 --- a/src/server/shared.ts +++ b/src/server/shared.ts @@ -1,4 +1,4 @@ -/// +/// namespace ts.server { export const ActionSet: ActionSet = "action::set"; diff --git a/src/server/tsconfig.library.json b/src/server/tsconfig.library.json index 5483cc8ec28..c589d875c3a 100644 --- a/src/server/tsconfig.library.json +++ b/src/server/tsconfig.library.json @@ -1,16 +1,20 @@ { "compilerOptions": { "noImplicitAny": true, + "noImplicitThis": true, "removeComments": true, "preserveConstEnums": true, + "pretty": true, "outFile": "../../built/local/tsserverlibrary.js", "sourceMap": true, "stripInternal": true, - "declaration": true, - "types": [], + "types": [ + "node" + ], "target": "es5", "noUnusedLocals": true, - "noUnusedParameters": true + "noUnusedParameters": true, + "declaration": true }, "files": [ "../services/shims.ts", @@ -19,11 +23,11 @@ "utilities.ts", "scriptVersionCache.ts", "scriptInfo.ts", - "lshost.ts", + "lsHost.ts", "typingsCache.ts", "project.ts", "editorServices.ts", - "protocol.d.ts", + "protocol.ts", "session.ts" ] } diff --git a/src/server/types.d.ts b/src/server/types.ts similarity index 100% rename from src/server/types.d.ts rename to src/server/types.ts diff --git a/src/server/typingsInstaller/tsconfig.json b/src/server/typingsInstaller/tsconfig.json index c6031b19aae..27f5cedc9d1 100644 --- a/src/server/typingsInstaller/tsconfig.json +++ b/src/server/typingsInstaller/tsconfig.json @@ -16,7 +16,7 @@ "noUnusedParameters": true }, "files": [ - "../types.d.ts", + "../types.ts", "../shared.ts", "typingsInstaller.ts", "nodeTypingsInstaller.ts" diff --git a/src/server/typingsInstaller/typingsInstaller.ts b/src/server/typingsInstaller/typingsInstaller.ts index 7a09c1f6c21..f706943a0f5 100644 --- a/src/server/typingsInstaller/typingsInstaller.ts +++ b/src/server/typingsInstaller/typingsInstaller.ts @@ -1,7 +1,7 @@ /// /// /// -/// +/// /// namespace ts.server.typingsInstaller { diff --git a/src/server/utilities.ts b/src/server/utilities.ts index d0790b93dba..1889b055d29 100644 --- a/src/server/utilities.ts +++ b/src/server/utilities.ts @@ -1,4 +1,4 @@ -/// +/// /// namespace ts.server { From cf5508732a520cd8ef26a071c9aab51e58a49087 Mon Sep 17 00:00:00 2001 From: Joel Day Date: Sun, 1 Jan 2017 17:58:33 -0800 Subject: [PATCH 2/3] Fix Gulp build of tsserverlibrary to match Jake. --- Gulpfile.ts | 2 +- Jakefile.js | 14 +++++++------- src/server/tsconfig.library.json | 26 +++++++++++++------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Gulpfile.ts b/Gulpfile.ts index 2eec5c22045..22bf020a435 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -471,7 +471,7 @@ gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => { js.pipe(prependCopyright()) .pipe(sourcemaps.write(".")) .pipe(gulp.dest(".")), - dts.pipe(prependCopyright()) + dts.pipe(prependCopyright(/*outputCopyright*/true)) .pipe(insert.transform((content) => { return content + "\r\nexport = ts;"; })) diff --git a/Jakefile.js b/Jakefile.js index 801ac924027..b810477d861 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -184,17 +184,17 @@ var servicesSources = [ })); var baseServerCoreSources = [ - "types.ts", - "shared.ts", - "utilities.ts", - "scriptVersionCache.ts", - "typingsCache.ts", - "scriptInfo.ts", + "editorServices.ts", "lsHost.ts", "project.ts", - "editorServices.ts", "protocol.ts", + "scriptInfo.ts", + "scriptVersionCache.ts", "session.ts", + "shared.ts", + "types.ts", + "typingsCache.ts", + "utilities.ts", ].map(function (f) { return path.join(serverDirectory, f); }); diff --git a/src/server/tsconfig.library.json b/src/server/tsconfig.library.json index c589d875c3a..397211e6ff4 100644 --- a/src/server/tsconfig.library.json +++ b/src/server/tsconfig.library.json @@ -2,12 +2,11 @@ "compilerOptions": { "noImplicitAny": true, "noImplicitThis": true, - "removeComments": true, + "removeComments": false, "preserveConstEnums": true, "pretty": true, "outFile": "../../built/local/tsserverlibrary.js", "sourceMap": true, - "stripInternal": true, "types": [ "node" ], @@ -17,17 +16,18 @@ "declaration": true }, "files": [ - "../services/shims.ts", - "../services/utilities.ts", - "shared.ts", - "utilities.ts", - "scriptVersionCache.ts", - "scriptInfo.ts", - "lsHost.ts", - "typingsCache.ts", - "project.ts", "editorServices.ts", - "protocol.ts", - "session.ts" + "lsHost.ts", + "project.ts", + "protocol.d.ts", + "scriptInfo.ts", + "scriptVersionCache.ts", + "session.ts", + "shared.ts", + "types.ts", + "typingsCache.ts", + "utilities.ts", + "../services/shims.ts", + "../services/utilities.ts" ] } From 3a9a136e515db9f0ef1bdd0839a6dc25f9dca171 Mon Sep 17 00:00:00 2001 From: Joel Day Date: Wed, 4 Jan 2017 15:56:16 -0800 Subject: [PATCH 3/3] Changes based on feedback. Whitespace cleanup. Switching back to protocol.ts and reenabling stripInternal. Marking internal symbols indirectly exported by dependencies of protocol.ts as internal. --- Gulpfile.ts | 2 +- Jakefile.js | 13 ++++++++----- src/server/editorServices.ts | 3 +++ src/server/project.ts | 2 ++ src/server/session.ts | 24 ++++++++++++++++++++++++ src/server/tsconfig.library.json | 7 ++----- src/server/types.ts | 1 + 7 files changed, 41 insertions(+), 11 deletions(-) diff --git a/Gulpfile.ts b/Gulpfile.ts index 22bf020a435..ef65454bc23 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -473,7 +473,7 @@ gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => { .pipe(gulp.dest(".")), dts.pipe(prependCopyright(/*outputCopyright*/true)) .pipe(insert.transform((content) => { - return content + "\r\nexport = ts;"; + return content + "\r\nexport = ts;\r\nexport as namespace ts;"; })) .pipe(gulp.dest(".")) ]); diff --git a/Jakefile.js b/Jakefile.js index b810477d861..093d6f16893 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -719,13 +719,16 @@ compileFile( [builtLocalDirectory, copyright, builtLocalCompiler].concat(languageServiceLibrarySources).concat(libraryTargets), /*prefixes*/[copyright], /*useBuiltCompiler*/ true, - { noOutFile: false, generateDeclarations: true }, - /*callback*/ function () { - + { noOutFile: false, generateDeclarations: true, stripInternal: true }, + /*callback*/ function () { prependFile(copyright, tsserverLibraryDefinitionFile); - // Appending 'export = ts;' at the end of the server library file to turn it into an external module - var tsserverLibraryDefinitionFileContents = fs.readFileSync(tsserverLibraryDefinitionFile).toString() + "\r\nexport = ts;"; + // Appending exports at the end of the server library + var tsserverLibraryDefinitionFileContents = + fs.readFileSync(tsserverLibraryDefinitionFile).toString() + + "\r\nexport = ts;" + + "\r\nexport as namespace ts;"; + fs.writeFileSync(tsserverLibraryDefinitionFile, tsserverLibraryDefinitionFileContents); }); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 00df53e1e35..38873a38aba 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -293,6 +293,7 @@ namespace ts.server { this.documentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames, host.getCurrentDirectory()); } + /* @internal */ getChangedFiles_TestOnly() { return this.changedFiles; } @@ -1274,6 +1275,7 @@ namespace ts.server { } } + /* @internal */ synchronizeProjectList(knownProjects: protocol.ProjectVersionInfo[]): ProjectFilesWithTSDiagnostics[] { const files: ProjectFilesWithTSDiagnostics[] = []; this.collectChanges(knownProjects, this.externalProjects, files); @@ -1282,6 +1284,7 @@ namespace ts.server { return files; } + /* @internal */ applyChangesInOpenFiles(openFiles: protocol.ExternalFile[], changedFiles: protocol.ChangedOpenFile[], closedFiles: string[]): void { const recordChangedFiles = changedFiles && !openFiles && !closedFiles; if (openFiles) { diff --git a/src/server/project.ts b/src/server/project.ts index 6085ee05159..ff2dd582b89 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -58,6 +58,7 @@ namespace ts.server { return counts.ts === 0 && counts.tsx === 0; } + /* @internal */ export interface ProjectFilesWithTSDiagnostics extends protocol.ProjectFiles { projectErrors: Diagnostic[]; } @@ -593,6 +594,7 @@ namespace ts.server { return false; } + /* @internal */ getChangesSinceVersion(lastKnownVersion?: number): ProjectFilesWithTSDiagnostics { this.updateGraph(); diff --git a/src/server/session.ts b/src/server/session.ts index 5c382aae7d3..b8eeb9219db 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -88,50 +88,65 @@ namespace ts.server { export namespace CommandNames { export const Brace: protocol.CommandTypes.Brace = "brace"; + /* @internal */ export const BraceFull: protocol.CommandTypes.BraceFull = "brace-full"; export const BraceCompletion: protocol.CommandTypes.BraceCompletion = "braceCompletion"; export const Change: protocol.CommandTypes.Change = "change"; export const Close: protocol.CommandTypes.Close = "close"; export const Completions: protocol.CommandTypes.Completions = "completions"; + /* @internal */ export const CompletionsFull: protocol.CommandTypes.CompletionsFull = "completions-full"; export const CompletionDetails: protocol.CommandTypes.CompletionDetails = "completionEntryDetails"; export const CompileOnSaveAffectedFileList: protocol.CommandTypes.CompileOnSaveAffectedFileList = "compileOnSaveAffectedFileList"; export const CompileOnSaveEmitFile: protocol.CommandTypes.CompileOnSaveEmitFile = "compileOnSaveEmitFile"; export const Configure: protocol.CommandTypes.Configure = "configure"; export const Definition: protocol.CommandTypes.Definition = "definition"; + /* @internal */ export const DefinitionFull: protocol.CommandTypes.DefinitionFull = "definition-full"; export const Exit: protocol.CommandTypes.Exit = "exit"; export const Format: protocol.CommandTypes.Format = "format"; export const Formatonkey: protocol.CommandTypes.Formatonkey = "formatonkey"; + /* @internal */ export const FormatFull: protocol.CommandTypes.FormatFull = "format-full"; + /* @internal */ export const FormatonkeyFull: protocol.CommandTypes.FormatonkeyFull = "formatonkey-full"; + /* @internal */ export const FormatRangeFull: protocol.CommandTypes.FormatRangeFull = "formatRange-full"; export const Geterr: protocol.CommandTypes.Geterr = "geterr"; export const GeterrForProject: protocol.CommandTypes.GeterrForProject = "geterrForProject"; export const Implementation: protocol.CommandTypes.Implementation = "implementation"; + /* @internal */ export const ImplementationFull: protocol.CommandTypes.ImplementationFull = "implementation-full"; export const SemanticDiagnosticsSync: protocol.CommandTypes.SemanticDiagnosticsSync = "semanticDiagnosticsSync"; export const SyntacticDiagnosticsSync: protocol.CommandTypes.SyntacticDiagnosticsSync = "syntacticDiagnosticsSync"; export const NavBar: protocol.CommandTypes.NavBar = "navbar"; + /* @internal */ export const NavBarFull: protocol.CommandTypes.NavBarFull = "navbar-full"; export const NavTree: protocol.CommandTypes.NavTree = "navtree"; export const NavTreeFull: protocol.CommandTypes.NavTreeFull = "navtree-full"; export const Navto: protocol.CommandTypes.Navto = "navto"; + /* @internal */ export const NavtoFull: protocol.CommandTypes.NavtoFull = "navto-full"; export const Occurrences: protocol.CommandTypes.Occurrences = "occurrences"; export const DocumentHighlights: protocol.CommandTypes.DocumentHighlights = "documentHighlights"; + /* @internal */ export const DocumentHighlightsFull: protocol.CommandTypes.DocumentHighlightsFull = "documentHighlights-full"; export const Open: protocol.CommandTypes.Open = "open"; export const Quickinfo: protocol.CommandTypes.Quickinfo = "quickinfo"; + /* @internal */ export const QuickinfoFull: protocol.CommandTypes.QuickinfoFull = "quickinfo-full"; export const References: protocol.CommandTypes.References = "references"; + /* @internal */ export const ReferencesFull: protocol.CommandTypes.ReferencesFull = "references-full"; export const Reload: protocol.CommandTypes.Reload = "reload"; export const Rename: protocol.CommandTypes.Rename = "rename"; + /* @internal */ export const RenameInfoFull: protocol.CommandTypes.RenameInfoFull = "rename-full"; + /* @internal */ export const RenameLocationsFull: protocol.CommandTypes.RenameLocationsFull = "renameLocations-full"; export const Saveto: protocol.CommandTypes.Saveto = "saveto"; export const SignatureHelp: protocol.CommandTypes.SignatureHelp = "signatureHelp"; + /* @internal */ export const SignatureHelpFull: protocol.CommandTypes.SignatureHelpFull = "signatureHelp-full"; export const TypeDefinition: protocol.CommandTypes.TypeDefinition = "typeDefinition"; export const ProjectInfo: protocol.CommandTypes.ProjectInfo = "projectInfo"; @@ -140,19 +155,28 @@ namespace ts.server { export const OpenExternalProject: protocol.CommandTypes.OpenExternalProject = "openExternalProject"; export const OpenExternalProjects: protocol.CommandTypes.OpenExternalProjects = "openExternalProjects"; export const CloseExternalProject: protocol.CommandTypes.CloseExternalProject = "closeExternalProject"; + /* @internal */ export const SynchronizeProjectList: protocol.CommandTypes.SynchronizeProjectList = "synchronizeProjectList"; + /* @internal */ export const ApplyChangedToOpenFiles: protocol.CommandTypes.ApplyChangedToOpenFiles = "applyChangedToOpenFiles"; + /* @internal */ export const EncodedSemanticClassificationsFull: protocol.CommandTypes.EncodedSemanticClassificationsFull = "encodedSemanticClassifications-full"; + /* @internal */ export const Cleanup: protocol.CommandTypes.Cleanup = "cleanup"; + /* @internal */ export const OutliningSpans: protocol.CommandTypes.OutliningSpans = "outliningSpans"; export const TodoComments: protocol.CommandTypes.TodoComments = "todoComments"; export const Indentation: protocol.CommandTypes.Indentation = "indentation"; export const DocCommentTemplate: protocol.CommandTypes.DocCommentTemplate = "docCommentTemplate"; + /* @internal */ export const CompilerOptionsDiagnosticsFull: protocol.CommandTypes.CompilerOptionsDiagnosticsFull = "compilerOptionsDiagnostics-full"; + /* @internal */ export const NameOrDottedNameSpan: protocol.CommandTypes.NameOrDottedNameSpan = "nameOrDottedNameSpan"; + /* @internal */ export const BreakpointStatement: protocol.CommandTypes.BreakpointStatement = "breakpointStatement"; export const CompilerOptionsForInferredProjects: protocol.CommandTypes.CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects"; export const GetCodeFixes: protocol.CommandTypes.GetCodeFixes = "getCodeFixes"; + /* @internal */ export const GetCodeFixesFull: protocol.CommandTypes.GetCodeFixesFull = "getCodeFixes-full"; export const GetSupportedCodeFixes: protocol.CommandTypes.GetSupportedCodeFixes = "getSupportedCodeFixes"; } diff --git a/src/server/tsconfig.library.json b/src/server/tsconfig.library.json index 397211e6ff4..76d700dd291 100644 --- a/src/server/tsconfig.library.json +++ b/src/server/tsconfig.library.json @@ -2,14 +2,11 @@ "compilerOptions": { "noImplicitAny": true, "noImplicitThis": true, - "removeComments": false, "preserveConstEnums": true, "pretty": true, "outFile": "../../built/local/tsserverlibrary.js", "sourceMap": true, - "types": [ - "node" - ], + "stripInternal": true, "target": "es5", "noUnusedLocals": true, "noUnusedParameters": true, @@ -19,7 +16,7 @@ "editorServices.ts", "lsHost.ts", "project.ts", - "protocol.d.ts", + "protocol.ts", "scriptInfo.ts", "scriptVersionCache.ts", "session.ts", diff --git a/src/server/types.ts b/src/server/types.ts index 9f53fa8def1..2c18f275202 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -82,6 +82,7 @@ declare namespace ts.server { readonly installSuccess: boolean; } + /* @internal */ export interface InstallTypingHost extends JsTyping.TypingResolutionHost { writeFile(path: string, content: string): void; createDirectory(path: string): void;