-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[plug-in] [WIP] Plugin api documentation #3045
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Basic architecture overview | ||
![Theia Plugin API](https://user-images.githubusercontent.com/436777/37775864-5cf856d0-2de4-11e8-8f55-2b5a5de72908.png) | ||
|
||
## Plugin runtime | ||
Plugin runtime is a JavaScript runtime for Theia plugins, for now we have two types of the runtime: | ||
|
||
1. WebWorker - for frontend plugins | ||
2. Separate Node.JS instance - for backend plugins | ||
|
||
## plugin-ext structure | ||
|
||
[api](../src/api) - protocol and model objects for communication between Theia client and plugins runtime | ||
|
||
[main](../src/main) - Theia part if plugin API. Code inside this directory is simple Theia extension and can use all functionality provided by Theia like `inversify`; | ||
|
||
[plugin](../src/plugin) - Plugin runtime part of the Plugin API. Here place for all types and namespaces described in [theia.d.ts](../../plugin/src/theia.d.ts) | ||
|
||
## How to add new Plugin API | ||
|
||
### Add new method/namespace to [theia.d.ts](../../plugin/src/theia.d.ts) | ||
|
||
You can copy from `vscode.d.ts` or provide your own. | ||
For example, adding Command API: | ||
|
||
```typescript | ||
export namespace commands { | ||
export function registerCommand(command: Command handler?: (...args: any[]) => any): Disposable; | ||
} | ||
``` | ||
|
||
### Add implementation of your API | ||
|
||
All implementations is stored in [plugin-context.ts](../src/plugin/plugin-context.ts) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo? |
||
`plugin-context.ts` contains `createAPIFactory` function which returns factory function which return own instance of Theia Plugin API for plugin. | ||
In that factory function you should provide implementation for API that you added in `theia.d.ts`. You should put your implementation in proper(the same) namespace object. | ||
|
||
#### Namespace handling | ||
|
||
If you add new namespace you need to create new namespace object and add it in object returned from factory function. For example: | ||
|
||
```typescript | ||
const commands: typeof theia.commands = { | ||
// implementation of commands namespace function and fields | ||
}; | ||
|
||
|
||
return <typeof theia>{ | ||
... | ||
// add your namespace and types there | ||
commands, | ||
... | ||
} | ||
``` | ||
|
||
#### New type adding | ||
|
||
Also you can add interfaces, classes and enums in `theia.d.ts`. | ||
Interfaces doesn't require anything special. But for classes and enums you should provide implementation. Common place for this implementations is [types-impl.ts](../src/plugin/types-impl.ts) | ||
|
||
Example: | ||
Adding new class in `theia.d.ts`: | ||
|
||
```typescript | ||
export class Foo { | ||
public bar: string; | ||
constructor(bar: string); | ||
} | ||
``` | ||
|
||
You need to provide implementation of `Foo` class in [types-impl.ts](../src/plugin/types-impl.ts): | ||
|
||
```typescript | ||
export class Foo { | ||
constructor(public bar: string){ | ||
} | ||
} | ||
``` | ||
|
||
Then in [plugin-context.ts](../src/plugin/plugin-context.ts): | ||
|
||
```typescript | ||
import {Foo} from './types-impl'; | ||
|
||
... | ||
|
||
return <typeof theia>{ | ||
... | ||
Foo, | ||
... | ||
} | ||
``` | ||
|
||
> For enums you should do the same. Usually it's just copying enum declaration from `theia.d.ts` to `types-impl.ts`, and adding that enum in to `theia` object returned by `createAPIFactory` factory function | ||
|
||
#### Adding plugin runtime part of the API implementation - TODO | ||
|
||
### Working with RPC proxy - TODO | ||
|
||
#### Theia <-> Plugin runtime communication - TODO | ||
|
||
##### *Ext and *Main interfaces - TODO | ||
|
||
### Adding Theia part of the API implementation - TODO |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo?
Theia part of plugin API ?