Skip to content

Commit

Permalink
Replace document_highlight_scopes setting with better default scopes (#…
Browse files Browse the repository at this point in the history
…1585)

* Replace document_highlight_scopes setting with better default scopes
* Use region scopes for documentHighlight and remove border for fill style
* Add back markup scopes for diagnostic severities

This removes the user setting for the scopes used to color highlighted
regions of the textDocument/documentHighlight request. Users (or color
scheme authors) can configure their desired style via rules in the color
scheme instead. To easily allow fine-tuned colors, the more specific
scopes `markup.highlight.{text|read|write}.lsp` were added to the
corresponding DocumentHighlightKinds.

Additionally, the `Unknown` kind was removed, because it doesn't exist
in the specification. Complying with the spec, the default kind `Text`
is used now in case the highlight kind is omitted in the response.
  • Loading branch information
jwortmann authored Feb 19, 2021
1 parent ffef40e commit 4610a1b
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 65 deletions.
7 changes: 0 additions & 7 deletions LSP.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@
// When set to the empty string (""), no document highlighting is requested.
"document_highlight_style": "underline",

"document_highlight_scopes": {
"unknown": "text",
"text": "text",
"read": "markup.inserted",
"write": "markup.changed"
},

// Gutter marker for code diagnostics.
// Valid values are "dot", "circle", "bookmark", "sign" or ""
"diagnostics_gutter_marker": "dot",
Expand Down
47 changes: 46 additions & 1 deletion docs/src/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,56 @@ Add these settings to LSP settings, your Sublime settings, Syntax-specific setti
* `diagnostics_highlight_style` `"underline"` *highlight style of code diagnostics: "box", "underline", "stippled", "squiggly" or ""*
* `highlight_active_signature_parameter`: *highlight the active parameter of the currently active signature*
* `document_highlight_style`: *document highlight style: "box", "underline", "stippled", "squiggly" or ""*
* `document_highlight_scopes`: *customize your sublime text scopes for document highlighting*
* `diagnostics_gutter_marker` `"dot"` *gutter marker for code diagnostics: "dot", "circle", "bookmark", "sign" or ""*
* `show_symbol_action_links` `false` *show links to symbol actions like go to, references and rename in the hover popup*
* `disabled_capabilities`, `[]` *Turn off client capabilities (features): "hover", "completion", "documentHighlight", "colorProvider", "signatureHelp", "codeLensProvider", "codeActionProvider"*
* `log_debug` `false` *show debug logging in the sublime console*
* `log_server` `[]` *log communication from and to language servers*
* `log_stderr` `false` *show language server stderr output in the console*
* `log_max_size` `8192` *max number of characters of payloads to print*

### Color configurations

Some features use TextMate scopes to control the colors (underline, background or text color) of styled regions in a document or popup.
Colors can be customized by adding a rule for these scopes into your color scheme, see https://www.sublimetext.com/docs/3/color_schemes.html#customization.

The following tables give an overview about the scope names used by LSP.

#### Document Highlights

!!! info "This feature is only available if the server has the *documentHighlightProvider* capability."
Highlights other occurrences of the symbol at a given cursor position.

| scope | DocumentHighlightKind | description |
| ----- | --------------------- | ----------- |
| `markup.highlight.text.lsp` | Text | A textual occurrence |
| `markup.highlight.read.lsp` | Read | Read-access of a symbol, like reading a variable |
| `markup.highlight.write.lsp` | Write | Write-access of a symbol, like writing to a variable |

!!! note
If `document_highlight_style` is set to "fill" in the LSP settings, the highlighting color can be controlled via the "background" color from a color scheme rule for the listed scopes.

#### Diagnostics

| scope | DiagnosticSeverity | description |
| ----- | ------------------ | ----------- |
| `markup.error.lsp` | Error | Reports an error |
| `markup.warning.lsp` | Warning | Reports a warning |
| `markup.info.lsp` | Information | Reports an information |
| `markup.info.hint.lsp` | Hint | Reports a hint |

!!! note
If `diagnostics_highlight_style` is set to "fill" in the LSP settings, the highlighting color can be controlled via the "background" color from a color scheme rule for the listed scopes.

#### Signature Help

| scope | description |
| ----- | ----------- |
| `entity.name.function.sighelp.lsp` | Function name in the signature help popup |
| `variable.parameter.sighelp.lsp` | Function argument in the signature help popup |

#### Code Lens

| scope | description |
| ----- | ----------- |
| `markup.codelens.accent` | Accent color for code lens annotations |
1 change: 0 additions & 1 deletion plugin/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class InsertTextFormat:


class DocumentHighlightKind:
Unknown = 0
Text = 1
Read = 2
Write = 3
Expand Down
4 changes: 1 addition & 3 deletions plugin/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def run() -> None:
def _settings_style_to_add_regions_flag(style: str) -> int:
flags = 0
if style == "fill":
pass
flags = sublime.DRAW_NO_OUTLINE
elif style == "box":
flags = sublime.DRAW_NO_FILL
else:
Expand Down Expand Up @@ -155,7 +155,6 @@ class Settings:
diagnostics_highlight_style = None # type: str
diagnostics_panel_include_severity_level = None # type: int
disabled_capabilities = None # type: List[str]
document_highlight_scopes = None # type: Dict[str, str]
document_highlight_style = None # type: str
inhibit_snippet_completions = None # type: bool
inhibit_word_completions = None # type: bool
Expand Down Expand Up @@ -191,7 +190,6 @@ def r(name: str, default: Union[bool, int, str, list, dict]) -> None:
r("diagnostics_highlight_style", "underline")
r("diagnostics_panel_include_severity_level", 4)
r("disabled_capabilities", [])
r("document_highlight_scopes", {"unknown": "text", "text": "text", "read": "markup.inserted", "write": "markup.changed"}) # noqa
r("document_highlight_style", "stippled")
r("log_debug", False)
r("log_max_size", 8 * 1024)
Expand Down
10 changes: 5 additions & 5 deletions plugin/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import tempfile

DIAGNOSTIC_SEVERITY = [
# Kind CSS class Scope for color Icon resource
("error", "errors", "region.redish", "Packages/LSP/icons/error.png"),
("warning", "warnings", "region.yellowish", "Packages/LSP/icons/warning.png"),
("info", "info", "region.bluish", "Packages/LSP/icons/info.png"),
("hint", "hints", "region.bluish", "Packages/LSP/icons/info.png"),
# Kind CSS class Scope for color Icon resource
("error", "errors", "region.redish markup.error.lsp", "Packages/LSP/icons/error.png"),
("warning", "warnings", "region.yellowish markup.warning.lsp", "Packages/LSP/icons/warning.png"),
("info", "info", "region.bluish markup.info.lsp", "Packages/LSP/icons/info.png"),
("hint", "hints", "region.bluish markup.info.hint.lsp", "Packages/LSP/icons/info.png"),
]

# The scope names mainly come from http://www.sublimetext.com/docs/3/scope_naming.html
Expand Down
40 changes: 25 additions & 15 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@
SUBLIME_WORD_MASK = 515

_kind2name = {
DocumentHighlightKind.Unknown: "unknown",
DocumentHighlightKind.Text: "text",
DocumentHighlightKind.Read: "read",
DocumentHighlightKind.Write: "write"
}

_kind2scope = {
DocumentHighlightKind.Text: "region.bluish markup.highlight.text.lsp",
DocumentHighlightKind.Read: "region.greenish markup.highlight.read.lsp",
DocumentHighlightKind.Write: "region.yellowish markup.highlight.write.lsp"
}

ResolveCompletionsFn = Callable[[List[sublime.CompletionItem], int], None]


Expand Down Expand Up @@ -559,12 +564,12 @@ def _unresolved_code_lenses(
# --- textDocument/documentHighlight -------------------------------------------------------------------------------

def _clear_highlight_regions(self) -> None:
for kind in userprefs().document_highlight_scopes.keys():
self.view.erase_regions("lsp_highlight_{}".format(kind))
for kind in range(1, 4):
self.view.erase_regions("lsp_highlight_{}".format(_kind2name[kind]))

def _is_in_higlighted_region(self, point: int) -> bool:
for kind in userprefs().document_highlight_scopes.keys():
regions = self.view.get_regions("lsp_highlight_{}".format(kind))
for kind in range(1, 4):
regions = self.view.get_regions("lsp_highlight_{}".format(_kind2name[kind]))
for r in regions:
if r.contains(point):
return True
Expand All @@ -584,23 +589,28 @@ def _on_highlights(self, response: Optional[List]) -> None:
if not response:
self._clear_highlight_regions()
return
kind2regions = {} # type: Dict[str, List[sublime.Region]]
for kind in range(0, 4):
kind2regions[_kind2name[kind]] = []
kind2regions = {} # type: Dict[int, List[sublime.Region]]
for kind in range(1, 4):
kind2regions[kind] = []
for highlight in response:
r = range_to_region(Range.from_lsp(highlight["range"]), self.view)
kind = highlight.get("kind", DocumentHighlightKind.Unknown)
if kind is not None:
kind2regions[_kind2name[kind]].append(r)
kind = highlight.get("kind", DocumentHighlightKind.Text)
if kind in kind2regions:
kind2regions[kind].append(r)
else:
debug("unknown DocumentHighlightKind", kind)

def render_highlights_on_main_thread() -> None:
self._clear_highlight_regions()
flags = userprefs().document_highlight_style_to_add_regions_flags()
for kind_str, regions in kind2regions.items():
for kind, regions in kind2regions.items():
if regions:
scope = userprefs().document_highlight_scopes.get(kind_str, None)
if scope:
self.view.add_regions("lsp_highlight_{}".format(kind_str), regions, scope=scope, flags=flags)
scope = _kind2scope[kind]
self.view.add_regions(
"lsp_highlight_{}".format(_kind2name[kind]),
regions,
scope=scope,
flags=flags)

sublime.set_timeout(render_highlights_on_main_thread)

Expand Down
33 changes: 0 additions & 33 deletions sublime-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,39 +253,6 @@
"default": "underline",
"markdownDescription": "Highlighting style of `\"highlights\"`: accentuating nearby text entities that are related to the one under your cursor. When set to the empty string (`\"\"`), no diagnostics are shown in-line."
},
"document_highlight_scopes": {
"type": "object",
"properties": {
"unknown": {
"type": "string",
"default": "text",
"markdownDescription": "What Sublime Text scope should receive the LSP `\"unknown\"` scope?"
},
"text": {
"type": "string",
"default": "text",
"markdownDescription": "What Sublime Text scope should receive the LSP `\"text\"` scope?"
},
"read": {
"type": "string",
"default": "markup.inserted",
"markdownDescription": "What Sublime Text scope should receive the LSP `\"read\"` scope?"
},
"write": {
"type": "string",
"default": "markup.changed",
"markdownDescription": "What Sublime Text scope should receive the LSP `\"write\"` scope?"
},
"additionalProperties": false
},
"default": {
"unknown": "text",
"text": "text",
"read": "markup.inserted",
"write": "markup.changed"
},
"markdownDescription": "Map the LSP scopes `\"unknown\"`, `\"text\"`, `\"read\"` and `\"write\"` to the given Sublime Text scopes. You can use those scopes in your .sublime-color-scheme to color the document highlight scopes."
},
"diagnostics_gutter_marker": {
"enum": [
"dot",
Expand Down

0 comments on commit 4610a1b

Please sign in to comment.