Skip to content

Commit 594bd04

Browse files
authored
Merge pull request #1412 from pybricks/dlech
2.1.0-beta.3
2 parents 74f1619 + 810ee36 commit 594bd04

File tree

6 files changed

+46
-10
lines changed

6 files changed

+46
-10
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44

55
## [Unreleased]
66

7+
## [2.1.0-beta.3] - 2022-12-28
8+
79
### Changed
810
- Improved syntax highlighting for f-strings, operators and numeric literals.
911

1012
### Fixed
1113
- Fixed clipping of code completion popup by terminal.
14+
- Fixed code completion for builtin types.
15+
- Fixed code completion for names starting with `_`.
16+
- Fixed code completion for `from ...` for user modules ([support#759]).
17+
18+
[support#759]: https://github.com/pybricks/support/issues/759
1219

1320
## [2.1.0-beta.2] - 2022-12-26
1421

@@ -659,7 +666,8 @@ Prerelease changes are documented at [support#48].
659666

660667
<!-- links for version headings -->
661668

662-
[Unreleased]: https://github.com/pybricks/pybricks-code/compare/v2.1.0-beta.2...HEAD
669+
[Unreleased]: https://github.com/pybricks/pybricks-code/compare/v2.1.0-beta.3...HEAD
670+
[2.1.0-beta.3]: https://github.com/pybricks/pybricks-code/compare/v2.1.0-beta.2...v2.1.0-beta.3
663671
[2.1.0-beta.2]: https://github.com/pybricks/pybricks-code/compare/v2.1.0-beta.1...v2.1.0-beta.2
664672
[2.1.0-beta.1]: https://github.com/pybricks/pybricks-code/compare/v2.0.1...v2.1.0-beta.1
665673
[2.0.1]: https://github.com/pybricks/pybricks-code/compare/v2.0.0...v2.0.1

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pybricks/pybricks-code",
3-
"version": "2.1.0-beta.2",
3+
"version": "2.1.0-beta.3",
44
"license": "MIT",
55
"author": "The Pybricks Authors",
66
"repository": {
@@ -16,7 +16,7 @@
1616
"@pybricks/firmware": "6.6.0",
1717
"@pybricks/ide-docs": "2.7.0",
1818
"@pybricks/images": "^1.3.0",
19-
"@pybricks/jedi": "1.6.0",
19+
"@pybricks/jedi": "1.7.0",
2020
"@pybricks/mpy-cross-v5": "^2.0.0",
2121
"@pybricks/mpy-cross-v6": "^2.0.0",
2222
"@pybricks/python-program-analysis": "^2.0.0",

src/editor/pybricksMicroPython.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export const language = <monaco.languages.IMonarchLanguage>{
224224
[/\b0[bB](0|1|_)+/, 'constant.numeric.bin'],
225225
[/\b0[oO]([0-7]|_)+/, 'constant.numeric.oct'],
226226
[/\b0[xX]([abcdef]|[ABCDEF]|\d|_)+/, 'constant.numeric.hex'],
227-
[/\b([\d_]*\.)?[\d_]+([eE][+-]?[\d_]+)?[jJ]?/, 'constant.numeric'],
227+
[/\b(\d[\d_]*\.|\.)?\d[\d_]*([eE][+-]?[\d_]+)?[jJ]?/, 'constant.numeric'],
228228
],
229229

230230
// Recognize strings, including those broken across lines with \ (but not without)

src/editor/sagas.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,15 @@ function* runJedi(): Generator {
698698
}
699699

700700
if (pythonMessageDidComplete.matches(msg.data)) {
701-
const list = JSON.parse(msg.data.completionListJson);
701+
const list: monaco.languages.CompletionItem[] = JSON.parse(
702+
msg.data.completionListJson,
703+
);
704+
705+
// maintain sort order from jedi
706+
for (const [i, item] of list.entries()) {
707+
item.sortText = String(i).padStart(5, '0');
708+
}
709+
702710
console.debug(list);
703711
complete.resolve({ suggestions: list });
704712
console.debug(`${id}: resolved: ${msg.data.type}`);

src/pybricksMicropython/python-worker.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,25 @@ function fixUpError(err: unknown): Error {
4343
return error;
4444
}
4545

46+
/**
47+
* Naively converts a file system path to a python module name.
48+
*
49+
* Assumes `.py` file extension and no invalid characters.
50+
*
51+
* @param path The path.
52+
*/
53+
function pathToModule(path: string): string {
54+
return path.slice(0, path.length - 3).replaceAll('/', '.');
55+
}
56+
4657
const setUpPythonEnvironment = `
4758
import jedi
4859
import pybricks_jedi
4960
5061
print('preloading pybricks_jedi...')
5162
pybricks_jedi.initialize()
63+
# TODO: this could be moved to pybricks_jedi.initialize()
64+
pybricks_jedi.complete("from ", 1, 6)
5265
print('preloading done.')
5366
`;
5467

@@ -68,16 +81,20 @@ async function init(): Promise<void> {
6881
pyodide.FS.mkdir(mountDir);
6982
pyodide.FS.mount(pyodide.FS.filesystems.MEMFS, { root: '.' }, mountDir);
7083

84+
const userModules = new Set<string>();
85+
7186
self.addEventListener('message', async (e) => {
7287
if (pythonMessageWriteUserFile.matches(e.data)) {
7388
pyodide.FS.writeFile(`${mountDir}/${e.data.path}`, e.data.contents);
7489
console.debug('copied', e.data.path, 'to emscripten fs');
90+
userModules.add(pathToModule(e.data.path));
7591
return;
7692
}
7793

7894
if (pythonMessageDeleteUserFile.matches(e.data)) {
7995
pyodide.FS.unlink(`${mountDir}/${e.data.path}`);
8096
console.debug('removed', e.data.path, ' from emscripten fs');
97+
userModules.delete(pathToModule(e.data.path));
8198
return;
8299
}
83100
});
@@ -103,6 +120,7 @@ async function init(): Promise<void> {
103120

104121
const complete = pyodide.runPython('pybricks_jedi.complete');
105122
const getSignatures = pyodide.runPython('pybricks_jedi.get_signatures');
123+
const updateUserModules = pyodide.runPython('pybricks_jedi.update_user_modules');
106124

107125
self.addEventListener('message', async (e) => {
108126
if (pythonMessageSetInterruptBuffer.matches(e.data)) {
@@ -113,6 +131,7 @@ async function init(): Promise<void> {
113131
if (pythonMessageComplete.matches(e.data)) {
114132
console.debug('worker received complete message');
115133
try {
134+
updateUserModules(userModules);
116135
const { code, lineNumber, column } = e.data;
117136
const list = complete(code, lineNumber, column);
118137
self.postMessage(pythonMessageDidComplete(list));
@@ -125,6 +144,7 @@ async function init(): Promise<void> {
125144
if (pythonMessageGetSignature.matches(e.data)) {
126145
console.debug('worker received getSignatures message');
127146
try {
147+
updateUserModules(userModules);
128148
const { code, lineNumber, column } = e.data;
129149
const list = getSignatures(code, lineNumber, column);
130150
self.postMessage(pythonMessageDidGetSignature(list));

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,10 +2383,10 @@ __metadata:
23832383
languageName: node
23842384
linkType: hard
23852385

2386-
"@pybricks/jedi@npm:1.6.0":
2387-
version: 1.6.0
2388-
resolution: "@pybricks/jedi@npm:1.6.0"
2389-
checksum: 982154fa8b3de0e8fcd023e89b6a6223c55948a673e47f25876eba18305d068d97f56012226eb2a217109dc924a43e8f912aae82f7c944eeb398448d90ff3f78
2386+
"@pybricks/jedi@npm:1.7.0":
2387+
version: 1.7.0
2388+
resolution: "@pybricks/jedi@npm:1.7.0"
2389+
checksum: 54a80640197ec674dcf99077a5a9906716b65361f6a8b22ebadc0f1d2716405c60cb0b76b14797b265e90ccac87a7b237d323399f8440d713c7850b2b37218f1
23902390
languageName: node
23912391
linkType: hard
23922392

@@ -2416,7 +2416,7 @@ __metadata:
24162416
"@pybricks/firmware": 6.6.0
24172417
"@pybricks/ide-docs": 2.7.0
24182418
"@pybricks/images": ^1.3.0
2419-
"@pybricks/jedi": 1.6.0
2419+
"@pybricks/jedi": 1.7.0
24202420
"@pybricks/mpy-cross-v5": ^2.0.0
24212421
"@pybricks/mpy-cross-v6": ^2.0.0
24222422
"@pybricks/python-program-analysis": ^2.0.0

0 commit comments

Comments
 (0)