@codingame/monaco-vscode-api 1.67.8 → 1.67.11

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.
package/README.md CHANGED
@@ -11,19 +11,61 @@ The VSCode api is composed of:
11
11
  - If it's some advanced features that don't make a lot of sense on Monaco (debug, tests...), it just throws an error when you try to use it.
12
12
 
13
13
 
14
- To implement by hands the optional features (type hierarchy, call hierarchy...), you can use the `Services` namespace from `vscode/services`:
14
+ To implement by hands the optional features (file system, workspace folders, file...), you can use the `Services` namespace from `vscode/services`:
15
15
  ```typescript
16
16
  import { Services } from 'vscode/services'
17
17
  Services.install({
18
- languages: {
19
- registerTypeHierarchyProvider (documentSelector, provider) {
20
- ...
21
- }
22
- }
18
+ workspace: {
19
+ workspaceFolders: ...,
20
+ createFileSystemWatcher (documentSelector, provider) {
21
+ ...
22
+ },
23
+ onDidSaveTextDocument
24
+ },
25
+ window: {
26
+ withProgress: ...
27
+ }
23
28
  })
24
29
  ```
25
30
 
31
+ Also, monaco-editor use `standalone` versions or the vscode services, which are much simpler.
26
32
 
33
+ You may want to provide your custom implementations of them, especially for: `textModelService`, `codeEditorService` and `notificationService`. To do so, you can provide them as the third parameter while creating your first editor.
34
+ This library allows you to use a more convenient way using `StandaloneService.initialize`.
35
+ Also, monaco-editor doesn't provide good type for them, so this library does it.
36
+
37
+ Example:
38
+ ```typescript
39
+ import { StandaloneService, INotificationService } from 'vscode/services'
40
+
41
+ class MyCustomNotificationService implements INotificationService { ... }
42
+ StandaloneService.initialize({
43
+ get [INotificationService.toString()] () {
44
+ return new MyCustomNotificationService(...)
45
+ }
46
+ })
47
+ ```
48
+
49
+ Additionally, this library exposes 2 modules that include the vscode version of some services (with some glue to make it work with monaco):
50
+ - Notification / Dialog: `vscode/service-override/messages`
51
+ - Model / Editor: `vscode/service-override/modelEditor`
52
+
53
+ Usage:
54
+ ```typescript
55
+ import { StandaloneService } from 'vscode/services'
56
+ import getModelEditorServiceOverride from 'vscode/service-override/modelEditor'
57
+ import getMessageServiceOverride from 'vscode/service-override/messages'
58
+
59
+ StandaloneServices.initialize({
60
+ ...getModelEditorServiceOverride((model, input, sideBySide) => {
61
+ // Open a new editor here and return it
62
+ // It will be called when for instance the user ctrl+click on an import
63
+ }),
64
+ ...getMessageServiceOverride(document.body)
65
+ })
66
+ ```
67
+
68
+ Note: using `vscode/service-override/modelEditor`, you'll be able to use the `vscode.workspace.registerTextDocumentContentProvider` api
27
69
 
28
70
  ### Installation
29
71
 
@@ -42,3 +84,26 @@ import * as vscode from 'vscode'
42
84
  const range = new new vscode.Range(...)
43
85
  vscode.languages.registerCompletionItemProvider(...)
44
86
  ```
87
+
88
+ ### History
89
+
90
+ This project was mainly created to make the implementation of [monaco-languageclient](https://github.com/TypeFox/monaco-languageclient) more robust and maintainable.
91
+
92
+ monaco-languageclient uses [vscode-languageclient](https://www.npmjs.com/package/vscode-languageclient) which was built to run inside a VSCode extension. VSCode extensions communicate with the editor via an [API](https://www.npmjs.com/package/@types/vscode) they can import into their code.
93
+
94
+ [The VSCode api](https://code.visualstudio.com/api/references/vscode-api) exports:
95
+ - Some functions to interact with the IDE ([language feature registrations](https://code.visualstudio.com/api/references/vscode-api#languages), [command execution](https://code.visualstudio.com/api/references/vscode-api#commands)...)
96
+ - A lot of utility classes (Range, Position...)
97
+
98
+ The first implementations of [monaco-languageclient](https://github.com/TypeFox/monaco-languageclient) were using a fake VSCode api implementation. The vscode-languageclient was hacked so the VSCode<->protocol object converters were mainly bypassed, so the fake VSCode api was receiving [Language Server Protocol](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/) objects. Then the objects were transformed using custom transformers into [Monaco](https://www.npmjs.com/package/monaco-editor) objects to communicate with the monaco api.
99
+
100
+ This approach has some disadvantages:
101
+ - There is a lot of code to transform LSP objects into Monaco objects
102
+ - It's hard to follow the updates of VSCode and the language server protocol
103
+ - It doesn't behave exactly the same as in VSCode
104
+
105
+ With this library, it would be possible to plug vscode-languageclient directly on top of monaco, monaco-languageclient still helps to do so by:
106
+ - Adding some tweaks to the VSCode LanguageClient (Removing unsupported features...)
107
+ - Providing a default implementations of the required fallback services (`vscode/services`)
108
+ - Providing some examples on how to build an app using it
109
+ - Adding some tools (DisposableCollection)