1namespace ts.server { 2 export enum LogLevel { 3 terse, 4 normal, 5 requestTime, 6 verbose 7 } 8 9 export const emptyArray: SortedReadonlyArray<never> = createSortedArray<never>(); 10 11 export interface Logger { 12 close(): void; 13 hasLevel(level: LogLevel): boolean; 14 loggingEnabled(): boolean; 15 perftrc(s: string): void; 16 info(s: string): void; 17 startGroup(): void; 18 endGroup(): void; 19 msg(s: string, type?: Msg): void; 20 getLogFileName(): string | undefined; 21 } 22 23 // TODO: Use a const enum (https://github.com/Microsoft/TypeScript/issues/16804) 24 export enum Msg { 25 Err = "Err", 26 Info = "Info", 27 Perf = "Perf", 28 } 29 export namespace Msg { 30 /** @deprecated Only here for backwards-compatibility. Prefer just `Msg`. */ 31 export type Types = Msg; 32 } 33 34 export function createInstallTypingsRequest(project: Project, typeAcquisition: TypeAcquisition, unresolvedImports: SortedReadonlyArray<string>, cachePath?: string): DiscoverTypings { 35 return { 36 projectName: project.getProjectName(), 37 fileNames: project.getFileNames(/*excludeFilesFromExternalLibraries*/ true, /*excludeConfigFiles*/ true).concat(project.getExcludedFiles() as NormalizedPath[]), 38 compilerOptions: project.getCompilationSettings(), 39 watchOptions: project.projectService.getWatchOptions(project), 40 typeAcquisition, 41 unresolvedImports, 42 projectRootPath: project.getCurrentDirectory() as Path, 43 cachePath, 44 kind: "discover" 45 }; 46 } 47 48 export namespace Errors { 49 export function ThrowNoProject(): never { 50 throw new Error("No Project."); 51 } 52 export function ThrowProjectLanguageServiceDisabled(): never { 53 throw new Error("The project's language service is disabled."); 54 } 55 export function ThrowProjectDoesNotContainDocument(fileName: string, project: Project): never { 56 throw new Error(`Project '${project.getProjectName()}' does not contain document '${fileName}'`); 57 } 58 } 59 60 export type NormalizedPath = string & { __normalizedPathTag: any }; 61 62 export function toNormalizedPath(fileName: string): NormalizedPath { 63 return normalizePath(fileName) as NormalizedPath; 64 } 65 66 export function normalizedPathToPath(normalizedPath: NormalizedPath, currentDirectory: string, getCanonicalFileName: (f: string) => string): Path { 67 const f = isRootedDiskPath(normalizedPath) ? normalizedPath : getNormalizedAbsolutePath(normalizedPath, currentDirectory); 68 return getCanonicalFileName(f) as Path; 69 } 70 71 export function asNormalizedPath(fileName: string): NormalizedPath { 72 return fileName as NormalizedPath; 73 } 74 75 export interface NormalizedPathMap<T> { 76 get(path: NormalizedPath): T | undefined; 77 set(path: NormalizedPath, value: T): void; 78 contains(path: NormalizedPath): boolean; 79 remove(path: NormalizedPath): void; 80 } 81 82 export function createNormalizedPathMap<T>(): NormalizedPathMap<T> { 83 const map = new Map<string, T>(); 84 return { 85 get(path) { 86 return map.get(path); 87 }, 88 set(path, value) { 89 map.set(path, value); 90 }, 91 contains(path) { 92 return map.has(path); 93 }, 94 remove(path) { 95 map.delete(path); 96 } 97 }; 98 } 99 100 /*@internal*/ 101 export interface ProjectOptions { 102 configHasExtendsProperty: boolean; 103 /** 104 * true if config file explicitly listed files 105 */ 106 configHasFilesProperty: boolean; 107 configHasIncludeProperty: boolean; 108 configHasExcludeProperty: boolean; 109 } 110 111 export function isInferredProjectName(name: string) { 112 // POSIX defines /dev/null as a device - there should be no file with this prefix 113 return /dev\/null\/inferredProject\d+\*/.test(name); 114 } 115 116 export function makeInferredProjectName(counter: number): string { 117 return `/dev/null/inferredProject${counter}*`; 118 } 119 120 /*@internal*/ 121 export function makeAutoImportProviderProjectName(counter: number): string { 122 return `/dev/null/autoImportProviderProject${counter}*`; 123 } 124 125 /*@internal*/ 126 export function makeAuxiliaryProjectName(counter: number): string { 127 return `/dev/null/auxiliaryProject${counter}*`; 128 } 129 130 export function createSortedArray<T>(): SortedArray<T> { 131 return [] as any as SortedArray<T>; // TODO: GH#19873 132 } 133} 134