monaco.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. /**
  145. * Limit diagnostic computation to only visible files.
  146. * Defaults to false.
  147. */
  148. onlyVisible?: boolean;
  149. diagnosticCodesToIgnore?: number[];
  150. }
  151. export interface WorkerOptions {
  152. /** A full HTTP path to a JavaScript file which adds a function `customTSWorkerFactory` to the self inside a web-worker */
  153. customWorkerPath?: string;
  154. }
  155. interface InlayHintsOptions {
  156. readonly includeInlayParameterNameHints?: 'none' | 'literals' | 'all';
  157. readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean;
  158. readonly includeInlayFunctionParameterTypeHints?: boolean;
  159. readonly includeInlayVariableTypeHints?: boolean;
  160. readonly includeInlayPropertyDeclarationTypeHints?: boolean;
  161. readonly includeInlayFunctionLikeReturnTypeHints?: boolean;
  162. readonly includeInlayEnumMemberValueHints?: boolean;
  163. }
  164. interface IExtraLib {
  165. content: string;
  166. version: number;
  167. }
  168. export interface IExtraLibs {
  169. [path: string]: IExtraLib;
  170. }
  171. /**
  172. * A linked list of formatted diagnostic messages to be used as part of a multiline message.
  173. * It is built from the bottom up, leaving the head to be the "main" diagnostic.
  174. */
  175. interface DiagnosticMessageChain {
  176. messageText: string;
  177. /** Diagnostic category: warning = 0, error = 1, suggestion = 2, message = 3 */
  178. category: 0 | 1 | 2 | 3;
  179. code: number;
  180. next?: DiagnosticMessageChain[];
  181. }
  182. export interface Diagnostic extends DiagnosticRelatedInformation {
  183. /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
  184. reportsUnnecessary?: {};
  185. reportsDeprecated?: {};
  186. source?: string;
  187. relatedInformation?: DiagnosticRelatedInformation[];
  188. }
  189. export interface DiagnosticRelatedInformation {
  190. /** Diagnostic category: warning = 0, error = 1, suggestion = 2, message = 3 */
  191. category: 0 | 1 | 2 | 3;
  192. code: number;
  193. /** TypeScriptWorker removes all but the `fileName` property to avoid serializing circular JSON structures. */
  194. file:
  195. | {
  196. fileName: string;
  197. }
  198. | undefined;
  199. start: number | undefined;
  200. length: number | undefined;
  201. messageText: string | DiagnosticMessageChain;
  202. }
  203. interface EmitOutput {
  204. outputFiles: OutputFile[];
  205. emitSkipped: boolean;
  206. }
  207. interface OutputFile {
  208. name: string;
  209. writeByteOrderMark: boolean;
  210. text: string;
  211. }
  212. export interface LanguageServiceDefaults {
  213. /**
  214. * Event fired when compiler options or diagnostics options are changed.
  215. */
  216. readonly onDidChange: IEvent<void>;
  217. /**
  218. * Event fired when extra libraries registered with the language service change.
  219. */
  220. readonly onDidExtraLibsChange: IEvent<void>;
  221. readonly workerOptions: WorkerOptions;
  222. readonly inlayHintsOptions: InlayHintsOptions;
  223. /**
  224. * Get the current extra libs registered with the language service.
  225. */
  226. getExtraLibs(): IExtraLibs;
  227. /**
  228. * Add an additional source file to the language service. Use this
  229. * for typescript (definition) files that won't be loaded as editor
  230. * documents, like `jquery.d.ts`.
  231. *
  232. * @param content The file content
  233. * @param filePath An optional file path
  234. * @returns A disposable which will remove the file from the
  235. * language service upon disposal.
  236. */
  237. addExtraLib(content: string, filePath?: string): IDisposable;
  238. /**
  239. * Remove all existing extra libs and set the additional source
  240. * files to the language service. Use this for typescript definition
  241. * files that won't be loaded as editor documents, like `jquery.d.ts`.
  242. * @param libs An array of entries to register.
  243. */
  244. setExtraLibs(
  245. libs: {
  246. content: string;
  247. filePath?: string;
  248. }[]
  249. ): void;
  250. /**
  251. * Get current TypeScript compiler options for the language service.
  252. */
  253. getCompilerOptions(): CompilerOptions;
  254. /**
  255. * Set TypeScript compiler options.
  256. */
  257. setCompilerOptions(options: CompilerOptions): void;
  258. /**
  259. * Get the current diagnostics options for the language service.
  260. */
  261. getDiagnosticsOptions(): DiagnosticsOptions;
  262. /**
  263. * Configure whether syntactic and/or semantic validation should
  264. * be performed
  265. */
  266. setDiagnosticsOptions(options: DiagnosticsOptions): void;
  267. /**
  268. * Configure webworker options
  269. */
  270. setWorkerOptions(options: WorkerOptions): void;
  271. /**
  272. * No-op.
  273. */
  274. setMaximumWorkerIdleTime(value: number): void;
  275. /**
  276. * Configure if all existing models should be eagerly sync'd
  277. * to the worker on start or restart.
  278. */
  279. setEagerModelSync(value: boolean): void;
  280. /**
  281. * Get the current setting for whether all existing models should be eagerly sync'd
  282. * to the worker on start or restart.
  283. */
  284. getEagerModelSync(): boolean;
  285. }
  286. export interface TypeScriptWorker {
  287. /**
  288. * Get diagnostic messages for any syntax issues in the given file.
  289. */
  290. getSyntacticDiagnostics(fileName: string): Promise<Diagnostic[]>;
  291. /**
  292. * Get diagnostic messages for any semantic issues in the given file.
  293. */
  294. getSemanticDiagnostics(fileName: string): Promise<Diagnostic[]>;
  295. /**
  296. * Get diagnostic messages for any suggestions related to the given file.
  297. */
  298. getSuggestionDiagnostics(fileName: string): Promise<Diagnostic[]>;
  299. /**
  300. * Get the content of a given file.
  301. */
  302. getScriptText(fileName: string): Promise<string | undefined>;
  303. /**
  304. * Get diagnostic messages related to the current compiler options.
  305. * @param fileName Not used
  306. */
  307. getCompilerOptionsDiagnostics(fileName: string): Promise<Diagnostic[]>;
  308. /**
  309. * Get code completions for the given file and position.
  310. * @returns `Promise<typescript.CompletionInfo | undefined>`
  311. */
  312. getCompletionsAtPosition(fileName: string, position: number): Promise<any | undefined>;
  313. /**
  314. * Get code completion details for the given file, position, and entry.
  315. * @returns `Promise<typescript.CompletionEntryDetails | undefined>`
  316. */
  317. getCompletionEntryDetails(
  318. fileName: string,
  319. position: number,
  320. entry: string
  321. ): Promise<any | undefined>;
  322. /**
  323. * Get signature help items for the item at the given file and position.
  324. * @returns `Promise<typescript.SignatureHelpItems | undefined>`
  325. */
  326. getSignatureHelpItems(
  327. fileName: string,
  328. position: number,
  329. options: any
  330. ): Promise<any | undefined>;
  331. /**
  332. * Get quick info for the item at the given position in the file.
  333. * @returns `Promise<typescript.QuickInfo | undefined>`
  334. */
  335. getQuickInfoAtPosition(fileName: string, position: number): Promise<any | undefined>;
  336. /**
  337. * Get other ranges which are related to the item at the given position in the file (often used for highlighting).
  338. * @returns `Promise<ReadonlyArray<typescript.ReferenceEntry> | undefined>`
  339. */
  340. getOccurrencesAtPosition(
  341. fileName: string,
  342. position: number
  343. ): Promise<ReadonlyArray<any> | undefined>;
  344. /**
  345. * Get the definition of the item at the given position in the file.
  346. * @returns `Promise<ReadonlyArray<typescript.DefinitionInfo> | undefined>`
  347. */
  348. getDefinitionAtPosition(
  349. fileName: string,
  350. position: number
  351. ): Promise<ReadonlyArray<any> | undefined>;
  352. /**
  353. * Get references to the item at the given position in the file.
  354. * @returns `Promise<typescript.ReferenceEntry[] | undefined>`
  355. */
  356. getReferencesAtPosition(fileName: string, position: number): Promise<any[] | undefined>;
  357. /**
  358. * Get outline entries for the item at the given position in the file.
  359. * @returns `Promise<typescript.NavigationBarItem[]>`
  360. */
  361. getNavigationBarItems(fileName: string): Promise<any[]>;
  362. /**
  363. * Get changes which should be applied to format the given file.
  364. * @param options `typescript.FormatCodeOptions`
  365. * @returns `Promise<typescript.TextChange[]>`
  366. */
  367. getFormattingEditsForDocument(fileName: string, options: any): Promise<any[]>;
  368. /**
  369. * Get changes which should be applied to format the given range in the file.
  370. * @param options `typescript.FormatCodeOptions`
  371. * @returns `Promise<typescript.TextChange[]>`
  372. */
  373. getFormattingEditsForRange(
  374. fileName: string,
  375. start: number,
  376. end: number,
  377. options: any
  378. ): Promise<any[]>;
  379. /**
  380. * Get formatting changes which should be applied after the given keystroke.
  381. * @param options `typescript.FormatCodeOptions`
  382. * @returns `Promise<typescript.TextChange[]>`
  383. */
  384. getFormattingEditsAfterKeystroke(
  385. fileName: string,
  386. postion: number,
  387. ch: string,
  388. options: any
  389. ): Promise<any[]>;
  390. /**
  391. * Get other occurrences which should be updated when renaming the item at the given file and position.
  392. * @returns `Promise<readonly typescript.RenameLocation[] | undefined>`
  393. */
  394. findRenameLocations(
  395. fileName: string,
  396. positon: number,
  397. findInStrings: boolean,
  398. findInComments: boolean,
  399. providePrefixAndSuffixTextForRename: boolean
  400. ): Promise<readonly any[] | undefined>;
  401. /**
  402. * Get edits which should be applied to rename the item at the given file and position (or a failure reason).
  403. * @param options `typescript.RenameInfoOptions`
  404. * @returns `Promise<typescript.RenameInfo>`
  405. */
  406. getRenameInfo(fileName: string, positon: number, options: any): Promise<any>;
  407. /**
  408. * Get transpiled output for the given file.
  409. * @returns `typescript.EmitOutput`
  410. */
  411. getEmitOutput(fileName: string): Promise<EmitOutput>;
  412. /**
  413. * Get possible code fixes at the given position in the file.
  414. * @param formatOptions `typescript.FormatCodeOptions`
  415. * @returns `Promise<ReadonlyArray<typescript.CodeFixAction>>`
  416. */
  417. getCodeFixesAtPosition(
  418. fileName: string,
  419. start: number,
  420. end: number,
  421. errorCodes: number[],
  422. formatOptions: any
  423. ): Promise<ReadonlyArray<any>>;
  424. /**
  425. * Get inlay hints in the range of the file.
  426. * @param fileName
  427. * @returns `Promise<typescript.InlayHint[]>`
  428. */
  429. provideInlayHints(fileName: string, start: number, end: number): Promise<ReadonlyArray<any>>;
  430. }
  431. export const typescriptVersion: string;
  432. export const typescriptDefaults: LanguageServiceDefaults;
  433. export const javascriptDefaults: LanguageServiceDefaults;
  434. export const getTypeScriptWorker: () => Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>>;
  435. export const getJavaScriptWorker: () => Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>>;
  436. }