monaco.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. /// <reference path="node_modules/monaco-editor-core/monaco.d.ts" />
  6. declare namespace monaco.languages.typescript {
  7. export enum ModuleKind {
  8. None = 0,
  9. CommonJS = 1,
  10. AMD = 2,
  11. UMD = 3,
  12. System = 4,
  13. ES2015 = 5,
  14. ESNext = 99
  15. }
  16. export enum JsxEmit {
  17. None = 0,
  18. Preserve = 1,
  19. React = 2,
  20. ReactNative = 3,
  21. ReactJSX = 4,
  22. ReactJSXDev = 5
  23. }
  24. export enum NewLineKind {
  25. CarriageReturnLineFeed = 0,
  26. LineFeed = 1
  27. }
  28. export enum ScriptTarget {
  29. ES3 = 0,
  30. ES5 = 1,
  31. ES2015 = 2,
  32. ES2016 = 3,
  33. ES2017 = 4,
  34. ES2018 = 5,
  35. ES2019 = 6,
  36. ES2020 = 7,
  37. ESNext = 99,
  38. JSON = 100,
  39. Latest = 99
  40. }
  41. export enum ModuleResolutionKind {
  42. Classic = 1,
  43. NodeJs = 2
  44. }
  45. interface MapLike<T> {
  46. [index: string]: T;
  47. }
  48. type CompilerOptionsValue =
  49. | string
  50. | number
  51. | boolean
  52. | (string | number)[]
  53. | string[]
  54. | MapLike<string[]>
  55. | null
  56. | undefined;
  57. interface CompilerOptions {
  58. allowJs?: boolean;
  59. allowSyntheticDefaultImports?: boolean;
  60. allowUmdGlobalAccess?: boolean;
  61. allowUnreachableCode?: boolean;
  62. allowUnusedLabels?: boolean;
  63. alwaysStrict?: boolean;
  64. baseUrl?: string;
  65. charset?: string;
  66. checkJs?: boolean;
  67. declaration?: boolean;
  68. declarationMap?: boolean;
  69. emitDeclarationOnly?: boolean;
  70. declarationDir?: string;
  71. disableSizeLimit?: boolean;
  72. disableSourceOfProjectReferenceRedirect?: boolean;
  73. downlevelIteration?: boolean;
  74. emitBOM?: boolean;
  75. emitDecoratorMetadata?: boolean;
  76. experimentalDecorators?: boolean;
  77. forceConsistentCasingInFileNames?: boolean;
  78. importHelpers?: boolean;
  79. inlineSourceMap?: boolean;
  80. inlineSources?: boolean;
  81. isolatedModules?: boolean;
  82. jsx?: JsxEmit;
  83. keyofStringsOnly?: boolean;
  84. lib?: string[];
  85. locale?: string;
  86. mapRoot?: string;
  87. maxNodeModuleJsDepth?: number;
  88. module?: ModuleKind;
  89. moduleResolution?: ModuleResolutionKind;
  90. newLine?: NewLineKind;
  91. noEmit?: boolean;
  92. noEmitHelpers?: boolean;
  93. noEmitOnError?: boolean;
  94. noErrorTruncation?: boolean;
  95. noFallthroughCasesInSwitch?: boolean;
  96. noImplicitAny?: boolean;
  97. noImplicitReturns?: boolean;
  98. noImplicitThis?: boolean;
  99. noStrictGenericChecks?: boolean;
  100. noUnusedLocals?: boolean;
  101. noUnusedParameters?: boolean;
  102. noImplicitUseStrict?: boolean;
  103. noLib?: boolean;
  104. noResolve?: boolean;
  105. out?: string;
  106. outDir?: string;
  107. outFile?: string;
  108. paths?: MapLike<string[]>;
  109. preserveConstEnums?: boolean;
  110. preserveSymlinks?: boolean;
  111. project?: string;
  112. reactNamespace?: string;
  113. jsxFactory?: string;
  114. composite?: boolean;
  115. removeComments?: boolean;
  116. rootDir?: string;
  117. rootDirs?: string[];
  118. skipLibCheck?: boolean;
  119. skipDefaultLibCheck?: boolean;
  120. sourceMap?: boolean;
  121. sourceRoot?: string;
  122. strict?: boolean;
  123. strictFunctionTypes?: boolean;
  124. strictBindCallApply?: boolean;
  125. strictNullChecks?: boolean;
  126. strictPropertyInitialization?: boolean;
  127. stripInternal?: boolean;
  128. suppressExcessPropertyErrors?: boolean;
  129. suppressImplicitAnyIndexErrors?: boolean;
  130. target?: ScriptTarget;
  131. traceResolution?: boolean;
  132. resolveJsonModule?: boolean;
  133. types?: string[];
  134. /** Paths used to compute primary types search locations */
  135. typeRoots?: string[];
  136. esModuleInterop?: boolean;
  137. useDefineForClassFields?: boolean;
  138. [option: string]: CompilerOptionsValue | undefined;
  139. }
  140. export interface DiagnosticsOptions {
  141. noSemanticValidation?: boolean;
  142. noSyntaxValidation?: boolean;
  143. noSuggestionDiagnostics?: boolean;
  144. diagnosticCodesToIgnore?: number[];
  145. }
  146. export interface WorkerOptions {
  147. /** A full HTTP path to a JavaScript file which adds a function `customTSWorkerFactory` to the self inside a web-worker */
  148. customWorkerPath?: string;
  149. }
  150. interface IExtraLib {
  151. content: string;
  152. version: number;
  153. }
  154. export interface IExtraLibs {
  155. [path: string]: IExtraLib;
  156. }
  157. /**
  158. * A linked list of formatted diagnostic messages to be used as part of a multiline message.
  159. * It is built from the bottom up, leaving the head to be the "main" diagnostic.
  160. */
  161. interface DiagnosticMessageChain {
  162. messageText: string;
  163. /** Diagnostic category: warning = 0, error = 1, suggestion = 2, message = 3 */
  164. category: 0 | 1 | 2 | 3;
  165. code: number;
  166. next?: DiagnosticMessageChain[];
  167. }
  168. export interface Diagnostic extends DiagnosticRelatedInformation {
  169. /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
  170. reportsUnnecessary?: {};
  171. reportsDeprecated?: {};
  172. source?: string;
  173. relatedInformation?: DiagnosticRelatedInformation[];
  174. }
  175. export interface DiagnosticRelatedInformation {
  176. /** Diagnostic category: warning = 0, error = 1, suggestion = 2, message = 3 */
  177. category: 0 | 1 | 2 | 3;
  178. code: number;
  179. /** TypeScriptWorker removes all but the `fileName` property to avoid serializing circular JSON structures. */
  180. file:
  181. | {
  182. fileName: string;
  183. }
  184. | undefined;
  185. start: number | undefined;
  186. length: number | undefined;
  187. messageText: string | DiagnosticMessageChain;
  188. }
  189. interface EmitOutput {
  190. outputFiles: OutputFile[];
  191. emitSkipped: boolean;
  192. }
  193. interface OutputFile {
  194. name: string;
  195. writeByteOrderMark: boolean;
  196. text: string;
  197. }
  198. export interface LanguageServiceDefaults {
  199. /**
  200. * Event fired when compiler options or diagnostics options are changed.
  201. */
  202. readonly onDidChange: IEvent<void>;
  203. /**
  204. * Event fired when extra libraries registered with the language service change.
  205. */
  206. readonly onDidExtraLibsChange: IEvent<void>;
  207. readonly workerOptions: WorkerOptions;
  208. /**
  209. * Get the current extra libs registered with the language service.
  210. */
  211. getExtraLibs(): IExtraLibs;
  212. /**
  213. * Add an additional source file to the language service. Use this
  214. * for typescript (definition) files that won't be loaded as editor
  215. * documents, like `jquery.d.ts`.
  216. *
  217. * @param content The file content
  218. * @param filePath An optional file path
  219. * @returns A disposable which will remove the file from the
  220. * language service upon disposal.
  221. */
  222. addExtraLib(content: string, filePath?: string): IDisposable;
  223. /**
  224. * Remove all existing extra libs and set the additional source
  225. * files to the language service. Use this for typescript definition
  226. * files that won't be loaded as editor documents, like `jquery.d.ts`.
  227. * @param libs An array of entries to register.
  228. */
  229. setExtraLibs(
  230. libs: {
  231. content: string;
  232. filePath?: string;
  233. }[]
  234. ): void;
  235. /**
  236. * Get current TypeScript compiler options for the language service.
  237. */
  238. getCompilerOptions(): CompilerOptions;
  239. /**
  240. * Set TypeScript compiler options.
  241. */
  242. setCompilerOptions(options: CompilerOptions): void;
  243. /**
  244. * Get the current diagnostics options for the language service.
  245. */
  246. getDiagnosticsOptions(): DiagnosticsOptions;
  247. /**
  248. * Configure whether syntactic and/or semantic validation should
  249. * be performed
  250. */
  251. setDiagnosticsOptions(options: DiagnosticsOptions): void;
  252. /**
  253. * Configure webworker options
  254. */
  255. setWorkerOptions(options: WorkerOptions): void;
  256. /**
  257. * No-op.
  258. */
  259. setMaximumWorkerIdleTime(value: number): void;
  260. /**
  261. * Configure if all existing models should be eagerly sync'd
  262. * to the worker on start or restart.
  263. */
  264. setEagerModelSync(value: boolean): void;
  265. /**
  266. * Get the current setting for whether all existing models should be eagerly sync'd
  267. * to the worker on start or restart.
  268. */
  269. getEagerModelSync(): boolean;
  270. }
  271. export interface TypeScriptWorker {
  272. /**
  273. * Get diagnostic messages for any syntax issues in the given file.
  274. */
  275. getSyntacticDiagnostics(fileName: string): Promise<Diagnostic[]>;
  276. /**
  277. * Get diagnostic messages for any semantic issues in the given file.
  278. */
  279. getSemanticDiagnostics(fileName: string): Promise<Diagnostic[]>;
  280. /**
  281. * Get diagnostic messages for any suggestions related to the given file.
  282. */
  283. getSuggestionDiagnostics(fileName: string): Promise<Diagnostic[]>;
  284. /**
  285. * Get the content of a given file.
  286. */
  287. getScriptText(fileName: string): Promise<string | undefined>;
  288. /**
  289. * Get diagnostic messages related to the current compiler options.
  290. * @param fileName Not used
  291. */
  292. getCompilerOptionsDiagnostics(fileName: string): Promise<Diagnostic[]>;
  293. /**
  294. * Get code completions for the given file and position.
  295. * @returns `Promise<typescript.CompletionInfo | undefined>`
  296. */
  297. getCompletionsAtPosition(fileName: string, position: number): Promise<any | undefined>;
  298. /**
  299. * Get code completion details for the given file, position, and entry.
  300. * @returns `Promise<typescript.CompletionEntryDetails | undefined>`
  301. */
  302. getCompletionEntryDetails(
  303. fileName: string,
  304. position: number,
  305. entry: string
  306. ): Promise<any | undefined>;
  307. /**
  308. * Get signature help items for the item at the given file and position.
  309. * @returns `Promise<typescript.SignatureHelpItems | undefined>`
  310. */
  311. getSignatureHelpItems(
  312. fileName: string,
  313. position: number,
  314. options: any
  315. ): Promise<any | undefined>;
  316. /**
  317. * Get quick info for the item at the given position in the file.
  318. * @returns `Promise<typescript.QuickInfo | undefined>`
  319. */
  320. getQuickInfoAtPosition(fileName: string, position: number): Promise<any | undefined>;
  321. /**
  322. * Get other ranges which are related to the item at the given position in the file (often used for highlighting).
  323. * @returns `Promise<ReadonlyArray<typescript.ReferenceEntry> | undefined>`
  324. */
  325. getOccurrencesAtPosition(
  326. fileName: string,
  327. position: number
  328. ): Promise<ReadonlyArray<any> | undefined>;
  329. /**
  330. * Get the definition of the item at the given position in the file.
  331. * @returns `Promise<ReadonlyArray<typescript.DefinitionInfo> | undefined>`
  332. */
  333. getDefinitionAtPosition(
  334. fileName: string,
  335. position: number
  336. ): Promise<ReadonlyArray<any> | undefined>;
  337. /**
  338. * Get references to the item at the given position in the file.
  339. * @returns `Promise<typescript.ReferenceEntry[] | undefined>`
  340. */
  341. getReferencesAtPosition(fileName: string, position: number): Promise<any[] | undefined>;
  342. /**
  343. * Get outline entries for the item at the given position in the file.
  344. * @returns `Promise<typescript.NavigationBarItem[]>`
  345. */
  346. getNavigationBarItems(fileName: string): Promise<any[]>;
  347. /**
  348. * Get changes which should be applied to format the given file.
  349. * @param options `typescript.FormatCodeOptions`
  350. * @returns `Promise<typescript.TextChange[]>`
  351. */
  352. getFormattingEditsForDocument(fileName: string, options: any): Promise<any[]>;
  353. /**
  354. * Get changes which should be applied to format the given range in the file.
  355. * @param options `typescript.FormatCodeOptions`
  356. * @returns `Promise<typescript.TextChange[]>`
  357. */
  358. getFormattingEditsForRange(
  359. fileName: string,
  360. start: number,
  361. end: number,
  362. options: any
  363. ): Promise<any[]>;
  364. /**
  365. * Get formatting changes which should be applied after the given keystroke.
  366. * @param options `typescript.FormatCodeOptions`
  367. * @returns `Promise<typescript.TextChange[]>`
  368. */
  369. getFormattingEditsAfterKeystroke(
  370. fileName: string,
  371. postion: number,
  372. ch: string,
  373. options: any
  374. ): Promise<any[]>;
  375. /**
  376. * Get other occurrences which should be updated when renaming the item at the given file and position.
  377. * @returns `Promise<readonly typescript.RenameLocation[] | undefined>`
  378. */
  379. findRenameLocations(
  380. fileName: string,
  381. positon: number,
  382. findInStrings: boolean,
  383. findInComments: boolean,
  384. providePrefixAndSuffixTextForRename: boolean
  385. ): Promise<readonly any[] | undefined>;
  386. /**
  387. * Get edits which should be applied to rename the item at the given file and position (or a failure reason).
  388. * @param options `typescript.RenameInfoOptions`
  389. * @returns `Promise<typescript.RenameInfo>`
  390. */
  391. getRenameInfo(fileName: string, positon: number, options: any): Promise<any>;
  392. /**
  393. * Get transpiled output for the given file.
  394. * @returns `typescript.EmitOutput`
  395. */
  396. getEmitOutput(fileName: string): Promise<EmitOutput>;
  397. /**
  398. * Get possible code fixes at the given position in the file.
  399. * @param formatOptions `typescript.FormatCodeOptions`
  400. * @returns `Promise<ReadonlyArray<typescript.CodeFixAction>>`
  401. */
  402. getCodeFixesAtPosition(
  403. fileName: string,
  404. start: number,
  405. end: number,
  406. errorCodes: number[],
  407. formatOptions: any
  408. ): Promise<ReadonlyArray<any>>;
  409. }
  410. export const typescriptVersion: string;
  411. export const typescriptDefaults: LanguageServiceDefaults;
  412. export const javascriptDefaults: LanguageServiceDefaults;
  413. export const getTypeScriptWorker: () => Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>>;
  414. export const getJavaScriptWorker: () => Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>>;
  415. }