Skip to content

Commit

Permalink
feat: python cell lsp (#29)
Browse files Browse the repository at this point in the history
* feat: python cell lsp

* feat: python cell lsp
  • Loading branch information
myzxlin authored Feb 29, 2024
1 parent 2ddf564 commit 87bbfc1
Show file tree
Hide file tree
Showing 12 changed files with 396 additions and 226 deletions.
10 changes: 5 additions & 5 deletions packages/secretnote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"dependencies": {
"@antv/s2": "^1.52.0",
"@codemirror/lang-python": "^6.1.2",
"@difizen/libro-jupyter": "^0.1.14",
"@difizen/mana-app": "^0.1.9",
"@difizen/mana-common": "^0.1.9",
"@difizen/mana-l10n": "^0.1.9",
"@difizen/mana-react": "^0.1.9",
"@difizen/libro-jupyter": "^0.1.22",
"@difizen/mana-app": "^0.1.10",
"@difizen/mana-common": "^0.1.10",
"@difizen/mana-l10n": "^0.1.10",
"@difizen/mana-react": "^0.1.10",
"@kanaries/web-data-loader": "^0.1.7",
"@lumino/polling": "^1.11.4",
"@rjsf/antd": "^5.7.3",
Expand Down
5 changes: 2 additions & 3 deletions packages/secretnote/src/modules/editor/cell/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ export class SecretNoteCodeCellView extends JupyterCodeCellView {
@inject(ViewOption) options: CellViewOptions,
@inject(CellService) cellService: CellService,
@inject(ViewManager) viewManager: ViewManager,
@inject(CodeEditorManager) codeEditorManager: CodeEditorManager,
@inject(SecretNoteServerManager) serverManager: SecretNoteServerManager,
@inject(SecretNoteKernelManager) kernelManager: SecretNoteKernelManager,
@inject(ILSPDocumentConnectionManager) lsp: ILSPDocumentConnectionManager,
@inject(CodeEditorManager) codeEditorManager: CodeEditorManager,
) {
super(options, cellService, viewManager, lsp, codeEditorManager);
super(options, cellService, viewManager, codeEditorManager);
this.serverManager = serverManager;
this.kernelManager = kernelManager;
this.parties = this.getInitializedParties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class SecretNoteContentContribution implements ContentContribution {
if (currentFileContents) {
currentFileContents.content.nbformat_minor = 5;
secretNoteModel.currentFileContents = currentFileContents;
secretNoteModel.filePath = currentFileContents.path;

if (!secretNoteModel.quickEditMode && !secretNoteModel.readOnly) {
secretNoteModel.startKernelConnection();
Expand Down
7 changes: 5 additions & 2 deletions packages/secretnote/src/modules/editor/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export class SecretNoteModel extends LibroModel {
kernelConnections: IKernelConnection[] = [];

@prop()
lspEnabled = false;
filePath = '';

@prop()
lspEnabled = true;

get isKernelIdle() {
return this.kernelConnections.every((item) => {
Expand All @@ -63,7 +66,7 @@ export class SecretNoteModel extends LibroModel {
this.commandRegistry = commandRegistry;
this.serverManager.onServerAdded(this.onServerAdded.bind(this));
this.serverManager.onServerDeleted(this.onServerDeleted.bind(this));
this.onContentChanged(this.autoSave.bind(this));
this.onSourceChanged(this.autoSave.bind(this));
}

async startKernelConnection() {
Expand Down
4 changes: 2 additions & 2 deletions packages/secretnote/src/modules/notebook/editor-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export const EditorComponent = () => {
setLibroView(v);
return;
})
.catch(() => {
//
.catch((e) => {
console.error('getOrCreateView fail', e);
});
}
}, [currentNotebookFile, instance]);
Expand Down
2 changes: 1 addition & 1 deletion packages/secretnote/src/modules/scql-editor/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class SecretNoteModel extends LibroModel {
this.contentsManager = contentsManager;
this.modalService = modalService;
this.commandRegistry = commandRegistry;
this.onContentChanged(this.autoSave.bind(this));
this.onSourceChanged(this.autoSave.bind(this));
}

async saveNotebookContent(): Promise<void> {
Expand Down
548 changes: 341 additions & 207 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions pyprojects/secretnote/.jupyter/config_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,29 @@

c.ServerApp.root_dir = "../../.secretnote"

c.LanguageServerManager.autodetect = False

c.LanguageServerManager.language_servers = {
"pyright-extended": {
"ruff-lsp": {
# if installed as a binary
"argv": [
"ruff-lsp",
],
"languages": ["python"],
"version": 2,
"mime_types": ["text/x-python"],
"display_name": "ruff-lsp",
},
"libro-analyzer": {
# if installed as a binary
"argv": [
"node",
"node_modules/@replit/pyright-extended/langserver.index.js",
"node_modules/@difizen/libro-analyzer/index.js",
"--stdio",
],
"languages": ["python"],
"version": 2,
"mime_types": ["text/x-python"],
"display_name": "pyright-extended",
"display_name": "libro-analyzer",
},
}
1 change: 1 addition & 0 deletions pyprojects/secretnote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"build": "nx build:py"
},
"devDependencies": {
"@difizen/libro-analyzer": "^0.1.0",
"@secretflow/secretnote": "workspace:^",
"@secretflow/secretnote-ui": "workspace:^"
}
Expand Down
2 changes: 2 additions & 0 deletions pyprojects/secretnote/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ dependencies = [
"stack_data>=0.6.3",
"tqdm>=4.66.1",
"dataset>=1.6.2",
"ruff-lsp==0.0.50",
"python-lsp-server==1.8.2",
]
description = "Notebook suite for SecretFlow"
dynamic = ["version"]
Expand Down
12 changes: 10 additions & 2 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# last locked with the following flags:
# pre: false
# features: []
# all-features: true
# all-features: false
# with-sources: false

-e file:.
Expand Down Expand Up @@ -33,6 +33,7 @@ black==24.1.1
bleach==6.1.0
blessed==1.20.0
cachetools==5.3.2
cattrs==23.2.3
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
Expand All @@ -53,6 +54,7 @@ deprecated==1.2.14
dill==0.3.8
distlib==0.3.8
dnspython==2.5.0
docstring-to-markdown==0.15
editables==0.5
email-validator==2.1.0.post1
emoji==1.7.0
Expand Down Expand Up @@ -103,7 +105,7 @@ jsonschema-specifications==2023.12.1
jupyter-client==8.6.0
jupyter-core==5.7.1
jupyter-events==0.9.0
jupyter-lsp==2.2.2
jupyter-lsp==2.2.0
jupyter-resource-usage==1.0.1
jupyter-server==2.12.5
jupyter-server-terminals==0.5.2
Expand All @@ -118,6 +120,7 @@ lightning-utilities==0.10.1
llvmlite==0.40.1
logging-tree==1.9
loguru==0.7.2
lsprotocol==2023.0.1
mako==1.3.2
markdown-it-py==3.0.0
markupsafe==2.1.4
Expand Down Expand Up @@ -177,12 +180,15 @@ pyasn1==0.5.1
pyasn1-modules==0.3.0
pycparser==2.21
pydantic==1.10.14
pygls==1.3.0
pygments==2.17.2
pyparsing==3.1.1
pytest==8.0.0
pytest-cov==4.1.0
python-dateutil==2.8.2
python-json-logger==2.0.7
python-lsp-jsonrpc==1.1.2
python-lsp-server==1.8.2
pytz==2024.1
pyyaml==6.0.1
pyzmq==25.1.2
Expand All @@ -196,6 +202,7 @@ rich==13.7.0
rpds-py==0.17.1
rsa==4.9
ruff==0.2.0
ruff-lsp==0.0.50
safetensors==0.4.2
scikit-learn==1.1.3
scipy==1.10.1
Expand Down Expand Up @@ -236,6 +243,7 @@ transformers==4.37.2
trove-classifiers==2024.1.31
types-python-dateutil==2.8.19.20240106
typing-extensions==4.9.0
ujson==5.9.0
uri-template==1.3.0
urllib3==2.2.0
userpath==1.9.1
Expand Down
12 changes: 11 additions & 1 deletion requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# last locked with the following flags:
# pre: false
# features: []
# all-features: true
# all-features: false
# with-sources: false

-e file:.
Expand All @@ -28,6 +28,7 @@ beautifulsoup4==4.12.3
bleach==6.1.0
blessed==1.20.0
cachetools==5.3.2
cattrs==23.2.3
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
Expand All @@ -40,6 +41,7 @@ decorator==5.1.1
defusedxml==0.7.1
deprecated==1.2.14
distlib==0.3.8
docstring-to-markdown==0.15
exceptiongroup==1.2.0
executing==2.0.1
fastjsonschema==2.19.1
Expand Down Expand Up @@ -72,6 +74,7 @@ jupyter-server-terminals==0.5.2
jupyterlab-pygments==0.3.0
jupyterlab-widgets==3.0.9
loguru==0.7.2
lsprotocol==2023.0.1
mako==1.3.2
markdown-it-py==3.0.0
markupsafe==2.1.4
Expand Down Expand Up @@ -102,6 +105,7 @@ pexpect==4.9.0
pickleshare==0.7.5
pkgutil-resolve-name==1.3.10
platformdirs==3.11.0
pluggy==1.4.0
prometheus-client==0.19.0
prompt-toolkit==3.0.43
protobuf==4.25.2
Expand All @@ -113,9 +117,12 @@ pyasn1==0.5.1
pyasn1-modules==0.3.0
pycparser==2.21
pydantic==1.10.14
pygls==1.3.0
pygments==2.17.2
python-dateutil==2.8.2
python-json-logger==2.0.7
python-lsp-jsonrpc==1.1.2
python-lsp-server==1.8.2
pyyaml==6.0.1
pyzmq==25.1.2
ray==2.6.3
Expand All @@ -126,6 +133,8 @@ rfc3986-validator==0.1.1
rich==13.7.0
rpds-py==0.17.1
rsa==4.9
ruff==0.2.2
ruff-lsp==0.0.50
secretflow-ray==2.2.0
send2trash==1.8.2
six==1.16.0
Expand All @@ -141,6 +150,7 @@ tqdm==4.66.1
traitlets==5.14.1
types-python-dateutil==2.8.19.20240106
typing-extensions==4.9.0
ujson==5.9.0
uri-template==1.3.0
urllib3==2.2.0
virtualenv==20.21.0
Expand Down

0 comments on commit 87bbfc1

Please sign in to comment.