languages.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. import { Codicon } from '../../base/common/codicons.js';
  2. import { URI } from '../../base/common/uri.js';
  3. import { Range } from './core/range.js';
  4. import { TokenizationRegistry as TokenizationRegistryImpl } from './tokenizationRegistry.js';
  5. export class Token {
  6. constructor(offset, type, language) {
  7. this.offset = offset;
  8. this.type = type;
  9. this.language = language;
  10. this._tokenBrand = undefined;
  11. }
  12. toString() {
  13. return '(' + this.offset + ', ' + this.type + ')';
  14. }
  15. }
  16. /**
  17. * @internal
  18. */
  19. export class TokenizationResult {
  20. constructor(tokens, endState) {
  21. this.tokens = tokens;
  22. this.endState = endState;
  23. this._tokenizationResultBrand = undefined;
  24. }
  25. }
  26. /**
  27. * @internal
  28. */
  29. export class EncodedTokenizationResult {
  30. constructor(
  31. /**
  32. * The tokens in binary format. Each token occupies two array indices. For token i:
  33. * - at offset 2*i => startIndex
  34. * - at offset 2*i + 1 => metadata
  35. *
  36. */
  37. tokens, endState) {
  38. this.tokens = tokens;
  39. this.endState = endState;
  40. this._encodedTokenizationResultBrand = undefined;
  41. }
  42. }
  43. /**
  44. * @internal
  45. */
  46. export var CompletionItemKinds;
  47. (function (CompletionItemKinds) {
  48. const byKind = new Map();
  49. byKind.set(0 /* CompletionItemKind.Method */, Codicon.symbolMethod);
  50. byKind.set(1 /* CompletionItemKind.Function */, Codicon.symbolFunction);
  51. byKind.set(2 /* CompletionItemKind.Constructor */, Codicon.symbolConstructor);
  52. byKind.set(3 /* CompletionItemKind.Field */, Codicon.symbolField);
  53. byKind.set(4 /* CompletionItemKind.Variable */, Codicon.symbolVariable);
  54. byKind.set(5 /* CompletionItemKind.Class */, Codicon.symbolClass);
  55. byKind.set(6 /* CompletionItemKind.Struct */, Codicon.symbolStruct);
  56. byKind.set(7 /* CompletionItemKind.Interface */, Codicon.symbolInterface);
  57. byKind.set(8 /* CompletionItemKind.Module */, Codicon.symbolModule);
  58. byKind.set(9 /* CompletionItemKind.Property */, Codicon.symbolProperty);
  59. byKind.set(10 /* CompletionItemKind.Event */, Codicon.symbolEvent);
  60. byKind.set(11 /* CompletionItemKind.Operator */, Codicon.symbolOperator);
  61. byKind.set(12 /* CompletionItemKind.Unit */, Codicon.symbolUnit);
  62. byKind.set(13 /* CompletionItemKind.Value */, Codicon.symbolValue);
  63. byKind.set(15 /* CompletionItemKind.Enum */, Codicon.symbolEnum);
  64. byKind.set(14 /* CompletionItemKind.Constant */, Codicon.symbolConstant);
  65. byKind.set(15 /* CompletionItemKind.Enum */, Codicon.symbolEnum);
  66. byKind.set(16 /* CompletionItemKind.EnumMember */, Codicon.symbolEnumMember);
  67. byKind.set(17 /* CompletionItemKind.Keyword */, Codicon.symbolKeyword);
  68. byKind.set(27 /* CompletionItemKind.Snippet */, Codicon.symbolSnippet);
  69. byKind.set(18 /* CompletionItemKind.Text */, Codicon.symbolText);
  70. byKind.set(19 /* CompletionItemKind.Color */, Codicon.symbolColor);
  71. byKind.set(20 /* CompletionItemKind.File */, Codicon.symbolFile);
  72. byKind.set(21 /* CompletionItemKind.Reference */, Codicon.symbolReference);
  73. byKind.set(22 /* CompletionItemKind.Customcolor */, Codicon.symbolCustomColor);
  74. byKind.set(23 /* CompletionItemKind.Folder */, Codicon.symbolFolder);
  75. byKind.set(24 /* CompletionItemKind.TypeParameter */, Codicon.symbolTypeParameter);
  76. byKind.set(25 /* CompletionItemKind.User */, Codicon.account);
  77. byKind.set(26 /* CompletionItemKind.Issue */, Codicon.issues);
  78. /**
  79. * @internal
  80. */
  81. function toIcon(kind) {
  82. let codicon = byKind.get(kind);
  83. if (!codicon) {
  84. console.info('No codicon found for CompletionItemKind ' + kind);
  85. codicon = Codicon.symbolProperty;
  86. }
  87. return codicon;
  88. }
  89. CompletionItemKinds.toIcon = toIcon;
  90. const data = new Map();
  91. data.set('method', 0 /* CompletionItemKind.Method */);
  92. data.set('function', 1 /* CompletionItemKind.Function */);
  93. data.set('constructor', 2 /* CompletionItemKind.Constructor */);
  94. data.set('field', 3 /* CompletionItemKind.Field */);
  95. data.set('variable', 4 /* CompletionItemKind.Variable */);
  96. data.set('class', 5 /* CompletionItemKind.Class */);
  97. data.set('struct', 6 /* CompletionItemKind.Struct */);
  98. data.set('interface', 7 /* CompletionItemKind.Interface */);
  99. data.set('module', 8 /* CompletionItemKind.Module */);
  100. data.set('property', 9 /* CompletionItemKind.Property */);
  101. data.set('event', 10 /* CompletionItemKind.Event */);
  102. data.set('operator', 11 /* CompletionItemKind.Operator */);
  103. data.set('unit', 12 /* CompletionItemKind.Unit */);
  104. data.set('value', 13 /* CompletionItemKind.Value */);
  105. data.set('constant', 14 /* CompletionItemKind.Constant */);
  106. data.set('enum', 15 /* CompletionItemKind.Enum */);
  107. data.set('enum-member', 16 /* CompletionItemKind.EnumMember */);
  108. data.set('enumMember', 16 /* CompletionItemKind.EnumMember */);
  109. data.set('keyword', 17 /* CompletionItemKind.Keyword */);
  110. data.set('snippet', 27 /* CompletionItemKind.Snippet */);
  111. data.set('text', 18 /* CompletionItemKind.Text */);
  112. data.set('color', 19 /* CompletionItemKind.Color */);
  113. data.set('file', 20 /* CompletionItemKind.File */);
  114. data.set('reference', 21 /* CompletionItemKind.Reference */);
  115. data.set('customcolor', 22 /* CompletionItemKind.Customcolor */);
  116. data.set('folder', 23 /* CompletionItemKind.Folder */);
  117. data.set('type-parameter', 24 /* CompletionItemKind.TypeParameter */);
  118. data.set('typeParameter', 24 /* CompletionItemKind.TypeParameter */);
  119. data.set('account', 25 /* CompletionItemKind.User */);
  120. data.set('issue', 26 /* CompletionItemKind.Issue */);
  121. /**
  122. * @internal
  123. */
  124. function fromString(value, strict) {
  125. let res = data.get(value);
  126. if (typeof res === 'undefined' && !strict) {
  127. res = 9 /* CompletionItemKind.Property */;
  128. }
  129. return res;
  130. }
  131. CompletionItemKinds.fromString = fromString;
  132. })(CompletionItemKinds || (CompletionItemKinds = {}));
  133. /**
  134. * How an {@link InlineCompletionsProvider inline completion provider} was triggered.
  135. */
  136. export var InlineCompletionTriggerKind;
  137. (function (InlineCompletionTriggerKind) {
  138. /**
  139. * Completion was triggered automatically while editing.
  140. * It is sufficient to return a single completion item in this case.
  141. */
  142. InlineCompletionTriggerKind[InlineCompletionTriggerKind["Automatic"] = 0] = "Automatic";
  143. /**
  144. * Completion was triggered explicitly by a user gesture.
  145. * Return multiple completion items to enable cycling through them.
  146. */
  147. InlineCompletionTriggerKind[InlineCompletionTriggerKind["Explicit"] = 1] = "Explicit";
  148. })(InlineCompletionTriggerKind || (InlineCompletionTriggerKind = {}));
  149. export class SelectedSuggestionInfo {
  150. constructor(range, text, completionKind, isSnippetText) {
  151. this.range = range;
  152. this.text = text;
  153. this.completionKind = completionKind;
  154. this.isSnippetText = isSnippetText;
  155. }
  156. equals(other) {
  157. return Range.lift(this.range).equalsRange(other.range)
  158. && this.text === other.text
  159. && this.completionKind === other.completionKind
  160. && this.isSnippetText === other.isSnippetText;
  161. }
  162. }
  163. export var SignatureHelpTriggerKind;
  164. (function (SignatureHelpTriggerKind) {
  165. SignatureHelpTriggerKind[SignatureHelpTriggerKind["Invoke"] = 1] = "Invoke";
  166. SignatureHelpTriggerKind[SignatureHelpTriggerKind["TriggerCharacter"] = 2] = "TriggerCharacter";
  167. SignatureHelpTriggerKind[SignatureHelpTriggerKind["ContentChange"] = 3] = "ContentChange";
  168. })(SignatureHelpTriggerKind || (SignatureHelpTriggerKind = {}));
  169. /**
  170. * A document highlight kind.
  171. */
  172. export var DocumentHighlightKind;
  173. (function (DocumentHighlightKind) {
  174. /**
  175. * A textual occurrence.
  176. */
  177. DocumentHighlightKind[DocumentHighlightKind["Text"] = 0] = "Text";
  178. /**
  179. * Read-access of a symbol, like reading a variable.
  180. */
  181. DocumentHighlightKind[DocumentHighlightKind["Read"] = 1] = "Read";
  182. /**
  183. * Write-access of a symbol, like writing to a variable.
  184. */
  185. DocumentHighlightKind[DocumentHighlightKind["Write"] = 2] = "Write";
  186. })(DocumentHighlightKind || (DocumentHighlightKind = {}));
  187. /**
  188. * @internal
  189. */
  190. export function isLocationLink(thing) {
  191. return thing
  192. && URI.isUri(thing.uri)
  193. && Range.isIRange(thing.range)
  194. && (Range.isIRange(thing.originSelectionRange) || Range.isIRange(thing.targetSelectionRange));
  195. }
  196. /**
  197. * @internal
  198. */
  199. export var SymbolKinds;
  200. (function (SymbolKinds) {
  201. const byKind = new Map();
  202. byKind.set(0 /* SymbolKind.File */, Codicon.symbolFile);
  203. byKind.set(1 /* SymbolKind.Module */, Codicon.symbolModule);
  204. byKind.set(2 /* SymbolKind.Namespace */, Codicon.symbolNamespace);
  205. byKind.set(3 /* SymbolKind.Package */, Codicon.symbolPackage);
  206. byKind.set(4 /* SymbolKind.Class */, Codicon.symbolClass);
  207. byKind.set(5 /* SymbolKind.Method */, Codicon.symbolMethod);
  208. byKind.set(6 /* SymbolKind.Property */, Codicon.symbolProperty);
  209. byKind.set(7 /* SymbolKind.Field */, Codicon.symbolField);
  210. byKind.set(8 /* SymbolKind.Constructor */, Codicon.symbolConstructor);
  211. byKind.set(9 /* SymbolKind.Enum */, Codicon.symbolEnum);
  212. byKind.set(10 /* SymbolKind.Interface */, Codicon.symbolInterface);
  213. byKind.set(11 /* SymbolKind.Function */, Codicon.symbolFunction);
  214. byKind.set(12 /* SymbolKind.Variable */, Codicon.symbolVariable);
  215. byKind.set(13 /* SymbolKind.Constant */, Codicon.symbolConstant);
  216. byKind.set(14 /* SymbolKind.String */, Codicon.symbolString);
  217. byKind.set(15 /* SymbolKind.Number */, Codicon.symbolNumber);
  218. byKind.set(16 /* SymbolKind.Boolean */, Codicon.symbolBoolean);
  219. byKind.set(17 /* SymbolKind.Array */, Codicon.symbolArray);
  220. byKind.set(18 /* SymbolKind.Object */, Codicon.symbolObject);
  221. byKind.set(19 /* SymbolKind.Key */, Codicon.symbolKey);
  222. byKind.set(20 /* SymbolKind.Null */, Codicon.symbolNull);
  223. byKind.set(21 /* SymbolKind.EnumMember */, Codicon.symbolEnumMember);
  224. byKind.set(22 /* SymbolKind.Struct */, Codicon.symbolStruct);
  225. byKind.set(23 /* SymbolKind.Event */, Codicon.symbolEvent);
  226. byKind.set(24 /* SymbolKind.Operator */, Codicon.symbolOperator);
  227. byKind.set(25 /* SymbolKind.TypeParameter */, Codicon.symbolTypeParameter);
  228. /**
  229. * @internal
  230. */
  231. function toIcon(kind) {
  232. let icon = byKind.get(kind);
  233. if (!icon) {
  234. console.info('No codicon found for SymbolKind ' + kind);
  235. icon = Codicon.symbolProperty;
  236. }
  237. return icon;
  238. }
  239. SymbolKinds.toIcon = toIcon;
  240. })(SymbolKinds || (SymbolKinds = {}));
  241. export class FoldingRangeKind {
  242. /**
  243. * Returns a {@link FoldingRangeKind} for the given value.
  244. *
  245. * @param value of the kind.
  246. */
  247. static fromValue(value) {
  248. switch (value) {
  249. case 'comment': return FoldingRangeKind.Comment;
  250. case 'imports': return FoldingRangeKind.Imports;
  251. case 'region': return FoldingRangeKind.Region;
  252. }
  253. return new FoldingRangeKind(value);
  254. }
  255. /**
  256. * Creates a new {@link FoldingRangeKind}.
  257. *
  258. * @param value of the kind.
  259. */
  260. constructor(value) {
  261. this.value = value;
  262. }
  263. }
  264. /**
  265. * Kind for folding range representing a comment. The value of the kind is 'comment'.
  266. */
  267. FoldingRangeKind.Comment = new FoldingRangeKind('comment');
  268. /**
  269. * Kind for folding range representing a import. The value of the kind is 'imports'.
  270. */
  271. FoldingRangeKind.Imports = new FoldingRangeKind('imports');
  272. /**
  273. * Kind for folding range representing regions (for example marked by `#region`, `#endregion`).
  274. * The value of the kind is 'region'.
  275. */
  276. FoldingRangeKind.Region = new FoldingRangeKind('region');
  277. /**
  278. * @internal
  279. */
  280. export var Command;
  281. (function (Command) {
  282. /**
  283. * @internal
  284. */
  285. function is(obj) {
  286. if (!obj || typeof obj !== 'object') {
  287. return false;
  288. }
  289. return typeof obj.id === 'string' &&
  290. typeof obj.title === 'string';
  291. }
  292. Command.is = is;
  293. })(Command || (Command = {}));
  294. export var InlayHintKind;
  295. (function (InlayHintKind) {
  296. InlayHintKind[InlayHintKind["Type"] = 1] = "Type";
  297. InlayHintKind[InlayHintKind["Parameter"] = 2] = "Parameter";
  298. })(InlayHintKind || (InlayHintKind = {}));
  299. /**
  300. * @internal
  301. */
  302. export class LazyTokenizationSupport {
  303. constructor(createSupport) {
  304. this.createSupport = createSupport;
  305. this._tokenizationSupport = null;
  306. }
  307. dispose() {
  308. if (this._tokenizationSupport) {
  309. this._tokenizationSupport.then((support) => {
  310. if (support) {
  311. support.dispose();
  312. }
  313. });
  314. }
  315. }
  316. get tokenizationSupport() {
  317. if (!this._tokenizationSupport) {
  318. this._tokenizationSupport = this.createSupport();
  319. }
  320. return this._tokenizationSupport;
  321. }
  322. }
  323. /**
  324. * @internal
  325. */
  326. export const TokenizationRegistry = new TokenizationRegistryImpl();