Skip to content
/ LSP Public
forked from sublimelsp/LSP

Commit

Permalink
Merge branch 'main' into jwortmann-call-hierarchy
Browse files Browse the repository at this point in the history
* main:
  workaround for View Listeners not being attached for new transient view (sublimelsp#2174)
  Make Document Symbols behavior more consistent with built-in Goto Symbol (sublimelsp#2166)
  docs: fsautocomplete config - remove redundant argument (sublimelsp#2165)
  Allow missing window/workDoneProgress/create request from the server (sublimelsp#2159)
  Use "plaintext" language ID for plain text files (sublimelsp#2164)
  Improve type annotations (sublimelsp#2162)
  Don't use "escapeall" extension when formatting with mdpopups (sublimelsp#2163)
  • Loading branch information
rchl committed Jan 22, 2023
2 parents d1950b6 + ff57279 commit fad24ed
Show file tree
Hide file tree
Showing 26 changed files with 332 additions and 201 deletions.
2 changes: 1 addition & 1 deletion docs/src/language_servers.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Follow installation instructions on [LSP-elm](https://github.com/sublimelsp/LSP-
"clients": {
"fsautocomplete": {
"enabled": true,
"command": ["fsautocomplete", "--background-service-enabled"],
"command": ["fsautocomplete"],
"selector": "source.fsharp",
"initializationOptions": {
"AutomaticWorkspaceInit": true
Expand Down
30 changes: 15 additions & 15 deletions language-ids.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,21 @@
"text.html.markdown.rmarkdown": "r", // https://github.com/REditorSupport/sublime-ide-r
"text.html.ngx": "html", // https://github.com/princemaple/ngx-html-syntax
"text.jinja": "html", // https://github.com/Sublime-Instincts/BetterJinja
"text.plain": "txt",
"text.plain.buildpacks": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.eslint": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.fastq": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.license": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.lnk": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.log": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.nodejs": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.pcb": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.ps": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.python": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.readme": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.ruby": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.sketch": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain.visualstudio": "txt", // https://github.com/SublimeText/AFileIcon
"text.plain": "plaintext",
"text.plain.buildpacks": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.eslint": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.fastq": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.license": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.lnk": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.log": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.nodejs": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.pcb": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.ps": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.python": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.readme": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.ruby": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.sketch": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plain.visualstudio": "plaintext", // https://github.com/SublimeText/AFileIcon
"text.plist": "xml", // https://bitbucket.org/fschwehn/sublime_plist
"text.xml.plist": "xml", // https://github.com/SublimeText/PackageDev
"text.xml.plist.textmate.preferences": "xml", // https://github.com/SublimeText/PackageDev
Expand Down
3 changes: 2 additions & 1 deletion plugin/code_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from .core.views import first_selection_region
from .core.views import format_code_actions_for_quick_panel
from .core.views import text_document_code_action_params
from .save_command import LspSaveCommand, SaveTask
from .save_command import LspSaveCommand
from .save_command import SaveTask
from abc import ABCMeta
from abc import abstractmethod
from functools import partial
Expand Down
4 changes: 3 additions & 1 deletion plugin/code_lens.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .core.protocol import CodeLens, CodeLensExtended, Error
from .core.protocol import CodeLens
from .core.protocol import CodeLensExtended
from .core.protocol import Error
from .core.typing import List, Tuple, Dict, Iterable, Generator, Union, cast
from .core.registry import LspTextCommand
from .core.registry import windows
Expand Down
73 changes: 73 additions & 0 deletions plugin/core/active_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from .sessions import SessionViewProtocol
from .progress import ProgressReporter
from .progress import ViewProgressReporter
from .progress import WindowProgressReporter
from .protocol import Request
from .typing import Any, Optional, Dict
from weakref import ref
import sublime


class ActiveRequest:
"""
Holds state per request.
"""

def __init__(self, sv: SessionViewProtocol, request_id: int, request: Request) -> None:
# sv is the parent object; there is no need to keep it alive explicitly.
self.weaksv = ref(sv)
self.request_id = request_id
self.request = request
self.progress = None # type: Optional[ProgressReporter]
# `request.progress` is either a boolean or a string. If it's a boolean, then that signals that the server does
# not support client-initiated progress. However, for some requests we still want to notify some kind of
# progress to the end-user. This is communicated by the boolean value being "True".
# If `request.progress` is a string, then this string is equal to the workDoneProgress token. In that case, the
# server should start reporting progress for this request. However, even if the server supports workDoneProgress
# then we still don't know for sure whether it will actually start reporting progress. So we still want to
# put a line in the status bar if the request takes a while even if the server promises to report progress.
if request.progress:
# Keep a weak reference because we don't want this delayed function to keep this object alive.
weakself = ref(self)

def show() -> None:
this = weakself()
# If the server supports client-initiated progress, then it should have sent a "progress begin"
# notification. In that case, `this.progress` should not be None. So if `this.progress` is None
# then the server didn't notify in a timely manner and we will start putting a line in the status bar
# about this request taking a long time (>200ms).
if this is not None and this.progress is None:
# If this object is still alive then that means the request hasn't finished yet after 200ms,
# so put a message in the status bar to notify that this request is still in progress.
this.progress = this._start_progress_reporter_async(this.request.method)

sublime.set_timeout_async(show, 200)

def _start_progress_reporter_async(
self,
title: str,
message: Optional[str] = None,
percentage: Optional[float] = None
) -> Optional[ProgressReporter]:
sv = self.weaksv()
if not sv:
return None
if self.request.view is not None:
key = "lspprogressview-{}-{}-{}".format(sv.session.config.name, self.request.view.id(), self.request_id)
return ViewProgressReporter(self.request.view, key, title, message, percentage)
else:
key = "lspprogresswindow-{}-{}-{}".format(sv.session.config.name, sv.session.window.id(), self.request_id)
return WindowProgressReporter(sv.session.window, key, title, message, percentage)

def update_progress_async(self, params: Dict[str, Any]) -> None:
value = params['value']
kind = value['kind']
message = value.get("message")
percentage = value.get("percentage")
if kind == 'begin':
title = value["title"]
# This would potentially overwrite the "manual" progress that activates after 200ms, which is OK.
self.progress = self._start_progress_reporter_async(title, message, percentage)
elif kind == 'report':
if self.progress:
self.progress(message, percentage)
7 changes: 5 additions & 2 deletions plugin/core/edit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from .logging import debug
from .open import open_file
from .promise import Promise
from .protocol import UINT_MAX, TextEdit as LspTextEdit, Position, WorkspaceEdit
from .protocol import Position
from .protocol import TextEdit
from .protocol import UINT_MAX
from .protocol import WorkspaceEdit
from .typing import List, Dict, Optional, Tuple
from functools import partial
import sublime
Expand Down Expand Up @@ -37,7 +40,7 @@ def parse_range(range: Position) -> Tuple[int, int]:
return range['line'], min(UINT_MAX, range['character'])


def parse_text_edit(text_edit: LspTextEdit, version: Optional[int] = None) -> TextEditTuple:
def parse_text_edit(text_edit: TextEdit, version: Optional[int] = None) -> TextEditTuple:
return (
parse_range(text_edit['range']['start']),
parse_range(text_edit['range']['end']),
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/open.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def open_file(
view = window.open_file(file, flags, group)
if not view.is_loading():
if was_already_open and (flags & sublime.SEMI_TRANSIENT):
# work-around bug https://github.com/sublimehq/sublime_text/issues/2411 where transient view might not get
# workaround bug https://github.com/sublimehq/sublime_text/issues/2411 where transient view might not get
# its view listeners initialized.
sublime_plugin.check_view_event_listeners(view) # type: ignore
# It's already loaded. Possibly already open in a tab.
Expand Down
48 changes: 30 additions & 18 deletions plugin/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -5861,55 +5861,55 @@ def __init__(
self.progress = progress # type: Union[bool, str]

@classmethod
def initialize(cls, params: Mapping[str, Any]) -> 'Request':
def initialize(cls, params: InitializeParams) -> 'Request':
return Request("initialize", params)

@classmethod
def complete(cls, params: Mapping[str, Any], view: sublime.View) -> 'Request':
def complete(cls, params: CompletionParams, view: sublime.View) -> 'Request':
return Request("textDocument/completion", params, view)

@classmethod
def signatureHelp(cls, params: Mapping[str, Any], view: sublime.View) -> 'Request':
def signatureHelp(cls, params: SignatureHelpParams, view: sublime.View) -> 'Request':
return Request("textDocument/signatureHelp", params, view)

@classmethod
def codeAction(cls, params: CodeActionParams, view: sublime.View) -> 'Request':
return Request("textDocument/codeAction", params, view)

@classmethod
def documentColor(cls, params: Mapping[str, Any], view: sublime.View) -> 'Request':
def documentColor(cls, params: DocumentColorParams, view: sublime.View) -> 'Request':
return Request('textDocument/documentColor', params, view)

@classmethod
def colorPresentation(cls, params: ColorPresentationParams, view: sublime.View) -> 'Request':
return Request('textDocument/colorPresentation', params, view)

@classmethod
def willSaveWaitUntil(cls, params: Mapping[str, Any], view: sublime.View) -> 'Request':
def willSaveWaitUntil(cls, params: WillSaveTextDocumentParams, view: sublime.View) -> 'Request':
return Request("textDocument/willSaveWaitUntil", params, view)

@classmethod
def documentSymbols(cls, params: DocumentSymbolParams, view: sublime.View) -> 'Request':
return Request("textDocument/documentSymbol", params, view, progress=True)

@classmethod
def documentHighlight(cls, params: Mapping[str, Any], view: sublime.View) -> 'Request':
def documentHighlight(cls, params: DocumentHighlightParams, view: sublime.View) -> 'Request':
return Request("textDocument/documentHighlight", params, view)

@classmethod
def documentLink(cls, params: Mapping[str, Any], view: sublime.View) -> 'Request':
def documentLink(cls, params: DocumentLinkParams, view: sublime.View) -> 'Request':
return Request("textDocument/documentLink", params, view)

@classmethod
def semanticTokensFull(cls, params: Mapping[str, Any], view: sublime.View) -> 'Request':
def semanticTokensFull(cls, params: SemanticTokensParams, view: sublime.View) -> 'Request':
return Request("textDocument/semanticTokens/full", params, view)

@classmethod
def semanticTokensFullDelta(cls, params: Mapping[str, Any], view: sublime.View) -> 'Request':
def semanticTokensFullDelta(cls, params: SemanticTokensDeltaParams, view: sublime.View) -> 'Request':
return Request("textDocument/semanticTokens/full/delta", params, view)

@classmethod
def semanticTokensRange(cls, params: Mapping[str, Any], view: sublime.View) -> 'Request':
def semanticTokensRange(cls, params: SemanticTokensRangeParams, view: sublime.View) -> 'Request':
return Request("textDocument/semanticTokens/range", params, view)

@classmethod
Expand Down Expand Up @@ -5940,6 +5940,18 @@ def inlayHint(cls, params: InlayHintParams, view: sublime.View) -> 'Request':
def resolveInlayHint(cls, params: InlayHint, view: sublime.View) -> 'Request':
return Request('inlayHint/resolve', params, view)

@classmethod
def rename(cls, params: RenameParams, view: sublime.View, progress: bool = False) -> 'Request':
return Request('textDocument/rename', params, view, progress)

@classmethod
def prepareRename(cls, params: PrepareRenameParams, view: sublime.View, progress: bool = False) -> 'Request':
return Request('textDocument/prepareRename', params, view, progress)

@classmethod
def selectionRange(cls, params: SelectionRangeParams) -> 'Request':
return Request('textDocument/selectionRange', params)

@classmethod
def workspaceSymbol(cls, params: WorkspaceSymbolParams) -> 'Request':
return Request("workspace/symbol", params, None, progress=True)
Expand Down Expand Up @@ -6015,35 +6027,35 @@ def initialized(cls) -> 'Notification':
return Notification("initialized", {})

@classmethod
def didOpen(cls, params: dict) -> 'Notification':
def didOpen(cls, params: DidOpenTextDocumentParams) -> 'Notification':
return Notification("textDocument/didOpen", params)

@classmethod
def didChange(cls, params: dict) -> 'Notification':
def didChange(cls, params: DidChangeTextDocumentParams) -> 'Notification':
return Notification("textDocument/didChange", params)

@classmethod
def willSave(cls, params: dict) -> 'Notification':
def willSave(cls, params: WillSaveTextDocumentParams) -> 'Notification':
return Notification("textDocument/willSave", params)

@classmethod
def didSave(cls, params: dict) -> 'Notification':
def didSave(cls, params: DidSaveTextDocumentParams) -> 'Notification':
return Notification("textDocument/didSave", params)

@classmethod
def didClose(cls, params: dict) -> 'Notification':
def didClose(cls, params: DidCloseTextDocumentParams) -> 'Notification':
return Notification("textDocument/didClose", params)

@classmethod
def didChangeConfiguration(cls, params: dict) -> 'Notification':
def didChangeConfiguration(cls, params: DidChangeConfigurationParams) -> 'Notification':
return Notification("workspace/didChangeConfiguration", params)

@classmethod
def didChangeWatchedFiles(cls, params: dict) -> 'Notification':
def didChangeWatchedFiles(cls, params: DidChangeWatchedFilesParams) -> 'Notification':
return Notification("workspace/didChangeWatchedFiles", params)

@classmethod
def didChangeWorkspaceFolders(cls, params: dict) -> 'Notification':
def didChangeWorkspaceFolders(cls, params: DidChangeWorkspaceFoldersParams) -> 'Notification':
return Notification("workspace/didChangeWorkspaceFolders", params)

@classmethod
Expand Down
Loading

0 comments on commit fad24ed

Please sign in to comment.