monaco.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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. * Configure inlay hints options.
  287. */
  288. setInlayHintsOptions(options: InlayHintsOptions): void;
  289. }
  290. export interface TypeScriptWorker {
  291. /**
  292. * Get diagnostic messages for any syntax issues in the given file.
  293. */
  294. getSyntacticDiagnostics(fileName: string): Promise<Diagnostic[]>;
  295. /**
  296. * Get diagnostic messages for any semantic issues in the given file.
  297. */
  298. getSemanticDiagnostics(fileName: string): Promise<Diagnostic[]>;
  299. /**
  300. * Get diagnostic messages for any suggestions related to the given file.
  301. */
  302. getSuggestionDiagnostics(fileName: string): Promise<Diagnostic[]>;
  303. /**
  304. * Get the content of a given file.
  305. */
  306. getScriptText(fileName: string): Promise<string | undefined>;
  307. /**
  308. * Get diagnostic messages related to the current compiler options.
  309. * @param fileName Not used
  310. */
  311. getCompilerOptionsDiagnostics(fileName: string): Promise<Diagnostic[]>;
  312. /**
  313. * Get code completions for the given file and position.
  314. * @returns `Promise<typescript.CompletionInfo | undefined>`
  315. */
  316. getCompletionsAtPosition(fileName: string, position: number): Promise<any | undefined>;
  317. /**
  318. * Get code completion details for the given file, position, and entry.
  319. * @returns `Promise<typescript.CompletionEntryDetails | undefined>`
  320. */
  321. getCompletionEntryDetails(
  322. fileName: string,
  323. position: number,
  324. entry: string
  325. ): Promise<any | undefined>;
  326. /**
  327. * Get signature help items for the item at the given file and position.
  328. * @returns `Promise<typescript.SignatureHelpItems | undefined>`
  329. */
  330. getSignatureHelpItems(
  331. fileName: string,
  332. position: number,
  333. options: any
  334. ): Promise<any | undefined>;
  335. /**
  336. * Get quick info for the item at the given position in the file.
  337. * @returns `Promise<typescript.QuickInfo | undefined>`
  338. */
  339. getQuickInfoAtPosition(fileName: string, position: number): Promise<any | undefined>;
  340. /**
  341. * Get other ranges which are related to the item at the given position in the file (often used for highlighting).
  342. * @returns `Promise<ReadonlyArray<typescript.ReferenceEntry> | undefined>`
  343. */
  344. getOccurrencesAtPosition(
  345. fileName: string,
  346. position: number
  347. ): Promise<ReadonlyArray<any> | undefined>;
  348. /**
  349. * Get the definition of the item at the given position in the file.
  350. * @returns `Promise<ReadonlyArray<typescript.DefinitionInfo> | undefined>`
  351. */
  352. getDefinitionAtPosition(
  353. fileName: string,
  354. position: number
  355. ): Promise<ReadonlyArray<any> | undefined>;
  356. /**
  357. * Get references to the item at the given position in the file.
  358. * @returns `Promise<typescript.ReferenceEntry[] | undefined>`
  359. */
  360. getReferencesAtPosition(fileName: string, position: number): Promise<any[] | undefined>;
  361. /**
  362. * Get outline entries for the item at the given position in the file.
  363. * @returns `Promise<typescript.NavigationBarItem[]>`
  364. */
  365. getNavigationBarItems(fileName: string): Promise<any[]>;
  366. /**
  367. * Get changes which should be applied to format the given file.
  368. * @param options `typescript.FormatCodeOptions`
  369. * @returns `Promise<typescript.TextChange[]>`
  370. */
  371. getFormattingEditsForDocument(fileName: string, options: any): Promise<any[]>;
  372. /**
  373. * Get changes which should be applied to format the given range in the file.
  374. * @param options `typescript.FormatCodeOptions`
  375. * @returns `Promise<typescript.TextChange[]>`
  376. */
  377. getFormattingEditsForRange(
  378. fileName: string,
  379. start: number,
  380. end: number,
  381. options: any
  382. ): Promise<any[]>;
  383. /**
  384. * Get formatting changes which should be applied after the given keystroke.
  385. * @param options `typescript.FormatCodeOptions`
  386. * @returns `Promise<typescript.TextChange[]>`
  387. */
  388. getFormattingEditsAfterKeystroke(
  389. fileName: string,
  390. postion: number,
  391. ch: string,
  392. options: any
  393. ): Promise<any[]>;
  394. /**
  395. * Get other occurrences which should be updated when renaming the item at the given file and position.
  396. * @returns `Promise<readonly typescript.RenameLocation[] | undefined>`
  397. */
  398. findRenameLocations(
  399. fileName: string,
  400. positon: number,
  401. findInStrings: boolean,
  402. findInComments: boolean,
  403. providePrefixAndSuffixTextForRename: boolean
  404. ): Promise<readonly any[] | undefined>;
  405. /**
  406. * Get edits which should be applied to rename the item at the given file and position (or a failure reason).
  407. * @param options `typescript.RenameInfoOptions`
  408. * @returns `Promise<typescript.RenameInfo>`
  409. */
  410. getRenameInfo(fileName: string, positon: number, options: any): Promise<any>;
  411. /**
  412. * Get transpiled output for the given file.
  413. * @returns `typescript.EmitOutput`
  414. */
  415. getEmitOutput(fileName: string): Promise<EmitOutput>;
  416. /**
  417. * Get possible code fixes at the given position in the file.
  418. * @param formatOptions `typescript.FormatCodeOptions`
  419. * @returns `Promise<ReadonlyArray<typescript.CodeFixAction>>`
  420. */
  421. getCodeFixesAtPosition(
  422. fileName: string,
  423. start: number,
  424. end: number,
  425. errorCodes: number[],
  426. formatOptions: any
  427. ): Promise<ReadonlyArray<any>>;
  428. /**
  429. * Get inlay hints in the range of the file.
  430. * @param fileName
  431. * @returns `Promise<typescript.InlayHint[]>`
  432. */
  433. provideInlayHints(fileName: string, start: number, end: number): Promise<ReadonlyArray<any>>;
  434. }
  435. export const typescriptVersion: string;
  436. export const typescriptDefaults: LanguageServiceDefaults;
  437. export const javascriptDefaults: LanguageServiceDefaults;
  438. export const getTypeScriptWorker: () => Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>>;
  439. export const getJavaScriptWorker: () => Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>>;
  440. }