@codingame/monaco-vscode-api 1.67.7 → 1.67.8-dev.0

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
@@ -1,20 +1,47 @@
1
1
  # @codingame/monaco-vscode-api · [![monthly downloads](https://img.shields.io/npm/dm/@codingame/monaco-vscode-api)](https://www.npmjs.com/package/@codingame/monaco-vscode-api) [![npm version](https://img.shields.io/npm/v/@codingame/monaco-vscode-api.svg?style=flat)](https://www.npmjs.com/package/@codingame/monaco-vscode-api) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/codingame/monaco-vscode-api/pulls)
2
2
 
3
- [NPM module](https://www.npmjs.com/) that respects the vscode api and redirect calls to monaco editor.
3
+ [NPM module](https://www.npmjs.com/) that implements the VSCode api and redirects calls to Monaco editor.
4
4
 
5
- Some features not supported by monaco (type hierarchy, call hierarchy...) can be implemented by hands:
5
+ The VSCode api is composed of:
6
+
7
+ - A lot of classes and tools, which are exported the same way as in VSCode.
8
+ - Some features that are supported by Monaco (Language feature registrations...) which are just forwarded to it (with some transformations)
9
+ - Some features that are not supported by Monaco, and in such case:
10
+ - If it's an important feature: we let the user implement it as they wish.
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
+
13
+
14
+ To implement by hands the optional features (file system, workspace folders, file...), you can use the `Services` namespace from `vscode/services`:
6
15
  ```typescript
7
16
  import { Services } from 'vscode/services'
8
17
  Services.install({
9
- languages: {
10
- registerTypeHierarchyProvider (documentSelector, provider) {
11
- ...
12
- }
13
- }
18
+ workspace: {
19
+ workspaceFolders: ...,
20
+ createFileSystemWatcher (documentSelector, provider) {
21
+ ...
22
+ },
23
+ onDidSaveTextDocument
24
+ },
25
+ window: {
26
+ withProgress: ...
27
+ }
14
28
  })
15
29
  ```
16
30
 
31
+ Also, monaco-editor use `standalone` versions or the vscode services, which are much simpler.
32
+
33
+ You may want to provide your custom implementations of them, especially for: `textModelService`, `codeEditorService` and `notificationService`. Do do so, you can give 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.
17
36
 
37
+ Example:
38
+ ```
39
+ import { StandaloneService, INotificationService } from 'vscode/services'
40
+
41
+ StandaloneService.initialize({
42
+ textModelService: class MyCustomNotificationService implements INotificationService { ... }
43
+ })
44
+ ```
18
45
 
19
46
  ### Installation
20
47
 
@@ -25,7 +52,7 @@ npm install -D @types/vscode
25
52
 
26
53
  ### Usage
27
54
 
28
- Just import it as if you were in a vscode extensions:
55
+ Just import it as if you were in a vscode extension:
29
56
 
30
57
  ```typescript
31
58
  import * as vscode from 'vscode'
@@ -34,3 +61,25 @@ const range = new new vscode.Range(...)
34
61
  vscode.languages.registerCompletionItemProvider(...)
35
62
  ```
36
63
 
64
+ ### History
65
+
66
+ This project was mainly created to make the implementation of [monaco-languageclient](https://github.com/TypeFox/monaco-languageclient) more robust and maintainable.
67
+
68
+ 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.
69
+
70
+ [The VSCode api](https://code.visualstudio.com/api/references/vscode-api) exports:
71
+ - 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)...)
72
+ - A lot of utility classes (Range, Position...)
73
+
74
+ 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.
75
+
76
+ This approach has some disadvantages:
77
+ - There is a lot of code to transform LSP objects into Monaco objects
78
+ - It's hard to follow the updates of VSCode and the language server protocol
79
+ - It doesn't behave exactly the same as in VSCode
80
+
81
+ With this library, it would be possible to plug vscode-languageclient directly on top of monaco, monaco-languageclient still helps to do so by:
82
+ - Adding some tweaks to the VSCode LanguageClient (Removing unsupported features...)
83
+ - Providing a default implementations of the required fallback services (`vscode/services`)
84
+ - Providing some examples on how to build an app using it
85
+ - Adding some tools (DisposableCollection)