@theia/plugin 1.53.0-next.4 → 1.53.0-next.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/README.md +766 -766
  2. package/package.json +3 -3
  3. package/src/package.spec.ts +28 -28
  4. package/src/theia-extra.d.ts +410 -410
  5. package/src/theia.d.ts +18078 -17684
  6. package/src/theia.proposed.canonicalUriProvider.d.ts +64 -64
  7. package/src/theia.proposed.customEditorMove.d.ts +41 -41
  8. package/src/theia.proposed.debugVisualization.d.ts +189 -189
  9. package/src/theia.proposed.diffCommand.d.ts +55 -55
  10. package/src/theia.proposed.documentPaste.d.ts +316 -316
  11. package/src/theia.proposed.editSessionIdentityProvider.d.ts +89 -89
  12. package/src/theia.proposed.extensionsAny.d.ts +57 -57
  13. package/src/theia.proposed.externalUriOpener.d.ts +158 -158
  14. package/src/theia.proposed.findTextInFiles.d.ts +178 -178
  15. package/src/theia.proposed.fsChunks.d.ts +32 -32
  16. package/src/theia.proposed.mappedEditsProvider.d.ts +59 -59
  17. package/src/theia.proposed.multiDocumentHighlightProvider.ts +82 -82
  18. package/src/theia.proposed.notebookCellExecutionState.d.ts +68 -68
  19. package/src/theia.proposed.notebookKernelSource.d.ts +62 -62
  20. package/src/theia.proposed.notebookMessaging.d.ts +84 -84
  21. package/src/theia.proposed.portsAttributes.d.ts +115 -115
  22. package/src/theia.proposed.profileContentHandlers.d.ts +35 -35
  23. package/src/theia.proposed.resolvers.d.ts +44 -44
  24. package/src/theia.proposed.scmValidation.d.ts +70 -70
  25. package/src/theia.proposed.shareProvider.d.ts +92 -92
  26. package/src/theia.proposed.terminalQuickFixProvider.d.ts +103 -103
  27. package/src/theia.proposed.textSearchProvider.d.ts +145 -145
  28. package/src/theia.proposed.timeline.d.ts +177 -177
package/README.md CHANGED
@@ -1,766 +1,766 @@
1
- <div align='center'>
2
-
3
- <br />
4
-
5
- <img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
6
-
7
- <h2>ECLIPSE THEIA - PLUGIN EXTENSION</h2>
8
-
9
- <hr />
10
-
11
- </div>
12
-
13
- ## Description
14
-
15
- The `@theia/plugin` extension contributes the plugin API to the application.
16
-
17
- ### Plugin API
18
-
19
- Namespace for dealing with installed plug-ins. Plug-ins are represented
20
- by a Plugin-interface which enables reflection on them.
21
- Plug-in writers can provide APIs to other plug-ins by returning their API public
22
- surface from the `start`-call.
23
-
24
- For example some plugin exports it's API:
25
-
26
- ```javascript
27
- export function start() {
28
- let api = {
29
- sum(a, b) {
30
- return a + b;
31
- },
32
- mul(a, b) {
33
- return a * b;
34
- }
35
- };
36
- // 'export' public api-surface
37
- return api;
38
- }
39
- ```
40
-
41
- Another plugin can use that API:
42
-
43
- ```javascript
44
- let mathExt = theia.plugins.getPlugin('genius.math');
45
- let importedApi = mathExt.exports;
46
- console.log(importedApi.mul(42, 1));
47
- ```
48
-
49
- Also plugin API allows access to plugin `package.json` content.
50
-
51
- Example:
52
-
53
- ```javascript
54
- const fooPlugin = plugins.getPlugin('publisher.plugin_name');
55
- const fooPluginPackageJson = fooPlugin.packageJSON;
56
- console.log(fooPluginPackageJson.someField);
57
- ```
58
-
59
- ### Command API
60
-
61
- A command is a unique identifier of a function which
62
- can be executed by a user via a keyboard shortcut, a
63
- menu action or directly.
64
-
65
- Commands can be added using the [registerCommand](#commands.registerCommand) and
66
- [registerTextEditorCommand](#commands.registerTextEditorCommand) functions.
67
- Registration can be split in two step: first register command without handler, second register handler by command id.
68
-
69
- Any contributed command are available to any plugin, command can be invoked by [executeCommand](#commands.executeCommand) function.
70
-
71
- Simple example that register command:
72
-
73
- ```typescript
74
- theia.commands.registerCommand({id:'say.hello.command'}, ()=>{
75
- console.log("Hello World!");
76
- });
77
- ```
78
-
79
- Simple example that invoke command:
80
-
81
- ```typescript
82
- theia.commands.executeCommand('core.about');
83
- ```
84
-
85
- ### Window
86
-
87
- Common namespace for dealing with window and editor, showing messages and user input.
88
-
89
- #### Quick Pick
90
-
91
- Function to ask user select some value from the list.
92
-
93
- Example of using:
94
-
95
- ```typescript
96
- //configure quick pick options
97
- const option: theia.QuickPickOptions = {
98
- machOnDescription: true,
99
- machOnDetail: true,
100
- canPickMany: false,
101
- placeHolder: "Select string:",
102
- onDidSelectItem: (item) => console.log(`Item ${item} is selected`)
103
- };
104
- // call Theia api to show quick pick
105
- theia.window.showQuickPick(["foo", "bar", "foobar"], option).then((val: string[] | undefined) => {
106
- console.log(`Quick Pick Selected: ${val}`);
107
- });
108
- ```
109
-
110
- #### Input Box
111
-
112
- Function to ask user for input.
113
-
114
- Example of using:
115
-
116
- ```typescript
117
- const option: theia.InputBoxOptions = {
118
- prompt:"Hello from Plugin",
119
- placeHolder:"Type text there",
120
- ignoreFocusOut: false,
121
- password: false,
122
- value:"Default value"
123
- };
124
- theia.window.showInputBox(option).then((s: string | undefined) => {
125
- console.log(typeof s !== 'undefined'? s : "Input was canceled");
126
- });
127
- ```
128
-
129
- #### Notification API
130
-
131
- A notification shows an information message to users.
132
- Optionally provide an array of items which will be presented as clickable buttons.
133
-
134
- Notifications can be shown using the [showInformationMessage](#window.showInformationMessage),
135
- [showWarningMessage](#window.showWarningMessage) and [showErrorMessage](#window.showErrorMessage) functions.
136
-
137
- Simple example that show an information message:
138
-
139
- ```typescript
140
- theia.window.showInformationMessage('Information message');
141
- ```
142
-
143
- Simple example that show an information message with buttons:
144
-
145
- ```typescript
146
- theia.window.showInformationMessage('Information message', 'Btn1', 'Btn2').then(result => {
147
- console.log("Click button", result);
148
- });
149
- ```
150
-
151
- #### Window State API
152
-
153
- It is possible to track state of the IDE window inside a plugin. Window state is defined as:
154
-
155
- ```typescript
156
- interface WindowState {
157
- readonly focused: boolean;
158
- }
159
- ```
160
-
161
- To read a state on demand one can use readonly variable:
162
-
163
- ```typescript
164
- theia.window.state
165
- ```
166
-
167
- To track window activity subscribe on `onDidChangeWindowState` event:
168
-
169
- ```typescript
170
- const disposable = theia.window.onDidChangeWindowState((windowState: theia.WindowState) => {
171
- console.log('Window focus changed: ', windowState.focused);
172
- });
173
- ```
174
-
175
- #### Status Bar API
176
-
177
- A status bar shows a message to users and supports icon substitution.
178
-
179
- Status bar message can be shown using the [setStatusBarMessage](#window.setStatusBarMessage) and
180
- [createStatusBarItem](#window.createStatusBarItem) functions.
181
-
182
- Simple example that show a status bar message:
183
-
184
- ```typescript
185
- theia.window.setStatusBarMessage('test status bar item');
186
- ```
187
-
188
- Simple example that show a status bar message with statusBarItem:
189
-
190
- ```typescript
191
- const item = theia.window.createStatusBarItem(theia.StatusBarAlignment.Right, 99);
192
- item.text = 'test status bar item';
193
- item.show();
194
- ```
195
- #### Output channel API
196
-
197
- It is possible to show a container for readonly textual information:
198
-
199
- ```typescript
200
- const channel = theia.window.createOutputChannel('test channel');
201
- channel.appendLine('test output');
202
-
203
- ```
204
-
205
- #### Environment API
206
-
207
- Environment API allows reading of environment variables and query parameters of the IDE.
208
-
209
- To get an environment variable by name one can use:
210
-
211
- ```typescript
212
- theia.env.getEnvVariable('NAME_OF_ENV_VARIABLE').then(value => {
213
- // process the value here
214
- }
215
- ```
216
-
217
- In case if environment variable doesn't exist `undefined` will be returned.
218
-
219
- Also this part of API exposes all query parameters (already URI decoded) with which IDE page is loaded. One can get a query parameter by name:
220
-
221
- ```typescript
222
- theia.env.getQueryParameter('NAME_OF_QUERY_PARAMETER');
223
- ```
224
-
225
- In case if query parameter doesn't exist `undefined` will be returned.
226
-
227
- Or it is possible to get a map of all query parameters:
228
-
229
- ```typescript
230
- theia.env.getQueryParameters();
231
- ```
232
-
233
- Note, that it is possible to have an array of values for single name, because it could be specified more than one time (for example `localhost:3000?foo=bar&foo=baz`).
234
-
235
- ### Terminal
236
-
237
- Function to create new terminal with specific arguments:
238
-
239
- ```typescript
240
- const terminal = theia.window.createTerminal("Bash terminal", "/bin/bash", ["-l"]);
241
- ```
242
-
243
- Where are:
244
- - first argument - terminal's name.
245
- - second argument - path to the executable shell.
246
- - third argument - arguments to configure executable shell.
247
-
248
- You can create terminal with specific options:
249
-
250
- ```typescript
251
- const options: theia.TerminalOptions {
252
- name: "Bash terminal",
253
- shellPath: "/bin/bash";
254
- shellArgs: ["-l"];
255
- cwd: "/projects";
256
- env: { "TERM": "screen" };
257
- };
258
- ```
259
-
260
- Where are:
261
- - "shellPath" - path to the executable shell, for example "/bin/bash", "bash", "sh" or so on.
262
- - "shellArgs" - shell command arguments, for example without login: "-l". If you defined shell command "/bin/bash" and set up shell arguments "-l" than will be created terminal process with command "/bin/bash -l". And client side will connect to stdin/stdout of this process to interaction with user.
263
- - "cwd" - current working directory;
264
- - "env"- environment variables for terminal process, for example TERM - identifier terminal window capabilities.
265
-
266
- Function to create new terminal with defined theia.TerminalOptions described above:
267
-
268
- ```typescript
269
- const terminal = theia.window.createTerminal(options);
270
- ```
271
-
272
- Created terminal is not attached to the panel. To apply created terminal to the panel use method "show":
273
-
274
- ```typescript
275
- terminal.show();
276
- ```
277
-
278
- To hide panel with created terminal use method "hide";
279
-
280
- ```typescript
281
- terminal.hide();
282
- ```
283
-
284
- Send text to the terminal:
285
-
286
- ```typescript
287
- terminal.sendText("Hello, Theia!", false);
288
- ```
289
-
290
- Where are:
291
- - first argument - text content.
292
- - second argument - in case true, terminal will apply new line after the text, otherwise will send only the text.
293
-
294
- Destroy terminal:
295
-
296
- ```typescript
297
- terminal.dispose();
298
- ```
299
-
300
- Subscribe to close terminal event:
301
-
302
- ```typescript
303
- theia.window.onDidCloseTerminal((term) => {
304
- console.log("Terminal closed.");
305
- });
306
- ```
307
-
308
- Detect destroying terminal by Id:
309
-
310
- ```typescript
311
- terminal.processId.then(id => {
312
- theia.window.onDidCloseTerminal(async (term) => {
313
- const currentId = await term.processId;
314
- if (currentId === id) {
315
- console.log("Terminal closed.", id);
316
- }
317
- }, id);
318
- });
319
- ```
320
-
321
- #### Preference API
322
-
323
- Preference API allows one to read or update User's and Workspace's preferences.
324
-
325
- To get preferences:
326
- ```typescript
327
- // editor preferences
328
- const preferences = theia.workspace.getConfiguration('editor');
329
-
330
- // retrieving values
331
- const fontSize = preferences.get('tabSize');
332
- ```
333
-
334
- To change preference:
335
- ```typescript
336
- preferences.onDidChangeConfiguration(e => {
337
- if (e.affectsConfiguration('editor.tabSize')) {
338
- console.log('Property "editor.tabSize" is changed');
339
- }
340
- });
341
-
342
- preferences.update('tabSize', 2);
343
- ```
344
-
345
- ### Languages API
346
-
347
- #### Diagnostics
348
-
349
- To get all existing diagnostics one should use `getDiagnostics` call. If diagnostics are needed for specific URI they could be obtain with following call:
350
-
351
- ```typescript
352
- const diagnostics = theia.languages.getDiagnostics(uriToResource)
353
- ```
354
-
355
- To get all diagnostics use:
356
- ```typescript
357
- const diagnostics = theia.languages.getDiagnostics()
358
- ```
359
-
360
- For example, following code will get diagnostics for current file in the editor (supposed one is already opened):
361
-
362
- ```typescript
363
- const diagnosticsForCurrentFile = theia.languages.getDiagnostics(theia.window.activeTextEditor.document.uri)
364
- ```
365
-
366
- If no diagnostics found empty array will be returned.
367
-
368
- Note, that returned array from `getDiagnostics` call are readonly.
369
-
370
- To tracks changes in diagnostics `onDidChangeDiagnostics` event should be used. Within event handler list of uris with changed diagnostics is available. Example:
371
-
372
- ```typescript
373
- disposables.push(
374
- theia.languages.onDidChangeDiagnostics((event: theia.DiagnosticChangeEvent) => {
375
- // handler code here
376
- }
377
- );
378
- ```
379
-
380
- Also it is possible to add own diagnostics. To do this, one should create diagnostics collection first:
381
-
382
- ```typescript
383
- const diagnosticsCollection = theia.languages.createDiagnosticCollection(collectionName);
384
- ```
385
-
386
- Collection name can be omitted. In such case the name will be auto-generated.
387
-
388
- When collection is created, one could operate with diagnostics. The collection object exposes all needed methods: `get`, `set`, `has`, `delete`, `clear`, `forEach` and `dispose`.
389
-
390
- `get`, `has` and `delete` performs corresponding operation by given resource uri. `clear` removes all diagnostics for all uris in the collection.
391
-
392
- Behavior of `set` is more complicated. To replace all diagnostics for given uri the following call should be used:
393
-
394
- ```typescript
395
- diagnosticsCollection.set(uri, newDiagnostics)
396
- ```
397
-
398
- if `undefined` is passed instead of diagnostics array the call will clear diagnostics for given uri in this collection (the same as `delete`).
399
- Also it is possible to set all diagnostics at once (it will replace existed ones). To do this, array of tuples in format `[uri, diagnostics]` should be passed as argument for `set`:
400
-
401
- ```typescript
402
- const changes: [Uri, Diagnostic[] | undefined][] = [];
403
-
404
- changes.push([uri1, diagnostics1]);
405
- changes.push([uri2, diagnostics2]);
406
- changes.push([uri3, undefined]);
407
- changes.push([uri1, diagnostics4]); // uri1 again
408
-
409
- diagnosticsCollection.set(changes);
410
- ```
411
-
412
- If the same uri is used a few times, corresponding diagnostics will be merged. In case of `undefined` all previous, but not following, diagnostics will be cleared. If `undefined` is given instead of tuples array the whole collection will be cleared.
413
-
414
- To iterate over all diagnostics within the collection `forEach` method could be used:
415
-
416
- ```typescript
417
- diagnosticsCollection.forEach((uri, diagnostics) => {
418
- // code here
419
- }
420
- ```
421
-
422
- `dispose` method should be used when the collection is not needed any more. In case of attempt to do an operation after disposing an error will be thrown.
423
-
424
- #### Signature help
425
-
426
- To provide signature help form plugin it is required to register provider. For registration 3 items are needed:
427
- - Documents selector to describe for which files it should be applied
428
- - Handler which will do the work
429
- - Trigger characters after typing of which the handler should be invoked. Often symbols `(` and `,` are used.
430
-
431
- Example of signature help provider registration:
432
-
433
- ```typescript
434
- const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
435
- const handler = { provideSignatureHelp: signatureHelpHandler };
436
- const triggerChars = '(,';
437
-
438
- const disposable = theia.languages.registerSignatureHelpProvider(documentsSelector, handler, ...triggerChars);
439
-
440
- ...
441
-
442
- function signatureHelpHandler(document: theia.TextDocument, position: theia.Position): theia.ProviderResult<theia.SignatureHelp> {
443
- // code here
444
- }
445
- ```
446
-
447
- Example of signature information:
448
-
449
- ```typescript
450
- {
451
- activeSignature: 0,
452
- activeParameter: 0,
453
- signatures: [
454
- {
455
- label: 'functionName(param1: number, param2: string, param3: boolean)',
456
- documentation: new theia.MarkdownString('What **this** function does'),
457
- parameters: [
458
- {
459
- label: 'param1: number',
460
- documentation: new theia.MarkdownString('Some number. Should not be `undefined`')
461
- },
462
- {
463
- label: 'param2: string',
464
- documentation: 'Some string'
465
- },
466
- {
467
- label: 'param3: boolean',
468
- documentation: 'Some flag'
469
- }
470
- ]
471
- }
472
- ]
473
- }
474
- ```
475
-
476
- Note, that:
477
- - `activeSignature` and `activeParameter` are zero based.
478
- - label is usually full method signature.
479
- - for documentation fields markdown partially supported (Tags aren't supported).
480
- - label of a parameter should be substring of the signature label. In such case the substring will be highlighted in main label when parameter is active. Otherwise has no effect.
481
-
482
- When signature help popup is shown then the handler will be invoked on each parameter edit or even cursor moving inside signature. If you have large objects it would be wise to cache them of at least reuse some parts.
483
-
484
- To hide your popup just return `undefined` from provider.
485
-
486
- In case if a few providers are registered the chain will be executed until one of the providers returns result. Next providers will be ignored for the call.
487
-
488
- #### Hover Message
489
-
490
- To contribute a hover it is only needed to provide a function that can be called with a `TextDocument` and a `Position` returning hover info. Registration is done using a document selector which either a language id ('typescript', 'javascript' etc.) or a more complex filter like `{scheme: 'file', language: 'typescript'}`.
491
-
492
- For example,
493
-
494
- ```typescript
495
- theia.languages.registerHoverProvider('typescript', {
496
- provideHover(doc: theia.TextDocument, position: theia.Position, token: theia.CancellationToken) {
497
- return new theia.Hover('Hover for all **typescript** files.');
498
- }
499
- });
500
- ```
501
-
502
- will show the hover message for all `typescript` files.
503
-
504
- The code below puts word under cursor into hover message:
505
-
506
- ```typescript
507
- theia.languages.registerHoverProvider({scheme: 'file'}, {
508
- provideHover(doc: theia.TextDocument, position: theia.Position, token: theia.CancellationToken) {
509
- const range = doc.getWordRangeAtPosition(position);
510
- const text = doc.getText(range);
511
- return new theia.Hover(text);
512
- }
513
- });
514
- ```
515
-
516
- #### Document Highlight provider
517
-
518
- It is possible to provide document highlight source for a symbol from within plugin.
519
- To do this one should register corresponding provider. For example:
520
-
521
- ```typescript
522
- const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
523
- const handler: theia.DocumentHighlightProvider = { provideDocumentHighlights: provideDocumentHighlightsHandler };
524
-
525
- const disposable = theia.languages.registerDocumentHighlightProvider(documentsSelector, handler);
526
-
527
- ...
528
-
529
- function provideDocumentHighlightsHandler(document: theia.TextDocument, position: theia.Position): theia.ProviderResult<theia.DocumentHighlight[]> {
530
- // code here
531
- }
532
- ```
533
-
534
- It is possible to return a few sources, but for most cases only one is enough. Return `undefined` to provide nothing.
535
-
536
- #### Definition provider
537
-
538
- It is possible to provide definition source for a symbol from within plugin.
539
- To do this one should register corresponding provider. For example:
540
-
541
- ```typescript
542
- const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
543
- const handler: theia.DefinitionProvider = { provideDefinition: provideDefinitionHandler };
544
-
545
- const disposable = theia.languages.registerDefinitionProvider(documentsSelector, handler);
546
-
547
- ...
548
-
549
- function provideDefinitionHandler(document: theia.TextDocument, position: theia.Position): theia.ProviderResult<theia.Definition | theia.DefinitionLink[]> {
550
- // code here
551
- }
552
- ```
553
-
554
- The handler will be invoked each time when a user executes `Go To Definition` command.
555
- It is possible to return a few sources, but for most cases only one is enough. Return `undefined` to provide nothing.
556
-
557
- #### Declaration provider
558
-
559
- It is possible to provide a declaration for a symbol from within a plugin.
560
- To do this one may register corresponding provider. For example:
561
-
562
- ```typescript
563
- const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
564
- const handler: theia.DeclarationProvider = { provideDeclaration: provideDeclarationHandler };
565
-
566
- const disposable = theia.languages.registerDeclarationProvider(documentsSelector, handler);
567
-
568
- ...
569
-
570
- function provideDeclarationHandler(document: theia.TextDocument, position: theia.Position): theia.ProviderResult<theia.Definition | theia.DefinitionLink[]> {
571
- // code here
572
- }
573
- ```
574
-
575
- The handler will be invoked each time when a user executes `Go To Declaration` command.
576
- It is possible to return a few sources, but for most cases only one is enough. Return `undefined` to provide nothing.
577
-
578
- #### Implementation provider
579
-
580
- It is possible to provide implementation source for a symbol from within plugin.
581
- To do this one should register corresponding provider. For example:
582
-
583
- ```typescript
584
- const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
585
- const handler: theia.ImplementationProvider = { provideImplementation: provideImplementationHandler };
586
-
587
- const disposable = theia.languages.registerImplementationProvider(documentsSelector, handler);
588
-
589
- ...
590
-
591
- function provideImplementationHandler(document: theia.TextDocument, position: theia.Position): theia.ProviderResult<theia.Definition | theia.DefinitionLink[]> {
592
- // code here
593
- }
594
- ```
595
-
596
- It is possible to return a few sources, but for most cases only one is enough. Return `undefined` to provide nothing.
597
-
598
- #### Type Definition provider
599
-
600
- It is possible to provide type definition source for a symbol from within plugin.
601
- To do this one should register corresponding provider. For example:
602
-
603
- ```typescript
604
- const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
605
- const handler: theia.TypeDefinitionProvider = { provideTypeDefinition: provideTypeDefinitionHandler };
606
-
607
- const disposable = theia.languages.registerTypeDefinitionProvider(documentsSelector, handler);
608
-
609
- ...
610
-
611
- function provideTypeDefinitionHandler(document: theia.TextDocument, position: theia.Position): theia.ProviderResult<theia.Definition | theia.DefinitionLink[]> {
612
- // code here
613
- }
614
- ```
615
-
616
- The handler will be invoked each time when a user executes `Go To Type Definition` command.
617
- It is possible to return a few sources, but for most cases only one is enough. Return `undefined` to provide nothing.
618
-
619
- #### Reference provider
620
-
621
- It is possible to provide reference sources for a symbol from within plugin.
622
- To do this one should register corresponding provider. For example:
623
-
624
- ```typescript
625
- const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
626
- const handler: theia.ReferenceProvider = { provideReferences: provideReferencesHandler };
627
-
628
- const disposable = theia.languages.registerReferenceProvider(documentsSelector, handler);
629
-
630
- ...
631
-
632
- function provideReferencesHandler(document: theia.TextDocument, position: theia.Position, context: theia.ReferenceContext): theia.ProviderResult<theia.Location[]> {
633
- // code here
634
- }
635
- ```
636
-
637
- The handler will be invoked each time when a user executes `Find All References` command.
638
- It is possible to return a few sources. Return `undefined` to provide nothing.
639
-
640
- #### Document Link Provider
641
-
642
- A document link provider allows to add a custom link detection logic.
643
-
644
- Example of document link provider registration:
645
-
646
- ```typescript
647
- const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
648
- const provider = { provideDocumentLinks: provideLinks };
649
-
650
- const disposable = theia.languages.registerDocumentLinkProvider(documentsSelector, provider);
651
-
652
- ...
653
-
654
- function provideLinks(document: theia.TextDocument): theia.ProviderResult<theia.DocumentLink[]> {
655
- // code here
656
- }
657
- ```
658
-
659
- #### Code Lens Provider
660
-
661
- A code lens provider allows to add a custom lens detection logic.
662
-
663
- Example of code lens provider registration:
664
-
665
- ```typescript
666
- const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
667
- const provider = { provideCodeLenses: provideLenses };
668
-
669
- const disposable = theia.languages.registerCodeLensProvider(documentsSelector, provider);
670
-
671
- ...
672
-
673
- function provideLenses(document: theia.TextDocument): theia.ProviderResult<theia.CodeLens[]> {
674
- // code here
675
- }
676
- ```
677
-
678
- #### Code Symbol Provider
679
-
680
- A document symbol provider allows to add a custom logic for symbols detection.
681
-
682
- Example of code symbol provider registration:
683
-
684
- ```typescript
685
- const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
686
- const provider = { provideDocumentSymbols: provideSymbols };
687
- const metadata = { label: 'providerLabel' }
688
-
689
- const disposable = theia.languages.registerDocumentSymbolProvider(documentsSelector, provider, metadata);
690
-
691
- ...
692
-
693
- function provideSymbols(document: theia.TextDocument): theia.ProviderResult<theia.SymbolInformation[] | theia.DocumentSymbol[]> {
694
- // code here
695
- }
696
- ```
697
-
698
- #### Workspace Symbol Provider
699
-
700
- A workspace symbol provider allows you register symbols for the symbol search feature.
701
-
702
- resolveWorkspaceSymbol is not needed if all SymbolInformation's returned from
703
- provideWorkspaceSymbols have a location. Otherwise resolveWorkspaceSymbol is needed
704
- in order to resolve the location of the SymbolInformation.
705
-
706
- Example of workspace symbol provider registration:
707
-
708
- ```typescript
709
- theia.languages.registerWorkspaceSymbolProvider({
710
- provideWorkspaceSymbols(query: string): theia.SymbolInformation[] {
711
- return [new theia.SymbolInformation('my symbol', 4, new theia.Range(new theia.Position(0, 0), new theia.Position(0, 0)), theia.Uri.parse("some_uri_to_file"))];
712
- }
713
- } as theia.WorkspaceSymbolProvider);
714
- ```
715
-
716
- In this case resolveWorkspaceSymbol is not needed because we have provided the location for every
717
- symbol returned from provideWorkspaceSymbols
718
-
719
- ```typescript
720
- theia.languages.registerWorkspaceSymbolProvider({
721
- provideWorkspaceSymbols(query: string): theia.SymbolInformation[] {
722
- return [new theia.SymbolInformation('my symbol', 4, 'my container name', new theia.Location(theia.Uri.parse("some_uri_to_file"), undefined))];
723
- },
724
- resolveWorkspaceSymbol(symbolInformation: theia.SymbolInformation): theia.SymbolInformation {
725
- symbolInformation.location.range = new theia.Range(new theia.Position(0, 0), new theia.Position(0, 0));
726
- return symbolInformation;
727
- }
728
- } as theia.WorkspaceSymbolProvider);
729
- ```
730
-
731
- resolveWorkspaceSymbol is needed here because we have not provided the location for every
732
- symbol return from provideWorkspaceSymbol
733
-
734
- #### Folding
735
-
736
- A folding range provider allows you to add logic to fold and unfold custom regions of source code.
737
-
738
- Example of folding range provider registration:
739
-
740
- ```typescript
741
- const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
742
- const provider = { provideFoldingRanges: provideRanges };
743
-
744
- const disposable = theia.languages.registerFoldingRangeProvider(documentsSelector, provider);
745
-
746
- ...
747
-
748
- function provideRanges(document: theia.TextDocument): theia.ProviderResult<theia.FoldingRange[]> {
749
- // code here
750
- }
751
- ```
752
-
753
- ## Additional Information
754
-
755
- - [API documentation for `@theia/plugin`](https://eclipse-theia.github.io/theia/docs/next/modules/plugin.html)
756
- - [Theia - GitHub](https://github.com/eclipse-theia/theia)
757
- - [Theia - Website](https://theia-ide.org/)
758
-
759
- ## License
760
-
761
- - [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
762
- - [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
763
-
764
- ## Trademark
765
- "Theia" is a trademark of the Eclipse Foundation
766
- https://www.eclipse.org/theia
1
+ <div align='center'>
2
+
3
+ <br />
4
+
5
+ <img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
6
+
7
+ <h2>ECLIPSE THEIA - PLUGIN EXTENSION</h2>
8
+
9
+ <hr />
10
+
11
+ </div>
12
+
13
+ ## Description
14
+
15
+ The `@theia/plugin` extension contributes the plugin API to the application.
16
+
17
+ ### Plugin API
18
+
19
+ Namespace for dealing with installed plug-ins. Plug-ins are represented
20
+ by a Plugin-interface which enables reflection on them.
21
+ Plug-in writers can provide APIs to other plug-ins by returning their API public
22
+ surface from the `start`-call.
23
+
24
+ For example some plugin exports it's API:
25
+
26
+ ```javascript
27
+ export function start() {
28
+ let api = {
29
+ sum(a, b) {
30
+ return a + b;
31
+ },
32
+ mul(a, b) {
33
+ return a * b;
34
+ }
35
+ };
36
+ // 'export' public api-surface
37
+ return api;
38
+ }
39
+ ```
40
+
41
+ Another plugin can use that API:
42
+
43
+ ```javascript
44
+ let mathExt = theia.plugins.getPlugin('genius.math');
45
+ let importedApi = mathExt.exports;
46
+ console.log(importedApi.mul(42, 1));
47
+ ```
48
+
49
+ Also plugin API allows access to plugin `package.json` content.
50
+
51
+ Example:
52
+
53
+ ```javascript
54
+ const fooPlugin = plugins.getPlugin('publisher.plugin_name');
55
+ const fooPluginPackageJson = fooPlugin.packageJSON;
56
+ console.log(fooPluginPackageJson.someField);
57
+ ```
58
+
59
+ ### Command API
60
+
61
+ A command is a unique identifier of a function which
62
+ can be executed by a user via a keyboard shortcut, a
63
+ menu action or directly.
64
+
65
+ Commands can be added using the [registerCommand](#commands.registerCommand) and
66
+ [registerTextEditorCommand](#commands.registerTextEditorCommand) functions.
67
+ Registration can be split in two step: first register command without handler, second register handler by command id.
68
+
69
+ Any contributed command are available to any plugin, command can be invoked by [executeCommand](#commands.executeCommand) function.
70
+
71
+ Simple example that register command:
72
+
73
+ ```typescript
74
+ theia.commands.registerCommand({id:'say.hello.command'}, ()=>{
75
+ console.log("Hello World!");
76
+ });
77
+ ```
78
+
79
+ Simple example that invoke command:
80
+
81
+ ```typescript
82
+ theia.commands.executeCommand('core.about');
83
+ ```
84
+
85
+ ### Window
86
+
87
+ Common namespace for dealing with window and editor, showing messages and user input.
88
+
89
+ #### Quick Pick
90
+
91
+ Function to ask user select some value from the list.
92
+
93
+ Example of using:
94
+
95
+ ```typescript
96
+ //configure quick pick options
97
+ const option: theia.QuickPickOptions = {
98
+ machOnDescription: true,
99
+ machOnDetail: true,
100
+ canPickMany: false,
101
+ placeHolder: "Select string:",
102
+ onDidSelectItem: (item) => console.log(`Item ${item} is selected`)
103
+ };
104
+ // call Theia api to show quick pick
105
+ theia.window.showQuickPick(["foo", "bar", "foobar"], option).then((val: string[] | undefined) => {
106
+ console.log(`Quick Pick Selected: ${val}`);
107
+ });
108
+ ```
109
+
110
+ #### Input Box
111
+
112
+ Function to ask user for input.
113
+
114
+ Example of using:
115
+
116
+ ```typescript
117
+ const option: theia.InputBoxOptions = {
118
+ prompt:"Hello from Plugin",
119
+ placeHolder:"Type text there",
120
+ ignoreFocusOut: false,
121
+ password: false,
122
+ value:"Default value"
123
+ };
124
+ theia.window.showInputBox(option).then((s: string | undefined) => {
125
+ console.log(typeof s !== 'undefined'? s : "Input was canceled");
126
+ });
127
+ ```
128
+
129
+ #### Notification API
130
+
131
+ A notification shows an information message to users.
132
+ Optionally provide an array of items which will be presented as clickable buttons.
133
+
134
+ Notifications can be shown using the [showInformationMessage](#window.showInformationMessage),
135
+ [showWarningMessage](#window.showWarningMessage) and [showErrorMessage](#window.showErrorMessage) functions.
136
+
137
+ Simple example that show an information message:
138
+
139
+ ```typescript
140
+ theia.window.showInformationMessage('Information message');
141
+ ```
142
+
143
+ Simple example that show an information message with buttons:
144
+
145
+ ```typescript
146
+ theia.window.showInformationMessage('Information message', 'Btn1', 'Btn2').then(result => {
147
+ console.log("Click button", result);
148
+ });
149
+ ```
150
+
151
+ #### Window State API
152
+
153
+ It is possible to track state of the IDE window inside a plugin. Window state is defined as:
154
+
155
+ ```typescript
156
+ interface WindowState {
157
+ readonly focused: boolean;
158
+ }
159
+ ```
160
+
161
+ To read a state on demand one can use readonly variable:
162
+
163
+ ```typescript
164
+ theia.window.state
165
+ ```
166
+
167
+ To track window activity subscribe on `onDidChangeWindowState` event:
168
+
169
+ ```typescript
170
+ const disposable = theia.window.onDidChangeWindowState((windowState: theia.WindowState) => {
171
+ console.log('Window focus changed: ', windowState.focused);
172
+ });
173
+ ```
174
+
175
+ #### Status Bar API
176
+
177
+ A status bar shows a message to users and supports icon substitution.
178
+
179
+ Status bar message can be shown using the [setStatusBarMessage](#window.setStatusBarMessage) and
180
+ [createStatusBarItem](#window.createStatusBarItem) functions.
181
+
182
+ Simple example that show a status bar message:
183
+
184
+ ```typescript
185
+ theia.window.setStatusBarMessage('test status bar item');
186
+ ```
187
+
188
+ Simple example that show a status bar message with statusBarItem:
189
+
190
+ ```typescript
191
+ const item = theia.window.createStatusBarItem(theia.StatusBarAlignment.Right, 99);
192
+ item.text = 'test status bar item';
193
+ item.show();
194
+ ```
195
+ #### Output channel API
196
+
197
+ It is possible to show a container for readonly textual information:
198
+
199
+ ```typescript
200
+ const channel = theia.window.createOutputChannel('test channel');
201
+ channel.appendLine('test output');
202
+
203
+ ```
204
+
205
+ #### Environment API
206
+
207
+ Environment API allows reading of environment variables and query parameters of the IDE.
208
+
209
+ To get an environment variable by name one can use:
210
+
211
+ ```typescript
212
+ theia.env.getEnvVariable('NAME_OF_ENV_VARIABLE').then(value => {
213
+ // process the value here
214
+ }
215
+ ```
216
+
217
+ In case if environment variable doesn't exist `undefined` will be returned.
218
+
219
+ Also this part of API exposes all query parameters (already URI decoded) with which IDE page is loaded. One can get a query parameter by name:
220
+
221
+ ```typescript
222
+ theia.env.getQueryParameter('NAME_OF_QUERY_PARAMETER');
223
+ ```
224
+
225
+ In case if query parameter doesn't exist `undefined` will be returned.
226
+
227
+ Or it is possible to get a map of all query parameters:
228
+
229
+ ```typescript
230
+ theia.env.getQueryParameters();
231
+ ```
232
+
233
+ Note, that it is possible to have an array of values for single name, because it could be specified more than one time (for example `localhost:3000?foo=bar&foo=baz`).
234
+
235
+ ### Terminal
236
+
237
+ Function to create new terminal with specific arguments:
238
+
239
+ ```typescript
240
+ const terminal = theia.window.createTerminal("Bash terminal", "/bin/bash", ["-l"]);
241
+ ```
242
+
243
+ Where are:
244
+ - first argument - terminal's name.
245
+ - second argument - path to the executable shell.
246
+ - third argument - arguments to configure executable shell.
247
+
248
+ You can create terminal with specific options:
249
+
250
+ ```typescript
251
+ const options: theia.TerminalOptions {
252
+ name: "Bash terminal",
253
+ shellPath: "/bin/bash";
254
+ shellArgs: ["-l"];
255
+ cwd: "/projects";
256
+ env: { "TERM": "screen" };
257
+ };
258
+ ```
259
+
260
+ Where are:
261
+ - "shellPath" - path to the executable shell, for example "/bin/bash", "bash", "sh" or so on.
262
+ - "shellArgs" - shell command arguments, for example without login: "-l". If you defined shell command "/bin/bash" and set up shell arguments "-l" than will be created terminal process with command "/bin/bash -l". And client side will connect to stdin/stdout of this process to interaction with user.
263
+ - "cwd" - current working directory;
264
+ - "env"- environment variables for terminal process, for example TERM - identifier terminal window capabilities.
265
+
266
+ Function to create new terminal with defined theia.TerminalOptions described above:
267
+
268
+ ```typescript
269
+ const terminal = theia.window.createTerminal(options);
270
+ ```
271
+
272
+ Created terminal is not attached to the panel. To apply created terminal to the panel use method "show":
273
+
274
+ ```typescript
275
+ terminal.show();
276
+ ```
277
+
278
+ To hide panel with created terminal use method "hide";
279
+
280
+ ```typescript
281
+ terminal.hide();
282
+ ```
283
+
284
+ Send text to the terminal:
285
+
286
+ ```typescript
287
+ terminal.sendText("Hello, Theia!", false);
288
+ ```
289
+
290
+ Where are:
291
+ - first argument - text content.
292
+ - second argument - in case true, terminal will apply new line after the text, otherwise will send only the text.
293
+
294
+ Destroy terminal:
295
+
296
+ ```typescript
297
+ terminal.dispose();
298
+ ```
299
+
300
+ Subscribe to close terminal event:
301
+
302
+ ```typescript
303
+ theia.window.onDidCloseTerminal((term) => {
304
+ console.log("Terminal closed.");
305
+ });
306
+ ```
307
+
308
+ Detect destroying terminal by Id:
309
+
310
+ ```typescript
311
+ terminal.processId.then(id => {
312
+ theia.window.onDidCloseTerminal(async (term) => {
313
+ const currentId = await term.processId;
314
+ if (currentId === id) {
315
+ console.log("Terminal closed.", id);
316
+ }
317
+ }, id);
318
+ });
319
+ ```
320
+
321
+ #### Preference API
322
+
323
+ Preference API allows one to read or update User's and Workspace's preferences.
324
+
325
+ To get preferences:
326
+ ```typescript
327
+ // editor preferences
328
+ const preferences = theia.workspace.getConfiguration('editor');
329
+
330
+ // retrieving values
331
+ const fontSize = preferences.get('tabSize');
332
+ ```
333
+
334
+ To change preference:
335
+ ```typescript
336
+ preferences.onDidChangeConfiguration(e => {
337
+ if (e.affectsConfiguration('editor.tabSize')) {
338
+ console.log('Property "editor.tabSize" is changed');
339
+ }
340
+ });
341
+
342
+ preferences.update('tabSize', 2);
343
+ ```
344
+
345
+ ### Languages API
346
+
347
+ #### Diagnostics
348
+
349
+ To get all existing diagnostics one should use `getDiagnostics` call. If diagnostics are needed for specific URI they could be obtain with following call:
350
+
351
+ ```typescript
352
+ const diagnostics = theia.languages.getDiagnostics(uriToResource)
353
+ ```
354
+
355
+ To get all diagnostics use:
356
+ ```typescript
357
+ const diagnostics = theia.languages.getDiagnostics()
358
+ ```
359
+
360
+ For example, following code will get diagnostics for current file in the editor (supposed one is already opened):
361
+
362
+ ```typescript
363
+ const diagnosticsForCurrentFile = theia.languages.getDiagnostics(theia.window.activeTextEditor.document.uri)
364
+ ```
365
+
366
+ If no diagnostics found empty array will be returned.
367
+
368
+ Note, that returned array from `getDiagnostics` call are readonly.
369
+
370
+ To tracks changes in diagnostics `onDidChangeDiagnostics` event should be used. Within event handler list of uris with changed diagnostics is available. Example:
371
+
372
+ ```typescript
373
+ disposables.push(
374
+ theia.languages.onDidChangeDiagnostics((event: theia.DiagnosticChangeEvent) => {
375
+ // handler code here
376
+ }
377
+ );
378
+ ```
379
+
380
+ Also it is possible to add own diagnostics. To do this, one should create diagnostics collection first:
381
+
382
+ ```typescript
383
+ const diagnosticsCollection = theia.languages.createDiagnosticCollection(collectionName);
384
+ ```
385
+
386
+ Collection name can be omitted. In such case the name will be auto-generated.
387
+
388
+ When collection is created, one could operate with diagnostics. The collection object exposes all needed methods: `get`, `set`, `has`, `delete`, `clear`, `forEach` and `dispose`.
389
+
390
+ `get`, `has` and `delete` performs corresponding operation by given resource uri. `clear` removes all diagnostics for all uris in the collection.
391
+
392
+ Behavior of `set` is more complicated. To replace all diagnostics for given uri the following call should be used:
393
+
394
+ ```typescript
395
+ diagnosticsCollection.set(uri, newDiagnostics)
396
+ ```
397
+
398
+ if `undefined` is passed instead of diagnostics array the call will clear diagnostics for given uri in this collection (the same as `delete`).
399
+ Also it is possible to set all diagnostics at once (it will replace existed ones). To do this, array of tuples in format `[uri, diagnostics]` should be passed as argument for `set`:
400
+
401
+ ```typescript
402
+ const changes: [Uri, Diagnostic[] | undefined][] = [];
403
+
404
+ changes.push([uri1, diagnostics1]);
405
+ changes.push([uri2, diagnostics2]);
406
+ changes.push([uri3, undefined]);
407
+ changes.push([uri1, diagnostics4]); // uri1 again
408
+
409
+ diagnosticsCollection.set(changes);
410
+ ```
411
+
412
+ If the same uri is used a few times, corresponding diagnostics will be merged. In case of `undefined` all previous, but not following, diagnostics will be cleared. If `undefined` is given instead of tuples array the whole collection will be cleared.
413
+
414
+ To iterate over all diagnostics within the collection `forEach` method could be used:
415
+
416
+ ```typescript
417
+ diagnosticsCollection.forEach((uri, diagnostics) => {
418
+ // code here
419
+ }
420
+ ```
421
+
422
+ `dispose` method should be used when the collection is not needed any more. In case of attempt to do an operation after disposing an error will be thrown.
423
+
424
+ #### Signature help
425
+
426
+ To provide signature help form plugin it is required to register provider. For registration 3 items are needed:
427
+ - Documents selector to describe for which files it should be applied
428
+ - Handler which will do the work
429
+ - Trigger characters after typing of which the handler should be invoked. Often symbols `(` and `,` are used.
430
+
431
+ Example of signature help provider registration:
432
+
433
+ ```typescript
434
+ const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
435
+ const handler = { provideSignatureHelp: signatureHelpHandler };
436
+ const triggerChars = '(,';
437
+
438
+ const disposable = theia.languages.registerSignatureHelpProvider(documentsSelector, handler, ...triggerChars);
439
+
440
+ ...
441
+
442
+ function signatureHelpHandler(document: theia.TextDocument, position: theia.Position): theia.ProviderResult<theia.SignatureHelp> {
443
+ // code here
444
+ }
445
+ ```
446
+
447
+ Example of signature information:
448
+
449
+ ```typescript
450
+ {
451
+ activeSignature: 0,
452
+ activeParameter: 0,
453
+ signatures: [
454
+ {
455
+ label: 'functionName(param1: number, param2: string, param3: boolean)',
456
+ documentation: new theia.MarkdownString('What **this** function does'),
457
+ parameters: [
458
+ {
459
+ label: 'param1: number',
460
+ documentation: new theia.MarkdownString('Some number. Should not be `undefined`')
461
+ },
462
+ {
463
+ label: 'param2: string',
464
+ documentation: 'Some string'
465
+ },
466
+ {
467
+ label: 'param3: boolean',
468
+ documentation: 'Some flag'
469
+ }
470
+ ]
471
+ }
472
+ ]
473
+ }
474
+ ```
475
+
476
+ Note, that:
477
+ - `activeSignature` and `activeParameter` are zero based.
478
+ - label is usually full method signature.
479
+ - for documentation fields markdown partially supported (Tags aren't supported).
480
+ - label of a parameter should be substring of the signature label. In such case the substring will be highlighted in main label when parameter is active. Otherwise has no effect.
481
+
482
+ When signature help popup is shown then the handler will be invoked on each parameter edit or even cursor moving inside signature. If you have large objects it would be wise to cache them of at least reuse some parts.
483
+
484
+ To hide your popup just return `undefined` from provider.
485
+
486
+ In case if a few providers are registered the chain will be executed until one of the providers returns result. Next providers will be ignored for the call.
487
+
488
+ #### Hover Message
489
+
490
+ To contribute a hover it is only needed to provide a function that can be called with a `TextDocument` and a `Position` returning hover info. Registration is done using a document selector which either a language id ('typescript', 'javascript' etc.) or a more complex filter like `{scheme: 'file', language: 'typescript'}`.
491
+
492
+ For example,
493
+
494
+ ```typescript
495
+ theia.languages.registerHoverProvider('typescript', {
496
+ provideHover(doc: theia.TextDocument, position: theia.Position, token: theia.CancellationToken) {
497
+ return new theia.Hover('Hover for all **typescript** files.');
498
+ }
499
+ });
500
+ ```
501
+
502
+ will show the hover message for all `typescript` files.
503
+
504
+ The code below puts word under cursor into hover message:
505
+
506
+ ```typescript
507
+ theia.languages.registerHoverProvider({scheme: 'file'}, {
508
+ provideHover(doc: theia.TextDocument, position: theia.Position, token: theia.CancellationToken) {
509
+ const range = doc.getWordRangeAtPosition(position);
510
+ const text = doc.getText(range);
511
+ return new theia.Hover(text);
512
+ }
513
+ });
514
+ ```
515
+
516
+ #### Document Highlight provider
517
+
518
+ It is possible to provide document highlight source for a symbol from within plugin.
519
+ To do this one should register corresponding provider. For example:
520
+
521
+ ```typescript
522
+ const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
523
+ const handler: theia.DocumentHighlightProvider = { provideDocumentHighlights: provideDocumentHighlightsHandler };
524
+
525
+ const disposable = theia.languages.registerDocumentHighlightProvider(documentsSelector, handler);
526
+
527
+ ...
528
+
529
+ function provideDocumentHighlightsHandler(document: theia.TextDocument, position: theia.Position): theia.ProviderResult<theia.DocumentHighlight[]> {
530
+ // code here
531
+ }
532
+ ```
533
+
534
+ It is possible to return a few sources, but for most cases only one is enough. Return `undefined` to provide nothing.
535
+
536
+ #### Definition provider
537
+
538
+ It is possible to provide definition source for a symbol from within plugin.
539
+ To do this one should register corresponding provider. For example:
540
+
541
+ ```typescript
542
+ const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
543
+ const handler: theia.DefinitionProvider = { provideDefinition: provideDefinitionHandler };
544
+
545
+ const disposable = theia.languages.registerDefinitionProvider(documentsSelector, handler);
546
+
547
+ ...
548
+
549
+ function provideDefinitionHandler(document: theia.TextDocument, position: theia.Position): theia.ProviderResult<theia.Definition | theia.DefinitionLink[]> {
550
+ // code here
551
+ }
552
+ ```
553
+
554
+ The handler will be invoked each time when a user executes `Go To Definition` command.
555
+ It is possible to return a few sources, but for most cases only one is enough. Return `undefined` to provide nothing.
556
+
557
+ #### Declaration provider
558
+
559
+ It is possible to provide a declaration for a symbol from within a plugin.
560
+ To do this one may register corresponding provider. For example:
561
+
562
+ ```typescript
563
+ const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
564
+ const handler: theia.DeclarationProvider = { provideDeclaration: provideDeclarationHandler };
565
+
566
+ const disposable = theia.languages.registerDeclarationProvider(documentsSelector, handler);
567
+
568
+ ...
569
+
570
+ function provideDeclarationHandler(document: theia.TextDocument, position: theia.Position): theia.ProviderResult<theia.Definition | theia.DefinitionLink[]> {
571
+ // code here
572
+ }
573
+ ```
574
+
575
+ The handler will be invoked each time when a user executes `Go To Declaration` command.
576
+ It is possible to return a few sources, but for most cases only one is enough. Return `undefined` to provide nothing.
577
+
578
+ #### Implementation provider
579
+
580
+ It is possible to provide implementation source for a symbol from within plugin.
581
+ To do this one should register corresponding provider. For example:
582
+
583
+ ```typescript
584
+ const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
585
+ const handler: theia.ImplementationProvider = { provideImplementation: provideImplementationHandler };
586
+
587
+ const disposable = theia.languages.registerImplementationProvider(documentsSelector, handler);
588
+
589
+ ...
590
+
591
+ function provideImplementationHandler(document: theia.TextDocument, position: theia.Position): theia.ProviderResult<theia.Definition | theia.DefinitionLink[]> {
592
+ // code here
593
+ }
594
+ ```
595
+
596
+ It is possible to return a few sources, but for most cases only one is enough. Return `undefined` to provide nothing.
597
+
598
+ #### Type Definition provider
599
+
600
+ It is possible to provide type definition source for a symbol from within plugin.
601
+ To do this one should register corresponding provider. For example:
602
+
603
+ ```typescript
604
+ const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
605
+ const handler: theia.TypeDefinitionProvider = { provideTypeDefinition: provideTypeDefinitionHandler };
606
+
607
+ const disposable = theia.languages.registerTypeDefinitionProvider(documentsSelector, handler);
608
+
609
+ ...
610
+
611
+ function provideTypeDefinitionHandler(document: theia.TextDocument, position: theia.Position): theia.ProviderResult<theia.Definition | theia.DefinitionLink[]> {
612
+ // code here
613
+ }
614
+ ```
615
+
616
+ The handler will be invoked each time when a user executes `Go To Type Definition` command.
617
+ It is possible to return a few sources, but for most cases only one is enough. Return `undefined` to provide nothing.
618
+
619
+ #### Reference provider
620
+
621
+ It is possible to provide reference sources for a symbol from within plugin.
622
+ To do this one should register corresponding provider. For example:
623
+
624
+ ```typescript
625
+ const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
626
+ const handler: theia.ReferenceProvider = { provideReferences: provideReferencesHandler };
627
+
628
+ const disposable = theia.languages.registerReferenceProvider(documentsSelector, handler);
629
+
630
+ ...
631
+
632
+ function provideReferencesHandler(document: theia.TextDocument, position: theia.Position, context: theia.ReferenceContext): theia.ProviderResult<theia.Location[]> {
633
+ // code here
634
+ }
635
+ ```
636
+
637
+ The handler will be invoked each time when a user executes `Find All References` command.
638
+ It is possible to return a few sources. Return `undefined` to provide nothing.
639
+
640
+ #### Document Link Provider
641
+
642
+ A document link provider allows to add a custom link detection logic.
643
+
644
+ Example of document link provider registration:
645
+
646
+ ```typescript
647
+ const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
648
+ const provider = { provideDocumentLinks: provideLinks };
649
+
650
+ const disposable = theia.languages.registerDocumentLinkProvider(documentsSelector, provider);
651
+
652
+ ...
653
+
654
+ function provideLinks(document: theia.TextDocument): theia.ProviderResult<theia.DocumentLink[]> {
655
+ // code here
656
+ }
657
+ ```
658
+
659
+ #### Code Lens Provider
660
+
661
+ A code lens provider allows to add a custom lens detection logic.
662
+
663
+ Example of code lens provider registration:
664
+
665
+ ```typescript
666
+ const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
667
+ const provider = { provideCodeLenses: provideLenses };
668
+
669
+ const disposable = theia.languages.registerCodeLensProvider(documentsSelector, provider);
670
+
671
+ ...
672
+
673
+ function provideLenses(document: theia.TextDocument): theia.ProviderResult<theia.CodeLens[]> {
674
+ // code here
675
+ }
676
+ ```
677
+
678
+ #### Code Symbol Provider
679
+
680
+ A document symbol provider allows to add a custom logic for symbols detection.
681
+
682
+ Example of code symbol provider registration:
683
+
684
+ ```typescript
685
+ const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
686
+ const provider = { provideDocumentSymbols: provideSymbols };
687
+ const metadata = { label: 'providerLabel' }
688
+
689
+ const disposable = theia.languages.registerDocumentSymbolProvider(documentsSelector, provider, metadata);
690
+
691
+ ...
692
+
693
+ function provideSymbols(document: theia.TextDocument): theia.ProviderResult<theia.SymbolInformation[] | theia.DocumentSymbol[]> {
694
+ // code here
695
+ }
696
+ ```
697
+
698
+ #### Workspace Symbol Provider
699
+
700
+ A workspace symbol provider allows you register symbols for the symbol search feature.
701
+
702
+ resolveWorkspaceSymbol is not needed if all SymbolInformation's returned from
703
+ provideWorkspaceSymbols have a location. Otherwise resolveWorkspaceSymbol is needed
704
+ in order to resolve the location of the SymbolInformation.
705
+
706
+ Example of workspace symbol provider registration:
707
+
708
+ ```typescript
709
+ theia.languages.registerWorkspaceSymbolProvider({
710
+ provideWorkspaceSymbols(query: string): theia.SymbolInformation[] {
711
+ return [new theia.SymbolInformation('my symbol', 4, new theia.Range(new theia.Position(0, 0), new theia.Position(0, 0)), theia.Uri.parse("some_uri_to_file"))];
712
+ }
713
+ } as theia.WorkspaceSymbolProvider);
714
+ ```
715
+
716
+ In this case resolveWorkspaceSymbol is not needed because we have provided the location for every
717
+ symbol returned from provideWorkspaceSymbols
718
+
719
+ ```typescript
720
+ theia.languages.registerWorkspaceSymbolProvider({
721
+ provideWorkspaceSymbols(query: string): theia.SymbolInformation[] {
722
+ return [new theia.SymbolInformation('my symbol', 4, 'my container name', new theia.Location(theia.Uri.parse("some_uri_to_file"), undefined))];
723
+ },
724
+ resolveWorkspaceSymbol(symbolInformation: theia.SymbolInformation): theia.SymbolInformation {
725
+ symbolInformation.location.range = new theia.Range(new theia.Position(0, 0), new theia.Position(0, 0));
726
+ return symbolInformation;
727
+ }
728
+ } as theia.WorkspaceSymbolProvider);
729
+ ```
730
+
731
+ resolveWorkspaceSymbol is needed here because we have not provided the location for every
732
+ symbol return from provideWorkspaceSymbol
733
+
734
+ #### Folding
735
+
736
+ A folding range provider allows you to add logic to fold and unfold custom regions of source code.
737
+
738
+ Example of folding range provider registration:
739
+
740
+ ```typescript
741
+ const documentsSelector: theia.DocumentSelector = { scheme: 'file', language: 'typescript' };
742
+ const provider = { provideFoldingRanges: provideRanges };
743
+
744
+ const disposable = theia.languages.registerFoldingRangeProvider(documentsSelector, provider);
745
+
746
+ ...
747
+
748
+ function provideRanges(document: theia.TextDocument): theia.ProviderResult<theia.FoldingRange[]> {
749
+ // code here
750
+ }
751
+ ```
752
+
753
+ ## Additional Information
754
+
755
+ - [API documentation for `@theia/plugin`](https://eclipse-theia.github.io/theia/docs/next/modules/plugin.html)
756
+ - [Theia - GitHub](https://github.com/eclipse-theia/theia)
757
+ - [Theia - Website](https://theia-ide.org/)
758
+
759
+ ## License
760
+
761
+ - [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
762
+ - [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
763
+
764
+ ## Trademark
765
+ "Theia" is a trademark of the Eclipse Foundation
766
+ https://www.eclipse.org/theia