Skip to content

Commit

Permalink
Completions bug fix (#129)
Browse files Browse the repository at this point in the history
* Completions bug fix

* syntax error
  • Loading branch information
Carson-Shaar authored Dec 14, 2023
1 parent d435a56 commit 8dcb5df
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 184 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '18'
cache: "yarn"
cache-dependency-path: "zt_frontend/yarn.lock"
- name: Setup Python for Docs
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -45,10 +51,10 @@ jobs:
rm -r zt_backend/dist_dev/
rm -r zt_backend/dist_app/
cd zt_frontend
yarn install
yarn install
yarn run build
cp -r dist/ ../zt_backend/dist_dev/
yarn run buildapp
yarn run buildapp
cp -r dist/ ../zt_backend/dist_app/
- name: Upload Frontend Artifacts
if: steps.check-changes.outputs.any_changed == 'true'
Expand Down Expand Up @@ -81,7 +87,7 @@ jobs:
Remove-Item -Path zt_backend\dist_dev -Force -Recurse
Remove-Item -Path zt_backend\dist_app -Force -Recurse
shell: powershell
# Only run this step on Windows


- name: Remove Existing Frontend Files (Linux/Mac)
if: runner.os != 'Windows' && needs.build-frontend.outputs.any_changed == 'true'
Expand All @@ -100,4 +106,4 @@ jobs:
- name: Setup Chrome
uses: nanasess/setup-chromedriver@v2
- name: Test with pytest
run: pytest
run: pytest
21 changes: 19 additions & 2 deletions .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,27 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '18'
cache: "yarn"
cache-dependency-path: "zt_frontend/yarn.lock"
- name: Set output
id: release_tag
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT

- name: Build Frontend Files
run: |
npm install --global yarn
ls -a
rm -r zt_backend/dist_dev/
rm -r zt_backend/dist_app/
cd zt_frontend
yarn install
yarn run build
cp -r dist/ ../zt_backend/dist_dev/
yarn run buildapp
cp -r dist/ ../zt_backend/dist_app/
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -32,4 +49,4 @@ jobs:
IMAGE_TAG: "${{ steps.release_tag.outputs.tag }}"
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:zero-true-$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:zero-true-$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:zero-true-$IMAGE_TAG
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = zero-true
description = A collaborative notebook built for data scientists
long_description = file: README.md
long_description_content_type = text/markdown
version = 0.0.dev35
version = 0.0.dev36

[options]
include_package_data = true
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion zt_backend/dist_app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" href="./favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Zero-True</title>
<script type="module" crossorigin src="./assets/index-11b2a933.js"></script>
<script type="module" crossorigin src="./assets/index-210ed3b1.js"></script>
<link rel="stylesheet" href="./assets/index-b4b3b1e9.css">
</head>

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion zt_backend/dist_dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" href="./favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Zero-True</title>
<script type="module" crossorigin src="./assets/index-ef62f442.js"></script>
<script type="module" crossorigin src="./assets/index-a82a07b4.js"></script>
<link rel="stylesheet" href="./assets/index-b4b3b1e9.css">
</head>

Expand Down
2 changes: 0 additions & 2 deletions zt_backend/models/generate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from .response import Response
from .notebook import Notebook
from .notebook import NotebookResponse
from .notebook import Completions
from .components.slider import Slider
from .components.text_input import TextInput
from .components.text_area_input import TextArea
Expand Down Expand Up @@ -33,7 +32,6 @@ def generate_schema():
generate_json(Response, 'response')
generate_json(Slider, 'slider')
generate_json(Notebook, 'notebook')
generate_json(Completions, 'completions')
generate_json(NotebookResponse, 'notebook_response')
generate_json(TextInput, 'text_input')
generate_json(TextArea,'text_area')
Expand Down
7 changes: 0 additions & 7 deletions zt_backend/models/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ class Notebook(BaseModel):
class Dependencies(BaseModel):
value: str

class Completion(BaseModel):
completions: list

class Completions(BaseModel):
cell_id: str
cell_completions: Completion

class NotebookResponse(BaseModel):
notebook: Notebook
dependencies: Dependencies
Expand Down
2 changes: 2 additions & 0 deletions zt_backend/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ async def stop_execution(websocket: WebSocket):

@router.on_event('shutdown')
def shutdown():
global current_thread
global user_threads
if current_thread:
current_thread.kill()
for user_id in user_threads:
Expand Down
10 changes: 7 additions & 3 deletions zt_backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,13 @@ def save_toml():
logger.debug("Toml saved for notebook %s", zt_notebook.notebookId)

def get_code_completions(cell_id:str, code: str, line: int, column: int) -> list:
script = jedi.Script(code)
completions = script.complete(line, column)
return {"cell_id": cell_id, "completions": [{"label": completion.name, "type": completion.type} for completion in completions]}
try:
script = jedi.Script(code)
completions = script.complete(line, column)
return {"cell_id": cell_id, "completions": [{"label": completion.name, "type": completion.type} for completion in completions]}
except Exception:
logger.debug("Error getting completions for cell_id %s: %s", cell_id, traceback.format_exc())
return {"cell_id": cell_id, "completions": []}

async def websocket_message_sender(execution_state: UserState):
while True:
Expand Down
14 changes: 4 additions & 10 deletions zt_frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ import { SaveRequest } from "./types/save_request";
import { CreateRequest, Celltype } from "./types/create_request";
import { ClearRequest } from "./types/clear_request";
import { Notebook, CodeCell, Layout } from "./types/notebook";
import { Completions, Completion } from "./types/completions";
import { Dependencies } from "./types/notebook_response";
import CodeComponent from "@/components/CodeComponent.vue";
import MarkdownComponent from "@/components/MarkdownComponent.vue";
Expand All @@ -106,7 +105,7 @@ export default {
return {
notebook: {} as Notebook,
dependencies: {} as Dependencies,
completions: {} as Completions,
completions: {} as {[key: string]: any[]},
ws_url: '',
notebook_socket: null as WebSocket | null,
save_socket: null as WebSocket | null,
Expand All @@ -124,9 +123,9 @@ export default {
{ title: 'Text' },
],
concatenatedCodeCache: {
lastCellId: null as string | null,
lastCellId: '' as string,
code: '' as string,
length: null as number | null
length: 0 as number
}
};
},
Expand Down Expand Up @@ -238,10 +237,7 @@ export default {
this.notebook = cell_response.notebook;
for (let cell_id in this.notebook.cells){
if (this.notebook.cells[cell_id].cellType==='code'){
const completion: Completion = {
completions: []
}
this.completions[cell_id] = completion
this.completions[cell_id] = []
}
}
this.dependencies = cell_response.dependencies;
Expand Down Expand Up @@ -468,8 +464,6 @@ export default {
},
async saveCell(cellId: string, text: string, line: string, column: string) {
let concatenatedCode = '';
// Check if the current cell is a code cell
if (this.notebook.cells[cellId].cellType === 'code') {
if (this.concatenatedCodeCache.lastCellId !== cellId) {
Expand Down
29 changes: 14 additions & 15 deletions zt_frontend/src/components/CodeComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ import {
} from "vuetify/lib/components/index.mjs";
import { VDataTable } from "vuetify/labs/VDataTable";
import { CodeCell, Layout } from "@/types/notebook";
import { Completion } from "@/types/completions";
import LayoutComponent from "@/components/LayoutComponent.vue";
import TextComponent from "@/components/TextComponent.vue"
Expand Down Expand Up @@ -204,7 +203,7 @@ export default {
required: true,
},
completions: {
type: Object as PropType<Completion>,
type: Object as PropType<any[]>,
required: true
}
},
Expand Down Expand Up @@ -247,19 +246,19 @@ export default {
const from = word ? word.from : context.pos;
return {
from: from,
options: (this.completions as unknown as { label: string; type: string }[]).map(completion => ({
label: completion.label,
type: completion.type,
apply: (view: { dispatch: (arg0: { changes: { from: any; to: any; insert: any } }) => void }, completion: { label: any }, from: any, to: any) => {
const insertText = completion.label;
view.dispatch({
changes: { from: from, to: to ?? context.pos, insert: insertText }
});
}
}))
};
};
from: from,
options: (this.completions as unknown as { label: string; type: string }[]).map(completion => ({
label: completion.label,
type: completion.type,
apply: (view: { dispatch: (arg0: { changes: { from: any; to: any; insert: any } }) => void }, completion: { label: any }, from: any, to: any) => {
const insertText = completion.label;
view.dispatch({
changes: { from: from, to: to ?? context.pos, insert: insertText }
});
}
}))
};
};
if (this.$devMode){
return [Prec.highest(keyMap), python(), oneDark, autocompletion({ override: [customCompletionSource] })]
}
Expand Down

0 comments on commit 8dcb5df

Please sign in to comment.