monaco.d.ts 14 KB

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