Skip to content

Commit

Permalink
Merge branch 'main' into add-will-rename-and-did-rename
Browse files Browse the repository at this point in the history
  • Loading branch information
predragnikolic committed Aug 20, 2024
2 parents 51962f1 + fe795a1 commit 21f1bf7
Show file tree
Hide file tree
Showing 6 changed files with 4,583 additions and 4,578 deletions.
81 changes: 68 additions & 13 deletions docs/src/language_servers.md
Original file line number Diff line number Diff line change
Expand Up @@ -778,35 +778,90 @@ See [Javascript/TypeScript](#javascripttypescript).
## Typst

1. Install the [Typst](https://packagecontrol.io/packages/Typst) package from Package Control for syntax highlighting.
2. Download the [typst-lsp](https://github.com/nvarner/typst-lsp/releases) language server executable for your platform.
3. Open `Preferences > Package Settings > LSP > Settings` and add the `"typst-lsp"` client configuration to the `"clients"`:
2. Optional: to enable auto-completions for the relevant situations in Typst files, adjust Sublime's `"auto_complete_selector"` and/or `"auto_complete_triggers"` setting (`Preferences > Settings`); for example
```jsonc
{
"auto_complete_triggers":
[
{"selector": "text.html, text.xml", "characters": "<"},
{"selector": "punctuation.accessor", "rhs_empty": true},
{"selector": "text.typst", "characters": "#", "rhs_empty": true},
],
}
```
There are 2 available languages servers.
### Tinymist
This server has more features, like go to definition, rename, etc.
1. Install [tinymist](https://github.com/Myriad-Dreamin/tinymist).
2. Open `Preferences > Package Settings > LSP > Settings` and add the `"tinymist"` client configuration to the `"clients"`:
```jsonc
{
"clients": {
"typst-lsp": {
"tinymist": {
"enabled": true,
"command": ["C:\\path\\to\\typst-lsp-win32-x64.exe"], // adjust this path according to your platform/setup
"selector": "text.typst"
"command": ["path/to/tinymist"], // adjust this path according to your platform/setup
"selector": "text.typst",
// you can provide some initialization options:
"initializationOptions": {
"exportPdf": "never",
"typstExtraArgs": [],
},
}
}
}
```
4. Optional: to enable auto-completions for the relevant situations in Typst files, adjust Sublime's `"auto_complete_selector"` and/or `"auto_complete_triggers"` setting (`Preferences > Settings`); for example
3. Optional: to enable some useful commands provided by language server, add the following to the `*.sublime-commands`:
<!-- how to call: see https://github.com/Myriad-Dreamin/tinymist/blob/main/editors/vscode/src/extension.ts -->
```jsonc title="Packages/User/Default.sublime-commands"
[
// ...
{
"caption": "tinymist - Pin the main file to the currently opened document",
"command": "lsp_execute",
"args": {
"session_name": "tinymist",
"command_name": "tinymist.pinMain",
"command_args": ["${file}"]
}
},
{
"caption": "tinymist - Unpin the main file",
"command": "lsp_execute",
"args": {
"session_name": "tinymist",
"command_name": "tinymist.pinMain",
"command_args": [null]
}
},
]
```
### Typst-lsp
1. Install [typst-lsp](https://github.com/nvarner/typst-lsp/releases).
2. Open `Preferences > Package Settings > LSP > Settings` and add the `"typst-lsp"` client configuration to the `"clients"`:
```jsonc
{
"auto_complete_triggers":
[
{"selector": "text.html, text.xml", "characters": "<"},
{"selector": "punctuation.accessor", "rhs_empty": true},
{"selector": "text.typst", "characters": "#", "rhs_empty": true},
],
"clients": {
"typst-lsp": {
"enabled": true,
"command": ["path/to/typst-lsp"], // adjust this path according to your platform/setup
"selector": "text.typst"
}
}
}
```
5. Optional: to enable some useful commands provided by language server, add the following to the `*.sublime-commands`:
3. Optional: to enable some useful commands provided by language server, add the following to the `*.sublime-commands`:
<!-- how to call: see https://github.com/nvarner/typst-lsp/blob/master/editors/vscode/src/extension.ts -->
```jsonc title="Packages/User/Default.sublime-commands"
Expand Down
4 changes: 2 additions & 2 deletions plugin/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .core.edit import apply_text_edits
from .core.logging import debug
from .core.promise import Promise
from .core.protocol import CompletionEditRange
from .core.protocol import EditRangeWithInsertReplace
from .core.protocol import CompletionItem
from .core.protocol import CompletionItemDefaults
from .core.protocol import CompletionItemKind
Expand Down Expand Up @@ -127,7 +127,7 @@ def is_range(val: Any) -> TypeGuard[Range]:
return isinstance(val, dict) and 'start' in val and 'end' in val


def is_edit_range(val: Any) -> TypeGuard[CompletionEditRange]:
def is_edit_range(val: Any) -> TypeGuard[EditRangeWithInsertReplace]:
return isinstance(val, dict) and 'insert' in val and 'replace' in val


Expand Down
11 changes: 8 additions & 3 deletions plugin/core/edit.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import annotations
from .logging import debug
from .protocol import AnnotatedTextEdit
from .protocol import Position
from .protocol import TextEdit
from .protocol import UINT_MAX
from .protocol import WorkspaceEdit
from typing import Dict, List, Optional, Tuple
from typing import Dict, List, Optional, Tuple, Union
import sublime


WorkspaceChanges = Dict[str, Tuple[List[TextEdit], Optional[int]]]
WorkspaceChanges = Dict[str, Tuple[List[Union[TextEdit, AnnotatedTextEdit]], Optional[int]]]


def parse_workspace_edit(workspace_edit: WorkspaceEdit) -> WorkspaceChanges:
Expand All @@ -24,7 +25,11 @@ def parse_workspace_edit(workspace_edit: WorkspaceEdit) -> WorkspaceChanges:
uri = text_document['uri']
version = text_document.get('version')
edits = document_change.get('edits')
changes.setdefault(uri, ([], version))[0].extend(edits)
for edit in edits:
if 'snippet' in edit:
debug('Ignoring unsupported SnippetTextEdit')
continue
changes.setdefault(uri, ([], version))[0].append(edit)
else:
raw_changes = workspace_edit.get('changes')
if isinstance(raw_changes, dict):
Expand Down
Loading

0 comments on commit 21f1bf7

Please sign in to comment.