Skip to content

Commit

Permalink
Merge pull request #980 from skbitsp/sk-lsp
Browse files Browse the repository at this point in the history
Adding foreign code extractors for spark sql and exporting required classes
  • Loading branch information
krassowski authored Sep 20, 2023
2 parents dc46506 + 95433f0 commit a4d9e95
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion atest/04_Interface/DiagnosticsPanel.robot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Test Tags ui:notebook aspect:ls:features


*** Variables ***
${DIAGNOSTIC MESSAGE R} Closing curly-braces should always be on their own line
${DIAGNOSTIC MESSAGE R} Opening curly braces should never go on their own line and should always be followed by a new line
${DIAGNOSTIC MESSAGE} trailing whitespace
${DIAGNOSTIC} W291 trailing whitespace (pycodestyle)
${EXPECTED_COUNT} 4
Expand Down
6 changes: 6 additions & 0 deletions packages/jupyterlab-lsp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
/** General public tokens, including lumino Tokens and namespaces */
export * from './tokens';

/** Export the required classes */
export { FileEditorAdapter } from './adapters/file_editor/file_editor';
export { FileEditorContextMenuEntryPoint } from './adapters/file_editor';
export { PositionConverter } from './converter';
export { VirtualDocument } from './virtual/document';

/** Generated JSON Schema types for server responses and settings */
export * as SCHEMA from './_schema';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ export let foreign_code_extractors: IForeignCodeExtractorsRegistry = {
foreign_capture_groups: [1],
is_standalone: false,
file_extension: 'sql'
}),
new RegExpForeignCodeExtractor({
language: 'sql',
pattern: `^%%spark -c sql(?: (?:${SQL_URL_PATTERN}|${COMMAND_PATTERN}|(?:\\w+ << )|(?:\\w+@\\w+)))?\n?((?:.+\n)?(?:[^]*))`,
foreign_capture_groups: [1],
is_standalone: true,
file_extension: 'sql'
}),
new RegExpForeignCodeExtractor({
language: 'sql',
pattern: `(?:^|\n)%spark -c sql (?:${SQL_URL_PATTERN}|${COMMAND_PATTERN}|(.*))\n?`,
foreign_capture_groups: [1],
is_standalone: false,
file_extension: 'sql'
})
]
};
2 changes: 1 addition & 1 deletion python_packages/jupyter_lsp/jupyter_lsp/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LanguageServerWebSocketHandler( # type: ignore
):
"""Setup tornado websocket to route to language server sessions"""

language_server = None # type: Optional[Text]
language_server: Optional[Text] = None

async def open(self, language_server):
await self.manager.ready()
Expand Down
21 changes: 12 additions & 9 deletions python_packages/jupyter_lsp/jupyter_lsp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
)


_SessionDict = Dict[Tuple[Text], LanguageServerSession]


class LanguageServerManager(LanguageServerManagerAPI):
"""Manage language servers"""

Expand All @@ -61,17 +64,17 @@ class LanguageServerManager(LanguageServerManagerAPI):
config=True
) # type: KeyedLanguageServerSpecs

autodetect = Bool(
autodetect: bool = Bool( # type:ignore[assignment]
True, help=_("try to find known language servers in sys.prefix (and elsewhere)")
).tag(
config=True
) # type: bool
)

sessions = Dict_( # type:ignore[assignment]
sessions: _SessionDict = Dict_( # type:ignore[assignment]
trait=Instance(LanguageServerSession),
default_value={},
help="sessions keyed by language server name",
) # type: Dict[Tuple[Text], LanguageServerSession]
)

virtual_documents_dir = Unicode(
help="""Path to virtual documents relative to the content manager root
Expand Down Expand Up @@ -99,8 +102,8 @@ def _default_virtual_documents_dir(self):
return os.getenv("JP_LSP_VIRTUAL_DIR", ".virtual_documents")

@default("conf_d_language_servers")
def _default_conf_d_language_servers(self):
language_servers = {} # type: KeyedLanguageServerSpecs
def _default_conf_d_language_servers(self) -> KeyedLanguageServerSpecs:
language_servers: KeyedLanguageServerSpecs = {}

manager = ConfigManager(read_config_path=jupyter_config_path())

Expand All @@ -113,10 +116,10 @@ def _default_conf_d_language_servers(self):

return language_servers

def __init__(self, **kwargs):
def __init__(self, **kwargs: Dict):
"""Before starting, perform all necessary configuration"""
self.all_language_servers: KeyedLanguageServerSpecs = {}
self._language_servers_from_config = {}
self._language_servers_from_config: KeyedLanguageServerSpecs = {}
super().__init__(**kwargs)

def initialize(self, *args, **kwargs):
Expand Down Expand Up @@ -253,7 +256,7 @@ def _autodetect_language_servers(self, only_installed: bool):

for ep in _entry_points or []:
try:
spec_finder = ep.load() # type: SpecMaker
spec_finder: SpecMaker = ep.load()
except Exception as err: # pragma: no cover
self.log.warning(
_("Failed to load language server spec finder `{}`: \n{}").format(
Expand Down
5 changes: 2 additions & 3 deletions python_packages/jupyter_lsp/jupyter_lsp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ class MessageScope(enum.Enum):
class MessageListener(object):
"""A base listener implementation"""

listener = None # type: HandlerListenerCallback
language_server = None # type: Optional[Pattern[Text]]
method = None # type: Optional[Pattern[Text]]
language_server: Optional[Pattern[Text]] = None
method: Optional[Pattern[Text]] = None

def __init__(
self,
Expand Down

0 comments on commit a4d9e95

Please sign in to comment.