Skip to content

Commit 096eea7

Browse files
committed
editor: add basic intellisense
This adds basic intellisense for code completion and function signatures using the Python `jedi` package running in a Pyodide environment.
1 parent 9f0e5db commit 096eea7

File tree

15 files changed

+693
-15
lines changed

15 files changed

+693
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
# Changelog
44

5+
## [Unreleased]
6+
7+
### Added
8+
- Added basic intellisense to the code editor.
9+
510
## [2.0.0-beta.1] - 2022-06-03
611

712
### Added

config/jest/babelTransform.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ module.exports = babelJest.createTransformer({
2020
['@babel/plugin-transform-typescript', {
2121
allowDeclareFields: true
2222
}],
23-
'@shopify/react-i18n/babel'],
23+
'@shopify/react-i18n/babel',
24+
"babel-plugin-transform-import-meta",
25+
],
2426
presets: [
2527
[
2628
require.resolve('babel-preset-react-app'),

config/webpackDevServer.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ module.exports = function (proxy, allowedHost) {
4040
'Access-Control-Allow-Origin': '*',
4141
'Access-Control-Allow-Methods': '*',
4242
'Access-Control-Allow-Headers': '*',
43+
'Cross-Origin-Opener-Policy': 'same-origin',
44+
'Cross-Origin-Embedder-Policy': 'require-corp',
4345
},
4446
// Enable gzip compression of generated files.
4547
compress: true,

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"babel-loader": "^8.2.3",
3939
"babel-plugin-macros": "^3.0.1",
4040
"babel-plugin-named-asset-import": "^0.3.8",
41+
"babel-plugin-transform-import-meta": "^2.2.0",
4142
"babel-preset-react-app": "^10.0.1",
4243
"bfj": "^7.0.2",
4344
"browser-fs-access": "^0.30.1",
@@ -78,6 +79,7 @@
7879
"postcss-preset-env": "^7.7.2",
7980
"prompts": "^2.4.2",
8081
"prop-types": "^15.8.1",
82+
"pyodide": "0.20.1-alpha.2",
8183
"react": "^16.13.1",
8284
"react-app-polyfill": "^3.0.0",
8385
"react-aria": "^3.17.0",

src/editor/actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
import { createAction } from '../actions';
55
import { UUID } from '../fileStorage';
6+
export {
7+
didFailToInit as editorCompletionDidFailToInit,
8+
didInit as editorCompletionDidInit,
9+
init as editorCompletionInit,
10+
} from './redux/codeCompletion';
611

712
/** Action that indicates that a code editor was created. */
813
export const editorDidCreate = createAction(() => ({

src/editor/reducers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
editorDidCreate,
1010
editorDidOpenFile,
1111
} from './actions';
12+
import codeCompletion from './redux/codeCompletion';
1213

1314
/** Indicates that the code editor is ready for use. */
1415
const isReady: Reducer<boolean> = (state = false, action) => {
@@ -46,6 +47,7 @@ const openFileUuids: Reducer<readonly UUID[]> = (state = [], action) => {
4647
};
4748

4849
export default combineReducers({
50+
codeCompletion,
4951
isReady,
5052
activeFileUuid,
5153
openFileUuids,

src/editor/redux/codeCompletion.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2022 The Pybricks Authors
3+
4+
import { createSlice } from '@reduxjs/toolkit';
5+
6+
export enum CompletionEngineStatus {
7+
Unknown,
8+
Loading,
9+
Ready,
10+
Failed,
11+
}
12+
13+
type State = {
14+
status: CompletionEngineStatus;
15+
};
16+
17+
const initialState: State = {
18+
status: CompletionEngineStatus.Unknown,
19+
};
20+
21+
const slice = createSlice({
22+
name: 'codeCompletion',
23+
initialState,
24+
reducers: {
25+
init(state) {
26+
state.status = CompletionEngineStatus.Loading;
27+
},
28+
didInit(state) {
29+
state.status = CompletionEngineStatus.Ready;
30+
},
31+
didFailToInit(state) {
32+
state.status = CompletionEngineStatus.Failed;
33+
},
34+
},
35+
});
36+
37+
export const { init, didInit, didFailToInit } = slice.actions;
38+
export default slice.reducer;

0 commit comments

Comments
 (0)