Skip to content

Commit bd91d9a

Browse files
committed
feat: python cell lsp
1 parent 2ddf564 commit bd91d9a

File tree

12 files changed

+459
-238
lines changed

12 files changed

+459
-238
lines changed

packages/secretnote/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
"dependencies": {
2828
"@antv/s2": "^1.52.0",
2929
"@codemirror/lang-python": "^6.1.2",
30-
"@difizen/libro-jupyter": "^0.1.14",
31-
"@difizen/mana-app": "^0.1.9",
32-
"@difizen/mana-common": "^0.1.9",
33-
"@difizen/mana-l10n": "^0.1.9",
34-
"@difizen/mana-react": "^0.1.9",
30+
"@difizen/libro-jupyter": "^0.2.0",
31+
"@difizen/mana-app": "^0.1.10",
32+
"@difizen/mana-common": "^0.1.10",
33+
"@difizen/mana-l10n": "^0.1.10",
34+
"@difizen/mana-react": "^0.1.10",
3535
"@kanaries/web-data-loader": "^0.1.7",
3636
"@lumino/polling": "^1.11.4",
3737
"@rjsf/antd": "^5.7.3",

packages/secretnote/src/modules/editor/cell/view.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,11 @@ export class SecretNoteCodeCellView extends JupyterCodeCellView {
7575
@inject(ViewOption) options: CellViewOptions,
7676
@inject(CellService) cellService: CellService,
7777
@inject(ViewManager) viewManager: ViewManager,
78+
@inject(CodeEditorManager) codeEditorManager: CodeEditorManager,
7879
@inject(SecretNoteServerManager) serverManager: SecretNoteServerManager,
7980
@inject(SecretNoteKernelManager) kernelManager: SecretNoteKernelManager,
80-
@inject(ILSPDocumentConnectionManager) lsp: ILSPDocumentConnectionManager,
81-
@inject(CodeEditorManager) codeEditorManager: CodeEditorManager,
8281
) {
83-
super(options, cellService, viewManager, lsp, codeEditorManager);
82+
super(options, cellService, viewManager, codeEditorManager);
8483
this.serverManager = serverManager;
8584
this.kernelManager = kernelManager;
8685
this.parties = this.getInitializedParties();

packages/secretnote/src/modules/editor/contents/contents-contrib.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class SecretNoteContentContribution implements ContentContribution {
1818
if (currentFileContents) {
1919
currentFileContents.content.nbformat_minor = 5;
2020
secretNoteModel.currentFileContents = currentFileContents;
21+
secretNoteModel.filePath = currentFileContents.path;
2122

2223
if (!secretNoteModel.quickEditMode && !secretNoteModel.readOnly) {
2324
secretNoteModel.startKernelConnection();

packages/secretnote/src/modules/editor/model.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export class SecretNoteModel extends LibroModel {
3636
kernelConnections: IKernelConnection[] = [];
3737

3838
@prop()
39-
lspEnabled = false;
39+
filePath = '';
40+
41+
@prop()
42+
lspEnabled = true;
4043

4144
get isKernelIdle() {
4245
return this.kernelConnections.every((item) => {
@@ -63,7 +66,7 @@ export class SecretNoteModel extends LibroModel {
6366
this.commandRegistry = commandRegistry;
6467
this.serverManager.onServerAdded(this.onServerAdded.bind(this));
6568
this.serverManager.onServerDeleted(this.onServerDeleted.bind(this));
66-
this.onContentChanged(this.autoSave.bind(this));
69+
this.onSourceChanged(this.autoSave.bind(this));
6770
}
6871

6972
async startKernelConnection() {

packages/secretnote/src/modules/notebook/editor-view.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export const EditorComponent = () => {
4040
setLibroView(v);
4141
return;
4242
})
43-
.catch(() => {
44-
//
43+
.catch((e) => {
44+
console.error('getOrCreateView fail', e);
4545
});
4646
}
4747
}, [currentNotebookFile, instance]);

packages/secretnote/src/modules/scql-editor/model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class SecretNoteModel extends LibroModel {
3434
this.contentsManager = contentsManager;
3535
this.modalService = modalService;
3636
this.commandRegistry = commandRegistry;
37-
this.onContentChanged(this.autoSave.bind(this));
37+
this.onSourceChanged(this.autoSave.bind(this));
3838
}
3939

4040
async saveNotebookContent(): Promise<void> {

pnpm-lock.yaml

+404-219
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyprojects/secretnote/.jupyter/config_dev.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,29 @@
1919

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

22+
c.LanguageServerManager.autodetect = False
23+
2224
c.LanguageServerManager.language_servers = {
23-
"pyright-extended": {
25+
"ruff-lsp": {
26+
# if installed as a binary
27+
"argv": [
28+
"ruff-lsp",
29+
],
30+
"languages": ["python"],
31+
"version": 2,
32+
"mime_types": ["text/x-python"],
33+
"display_name": "ruff-lsp",
34+
},
35+
"libro-analyzer": {
2436
# if installed as a binary
2537
"argv": [
2638
"node",
27-
"node_modules/@replit/pyright-extended/langserver.index.js",
39+
"node_modules/@difizen/libro-analyzer/index.js",
2840
"--stdio",
2941
],
3042
"languages": ["python"],
3143
"version": 2,
3244
"mime_types": ["text/x-python"],
33-
"display_name": "pyright-extended",
45+
"display_name": "libro-analyzer",
3446
},
3547
}

pyprojects/secretnote/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"build": "nx build:py"
1818
},
1919
"devDependencies": {
20+
"@difizen/libro-analyzer": "^0.1.0",
2021
"@secretflow/secretnote": "workspace:^",
2122
"@secretflow/secretnote-ui": "workspace:^"
2223
}

pyprojects/secretnote/pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ dependencies = [
2828
"stack_data>=0.6.3",
2929
"tqdm>=4.66.1",
3030
"dataset>=1.6.2",
31+
"ruff-lsp==0.0.50",
32+
"python-lsp-server==1.8.2",
3133
]
3234
description = "Notebook suite for SecretFlow"
3335
dynamic = ["version"]

requirements-dev.lock

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# last locked with the following flags:
55
# pre: false
66
# features: []
7-
# all-features: true
7+
# all-features: false
88
# with-sources: false
99

1010
-e file:.
@@ -33,6 +33,7 @@ black==24.1.1
3333
bleach==6.1.0
3434
blessed==1.20.0
3535
cachetools==5.3.2
36+
cattrs==23.2.3
3637
certifi==2024.2.2
3738
cffi==1.16.0
3839
charset-normalizer==3.3.2
@@ -53,6 +54,7 @@ deprecated==1.2.14
5354
dill==0.3.8
5455
distlib==0.3.8
5556
dnspython==2.5.0
57+
docstring-to-markdown==0.15
5658
editables==0.5
5759
email-validator==2.1.0.post1
5860
emoji==1.7.0
@@ -103,7 +105,7 @@ jsonschema-specifications==2023.12.1
103105
jupyter-client==8.6.0
104106
jupyter-core==5.7.1
105107
jupyter-events==0.9.0
106-
jupyter-lsp==2.2.2
108+
jupyter-lsp==2.2.0
107109
jupyter-resource-usage==1.0.1
108110
jupyter-server==2.12.5
109111
jupyter-server-terminals==0.5.2
@@ -118,6 +120,7 @@ lightning-utilities==0.10.1
118120
llvmlite==0.40.1
119121
logging-tree==1.9
120122
loguru==0.7.2
123+
lsprotocol==2023.0.1
121124
mako==1.3.2
122125
markdown-it-py==3.0.0
123126
markupsafe==2.1.4
@@ -177,12 +180,15 @@ pyasn1==0.5.1
177180
pyasn1-modules==0.3.0
178181
pycparser==2.21
179182
pydantic==1.10.14
183+
pygls==1.3.0
180184
pygments==2.17.2
181185
pyparsing==3.1.1
182186
pytest==8.0.0
183187
pytest-cov==4.1.0
184188
python-dateutil==2.8.2
185189
python-json-logger==2.0.7
190+
python-lsp-jsonrpc==1.1.2
191+
python-lsp-server==1.8.2
186192
pytz==2024.1
187193
pyyaml==6.0.1
188194
pyzmq==25.1.2
@@ -196,6 +202,7 @@ rich==13.7.0
196202
rpds-py==0.17.1
197203
rsa==4.9
198204
ruff==0.2.0
205+
ruff-lsp==0.0.50
199206
safetensors==0.4.2
200207
scikit-learn==1.1.3
201208
scipy==1.10.1
@@ -236,6 +243,7 @@ transformers==4.37.2
236243
trove-classifiers==2024.1.31
237244
types-python-dateutil==2.8.19.20240106
238245
typing-extensions==4.9.0
246+
ujson==5.9.0
239247
uri-template==1.3.0
240248
urllib3==2.2.0
241249
userpath==1.9.1

requirements.lock

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# last locked with the following flags:
55
# pre: false
66
# features: []
7-
# all-features: true
7+
# all-features: false
88
# with-sources: false
99

1010
-e file:.
@@ -28,6 +28,7 @@ beautifulsoup4==4.12.3
2828
bleach==6.1.0
2929
blessed==1.20.0
3030
cachetools==5.3.2
31+
cattrs==23.2.3
3132
certifi==2024.2.2
3233
cffi==1.16.0
3334
charset-normalizer==3.3.2
@@ -40,6 +41,7 @@ decorator==5.1.1
4041
defusedxml==0.7.1
4142
deprecated==1.2.14
4243
distlib==0.3.8
44+
docstring-to-markdown==0.15
4345
exceptiongroup==1.2.0
4446
executing==2.0.1
4547
fastjsonschema==2.19.1
@@ -72,6 +74,7 @@ jupyter-server-terminals==0.5.2
7274
jupyterlab-pygments==0.3.0
7375
jupyterlab-widgets==3.0.9
7476
loguru==0.7.2
77+
lsprotocol==2023.0.1
7578
mako==1.3.2
7679
markdown-it-py==3.0.0
7780
markupsafe==2.1.4
@@ -102,6 +105,7 @@ pexpect==4.9.0
102105
pickleshare==0.7.5
103106
pkgutil-resolve-name==1.3.10
104107
platformdirs==3.11.0
108+
pluggy==1.4.0
105109
prometheus-client==0.19.0
106110
prompt-toolkit==3.0.43
107111
protobuf==4.25.2
@@ -113,9 +117,12 @@ pyasn1==0.5.1
113117
pyasn1-modules==0.3.0
114118
pycparser==2.21
115119
pydantic==1.10.14
120+
pygls==1.3.0
116121
pygments==2.17.2
117122
python-dateutil==2.8.2
118123
python-json-logger==2.0.7
124+
python-lsp-jsonrpc==1.1.2
125+
python-lsp-server==1.8.2
119126
pyyaml==6.0.1
120127
pyzmq==25.1.2
121128
ray==2.6.3
@@ -126,6 +133,8 @@ rfc3986-validator==0.1.1
126133
rich==13.7.0
127134
rpds-py==0.17.1
128135
rsa==4.9
136+
ruff==0.2.2
137+
ruff-lsp==0.0.50
129138
secretflow-ray==2.2.0
130139
send2trash==1.8.2
131140
six==1.16.0
@@ -141,6 +150,7 @@ tqdm==4.66.1
141150
traitlets==5.14.1
142151
types-python-dateutil==2.8.19.20240106
143152
typing-extensions==4.9.0
153+
ujson==5.9.0
144154
uri-template==1.3.0
145155
urllib3==2.2.0
146156
virtualenv==20.21.0

0 commit comments

Comments
 (0)