Skip to content

Commit

Permalink
lsp-devtools: Linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Oct 6, 2023
1 parent b06017d commit d640561
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ repos:
- aiosqlite
- attrs
- importlib-resources
- platformdirs
- pygls
- stamina
- textual
- types-appdirs
- websockets
files: 'lib/lsp-devtools/lsp_devtools/.*\.py'
2 changes: 1 addition & 1 deletion lib/lsp-devtools/lsp_devtools/agent/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def start_tcp(self, host: str, port: int):
with attempt:
reader, writer = await asyncio.open_connection(host, port)

self.protocol.connection_made(writer)
self.protocol.connection_made(writer) # type: ignore[arg-type]
connection = asyncio.create_task(
aio_readline(self._stop_event, reader, self.protocol.data_received)
)
Expand Down
6 changes: 5 additions & 1 deletion lib/lsp-devtools/lsp_devtools/agent/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from lsp_devtools.agent.protocol import AgentProtocol
from lsp_devtools.agent.protocol import MessageText
from lsp_devtools.database import Database


class AgentServer(Server):
Expand All @@ -27,6 +28,9 @@ def __init__(self, *args, **kwargs):
kwargs["converter_factory"] = default_converter

super().__init__(*args, **kwargs)

self.db: Optional[Database] = None

self._client_buffer = []
self._server_buffer = []
self._stop_event = threading.Event()
Expand All @@ -35,7 +39,7 @@ def __init__(self, *args, **kwargs):
def feature(self, feature_name: str, options: Optional[Any] = None):
return self.lsp.fm.feature(feature_name, options)

async def start_tcp(self, host: str, port: int) -> None:
async def start_tcp(self, host: str, port: int) -> None: # type: ignore[override]
async def handle_client(reader, writer):
self.lsp.connection_made(writer)
await aio_readline(self._stop_event, reader, self.lsp.data_received)
Expand Down
5 changes: 0 additions & 5 deletions lib/lsp-devtools/lsp_devtools/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
import os
import pathlib
from typing import List
from typing import Optional
from typing import Set
from uuid import uuid4

import platformdirs
from lsprotocol import types
from pygls import uris as uri
from pygls.capabilities import get_capability
from textual import events
from textual import log
from textual import on
from textual.app import App
from textual.app import ComposeResult
Expand All @@ -22,7 +18,6 @@
from textual.widgets import DirectoryTree
from textual.widgets import Footer
from textual.widgets import Header
from textual.widgets import TextArea

from lsp_devtools.agent import logger
from lsp_devtools.database import Database
Expand Down
12 changes: 9 additions & 3 deletions lib/lsp-devtools/lsp_devtools/client/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def on_blur(self, event: events.Blur):
def action_dismiss(self):
self.remove()
if self.parent:
self.app.set_focus(self.parent)
self.app.set_focus(self.parent) # type: ignore


class TextEditor(TextArea):
Expand All @@ -65,7 +65,9 @@ def __init__(self, lsp_client: LanguageClient, *args, **kwargs):
@property
def completion_triggers(self):
return get_capability(
self.capabilities, "completion_provider.trigger_characters", set()
self.capabilities, # type: ignore
"completion_provider.trigger_characters",
set(),
)

def open_file(self, path: pathlib.Path):
Expand Down Expand Up @@ -124,6 +126,10 @@ def edit(self, edit):

def trigger_completion(self, line: int, character: int):
"""Trigger completion at the given location."""

if self.uri is None:
return

task = asyncio.create_task(
self.lsp_client.text_document_completion_async(
types.CompletionParams(
Expand Down Expand Up @@ -152,4 +158,4 @@ def show_completions(self, task: asyncio.Task):
@on(OptionList.OptionSelected)
def completion_selected(self, event: OptionList.OptionSelected):
log(f"{event.option} was selected!")
event.option_list.action_dismiss()
event.option_list.action_dismiss() # type: ignore
1 change: 0 additions & 1 deletion lib/lsp-devtools/lsp_devtools/client/lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pygls.protocol import LanguageServerProtocol

from lsp_devtools.agent import logger
from lsp_devtools.database import Database

VERSION = importlib.metadata.version("lsp-devtools")

Expand Down
13 changes: 8 additions & 5 deletions lib/lsp-devtools/lsp_devtools/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import pathlib
import sys
from contextlib import asynccontextmanager
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import Set
from uuid import uuid4

import aiosqlite
from textual import log
from textual.app import App
from textual.message import Message

from lsp_devtools.handlers import LspMessage
Expand All @@ -29,7 +32,7 @@ class Update(Message):
def __init__(self, dbpath: Optional[pathlib.Path] = None):
self.dbpath = dbpath or ":memory:"
self.db: Optional[aiosqlite.Connection] = None
self.app = None
self.app: Optional[App] = None
self._handlers: Dict[str, set] = {}

async def close(self):
Expand Down Expand Up @@ -104,8 +107,8 @@ async def get_messages(
"""

base_query = "SELECT rowid, * FROM protocol"
where = []
parameters = []
where: List[str] = []
parameters: List[Any] = []

if session:
where.append("session = ?")
Expand Down Expand Up @@ -153,7 +156,7 @@ def __init__(self, db: Database, *args, session=None, **kwargs):
self._tasks: Set[asyncio.Task] = set()

def emit(self, record: logging.LogRecord):
body = json.loads(record.args[0])
body = json.loads(record.args[0]) # type: ignore
task = asyncio.create_task(
self.db.add_message(
self.session, record.created, record.__dict__["source"], body
Expand Down
10 changes: 6 additions & 4 deletions lib/lsp-devtools/lsp_devtools/inspector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
from typing import Any
from typing import Dict
from typing import List
from typing import Optional

import platformdirs
from rich.highlighter import ReprHighlighter
from rich.text import Text
from textual import events
from textual import log
from textual import on
from textual.app import App
from textual.app import ComposeResult
Expand Down Expand Up @@ -117,7 +116,7 @@ def show_object(self, event: DataTable.RowHighlighted):

def _get_query_params(self):
"""Return the set of query parameters to use when populating the table."""
query = dict(max_row=self.max_row)
query: Dict[str, Any] = dict(max_row=self.max_row)

if self.session is not None:
query["session"] = self.session
Expand Down Expand Up @@ -243,7 +242,10 @@ async def handle_message(ls: AgentServer, message: MessageText):
message_buf.clear()

rpc = json.loads(body)
await ls.db.add_message(message.session, message.timestamp, message.source, rpc)
if ls.db is not None:
await ls.db.add_message(
message.session, message.timestamp, message.source, rpc
)


def setup_server(db: Database):
Expand Down

0 comments on commit d640561

Please sign in to comment.