Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement basic worksheet mode using mdoc and text decorations (#1041)
Implement basic worksheet mode using mdoc and text decorations
- Loading branch information
Showing
40 changed files
with
1,209 additions
and
126 deletions.
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,115 @@ | ||
--- | ||
id: decoration-protocol | ||
sidebar_label: Decoration Protocol | ||
title: Decoration Protocol v0.1.0 | ||
--- | ||
|
||
Metals implements a Language Server Protocol extension called the "Decoration | ||
Protocol" to display non-editable text in the text editor. | ||
|
||
## Base data structures | ||
|
||
The Decoration Protocol has several base data structures that are mostly derived | ||
from the [VS Code API](https://code.visualstudio.com/api/references/vscode-api). | ||
|
||
### Decoration | ||
|
||
A "decoration" represents non-editable code that is display in the text editor | ||
alongside editable code. The GIF below demonstrates an example of green | ||
decorations that are formatted as comments, which contain the evaluated code. | ||
|
||
![Example decoration](https://user-images.githubusercontent.com/1408093/68091453-bacbea00-fe77-11e9-80b9-52a9bbd6d98a.gif) | ||
|
||
Although decorations appear as text inside the editor, they can't be edited by | ||
the user. In the GIF above, observe that the decoration can optionally include a | ||
message that's displayed on mouse hover. | ||
|
||
## DecorationOptions | ||
|
||
```ts | ||
export interface DecorationOptions { | ||
/** | ||
* The range position to place the decoration. | ||
* The Range data structure is defined in the Language Server Protocol. | ||
*/ | ||
range: Range; | ||
/** | ||
* The text to display when the mouse hovers over the decoration. | ||
* The MarkedString data structure is defined in the LanguageServerProtocol | ||
*/ | ||
hoverMessage?: MarkedString; | ||
/** The URI of the text document to place text decorations */ | ||
renderOptions: ThemableDecorationInstanceRenderOption; | ||
} | ||
``` | ||
|
||
## ThemableDecorationInstanceRenderOption | ||
|
||
```ts | ||
export interface ThemableDecorationInstanceRenderOption { | ||
/** The decoration to display next to the given range. */ | ||
after?: ThemableDecorationAttachmentRenderOptions; | ||
} | ||
``` | ||
|
||
## ThemableDecorationAttachmentRenderOptions | ||
|
||
```ts | ||
export interface ThemableDecorationAttachmentRenderOptions { | ||
/** The text to display in the decoration */ | ||
contentText?: string; | ||
/** The color of `contentText`. More colors may be added in the future. */ | ||
color?: "green"; | ||
/** The font style to use for displaying `contentText. More styles may be added in the future. */ | ||
fontStyle?: "italic"; | ||
} | ||
``` | ||
|
||
## Endpoints | ||
|
||
The Decoration Protocol is embedded inside the Language Server Protocol and | ||
consists of a single JSON-RPC notification. | ||
|
||
### `initialize` | ||
|
||
The Decoration Protocol is only enabled when both the client and server declare | ||
support for the protocol by adding an `decorationProvider: true` field to the | ||
experimental section of the server and client capabilities in the `initialize` | ||
response. | ||
|
||
```json | ||
{ | ||
"capabilities": { | ||
"experimental": { | ||
"decorationProvider": true | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### `metals/publishDecorations` | ||
|
||
The decoration ranges did change notification is sent from the server to the | ||
client to notify that decorations have changes for a given text document. | ||
|
||
_Notification_: | ||
|
||
- method: `metals/publishDecorations` | ||
- params: `PublishDecorationsParams` as defined below: | ||
|
||
```ts | ||
export interface PublishDecorationsParams { | ||
/** The URI of the text document to place text decorations */ | ||
uri: string; | ||
|
||
/** | ||
* The ranges to publish for this given document. | ||
* Use empty list to clear all decorations. | ||
*/ | ||
options: DecorationOptions[]; | ||
} | ||
``` | ||
|
||
## Changelog | ||
|
||
- v0.1.0: First release with basic support for worksheets. |
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
18 changes: 18 additions & 0 deletions
18
metals/src/main/scala/scala/meta/internal/async/ConcurrentQueue.scala
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,18 @@ | ||
package scala.meta.internal.async | ||
import java.util.concurrent.ConcurrentLinkedQueue | ||
import scala.collection.mutable | ||
|
||
object ConcurrentQueue { | ||
|
||
/** Returns all elements in the queue and empties the queue */ | ||
def pollAll[T](queue: ConcurrentLinkedQueue[T]): List[T] = { | ||
val buffer = mutable.ListBuffer.empty[T] | ||
var elem = queue.poll() | ||
while (elem != null) { | ||
buffer += elem | ||
elem = queue.poll() | ||
} | ||
buffer.toList | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
metals/src/main/scala/scala/meta/internal/decorations/DecorationClient.scala
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,24 @@ | ||
package scala.meta.internal.decorations | ||
|
||
import javax.annotation.Nullable | ||
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification | ||
import org.eclipse.lsp4j.Range | ||
import org.eclipse.lsp4j.MarkedString | ||
|
||
trait DecorationClient { | ||
@JsonNotification("metals/publishDecorations") | ||
def metalsPublishDecorations( | ||
params: PublishDecorationsParams | ||
): Unit | ||
} | ||
|
||
case class DecorationOptions( | ||
range: Range, | ||
@Nullable hoverMessage: MarkedString = null, | ||
@Nullable renderOptions: ThemableDecorationInstanceRenderOptions = null | ||
) | ||
|
||
case class PublishDecorationsParams( | ||
uri: String, | ||
options: Array[DecorationOptions] | ||
) |
21 changes: 21 additions & 0 deletions
21
...ain/scala/scala/meta/internal/decorations/ThemableDecorationAttachmentRenderOptions.scala
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,21 @@ | ||
package scala.meta.internal.decorations | ||
|
||
import javax.annotation.Nullable | ||
|
||
case class ThemableDecorationAttachmentRenderOptions( | ||
@Nullable contentText: String = null, | ||
@Nullable contentIconPath: String = null, | ||
@Nullable border: String = null, | ||
@Nullable borderColor: String = null, | ||
@Nullable fontStyle: String = null, | ||
@Nullable fontWeight: String = null, | ||
@Nullable textDecoration: String = null, | ||
@Nullable color: String = null, | ||
@Nullable backgroundColor: String = null, | ||
@Nullable margin: String = null, | ||
@Nullable width: String = null, | ||
@Nullable height: String = null, | ||
@Nullable opacity: java.lang.Double = null, | ||
@Nullable light: ThemableDecorationAttachmentRenderOptions = null, | ||
@Nullable dark: ThemableDecorationAttachmentRenderOptions = null | ||
) |
10 changes: 10 additions & 0 deletions
10
.../main/scala/scala/meta/internal/decorations/ThemableDecorationInstanceRenderOptions.scala
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,10 @@ | ||
package scala.meta.internal.decorations | ||
|
||
import javax.annotation.Nullable | ||
|
||
case class ThemableDecorationInstanceRenderOptions( | ||
@Nullable before: ThemableDecorationAttachmentRenderOptions = null, | ||
@Nullable after: ThemableDecorationAttachmentRenderOptions = null, | ||
@Nullable light: ThemableDecorationInstanceRenderOptions = null, | ||
@Nullable dark: ThemableDecorationInstanceRenderOptions = null | ||
) |
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
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
Oops, something went wrong.