Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #17

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
- name: Install node
uses: actions/setup-node@v1
with:
node-version: '10.x'
node-version: '20.x'
- name: Install Python
uses: actions/setup-python@v1
with:
python-version: '3.7'
python-version: '3.12'
architecture: 'x64'
- name: Install dependencies
run: python -m pip install jupyterlab
Expand All @@ -44,11 +44,11 @@ jobs:
- name: Install node
uses: actions/setup-node@v1
with:
node-version: '10.x'
node-version: '20.x'
- name: Install Python
uses: actions/setup-python@v1
with:
python-version: '3.7'
python-version: '3.12'
architecture: 'x64'
- name: Install dependencies
run: python -m pip install jupyterlab
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ node_modules/
*.egg-info/
.ipynb_checkpoints
*.tsbuildinfo

.yarn/
.yarnrc.yml
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"watch": "tsc -w"
},
"dependencies": {
"@jupyterlab/application": "^2.0.0",
"@jupyterlab/notebook": "^2.0.0"
"@jupyterlab/application": "^4.3.0",
"@jupyterlab/notebook": "^4.3.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.25.0",
Expand Down
27 changes: 10 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ interface IFormatResponseContent {

function scalafmtConf(notebookTracker: INotebookTracker): Record<string, any> {
let conf: Record<string, any> = {};
const maybeConf = notebookTracker.currentWidget.model.metadata.get(
'scalafmt'
);
const maybeConf = notebookTracker.currentWidget.model.metadata['scalafmt'];
if (maybeConf && maybeConf.constructor === {}.constructor) {
conf = maybeConf as Record<string, any>;
}
Expand All @@ -44,14 +42,14 @@ function getCells(
return;
}

const it = notebookModel.cells.iter();
const it = notebookModel.cells[Symbol.iterator]();
let cellModel = it.next();
while (cellModel) {
const cellId = cellModel.id;
while (!cellModel.done) {
const cellId = cellModel.value.id;
const initialCode = cellModel.value.text;
if (cellModel.type === 'code' && initialCode.length > 0) {
if (cellModel.value.type === 'code' && initialCode.length > 0) {
requestCells[cellId] = initialCode;
cellDict[cellId] = cellModel;
cellDict[cellId] = cellModel.value;
}
cellModel = it.next();
}
Expand All @@ -69,7 +67,7 @@ function getCells(
}

const cellId = cellModel.id;
const initialCode = cellModel.value.text;
const initialCode = cellModel.sharedModel.source;

if (initialCode.length === 0) {
console.log('nothing to format');
Expand All @@ -93,18 +91,13 @@ function handleResponse(
if (response.key in cellDict && response.key in requestCells) {
const cellModel = cellDict[response.key];
const initialCode = requestCells[response.key];
const codeObservable = cellModel.value;
const codeObservable = cellModel.sharedModel;
if (
response.code &&
response.initial_code === initialCode &&
codeObservable.text === initialCode
codeObservable.source === initialCode
) {
// FIXME Seems there's no way to set the content in one go
codeObservable.insert(0, response.code);
codeObservable.remove(
response.code.length,
codeObservable.text.length
);
codeObservable.setSource(response.code);
} else {
console.log(
'Cell code changed, not updating it with stale formatted code'
Expand Down
Loading
Loading