Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace document_highlight_scopes setting with better default scopes #1585

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not use abbreviation like "sighelp"?

Copy link
Member Author

@jwortmann jwortmann Feb 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added by @rwols in #1576. I do find it useful, so that it can be easily targeted by color schemes. Or do you mean write it out as e.g. "entity.name.function.signature-help.lsp" instead of "sighelp"?

But besides that, looking at the docs now, I recommend to change "markup.codelens.accent" to "markup.accent.codelens.lsp". The "markup.accent" looks general enough so it could be reused by other features than code lens, or other plugins too, and the "lsp" suffix to keep all scopes from LSP consistent.

Or maybe even better not to use a TextMate scope here, and instead use the "accent" color from the color scheme via var(--accent)? The related code for this is at

accent = self.view.style_for_scope("region.greenish markup.codelens.accent")["foreground"]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or do you mean write it out as e.g. "entity.name.function.signature-help.lsp" instead of "sighelp"?

Yeah I meant that, rename "sighelp" to "signature-help". (abbreviations are sometimes hard to understand)
But because this was already added I don't want to introduce breaking changes, so ignore this comment.

because this was recently added 11 feb. maybe worth reconsidering renaming... but again this is not a big deal.

| `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