Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.
Merged
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ A `ThirdPartyNotices.txt` file is provided in the extension's source code listin
- The first time you install the extension, you'll need to execute the `run` command at least once in order to access auto-completion.
- While running a code file, if you get an error saying it can't find the file, make sure you've clicked on a valid Python code file before running it.
- To open the output panel again after closing it go to VS Code menu: `View->Output`.
- If you have pylint enabled, it might underline the import of the adafruit_circuitplayground library, but it will work correctly.
- If you try to deploy to the device while it's plugged in but you still get an error saying it cannot find the board, make sure your Circuit Playground Express is formatted correctly and that its name matches `CIRCUITPY`.
- If you can't get the Simulator communication working while debugging, try to open your `Settings` and check the port used under `"Device Simulator Express: Debugger Server Port"`. You can either change it (usually ports above 5000 should work) or try to free it, then start debugging again.
- When you are using the serial monitor, if you get some unusual error messages, unplug the device and reload the VS Code windows.
Expand Down
1 change: 0 additions & 1 deletion docs/how-to-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ Here are the settings you can change in the Device Simulator Express configurati
- The first time you install the extension, you'll need to execute the `run` command at least once in order to access auto-completion.
- While running a code file, if you get an error saying it can't find the file, make sure you've clicked on a valid Python code file before running it.
- To open the output panel again after closing it go to VS Code menu : `View->Output`.
- If you have pylint enabled, it might underline the import of the adafruit_circuitplayground library, but it will work correctly.
- If you try to deploy to the device while it's plugged in but you still get an error saying it cannot find the board, make sure your Circuit Playground Express is formatted correctly and that its name matches `CIRCUITPY`.
- If you can't get the Simulator communication working while debugging, try to open you `Settings` and check the port used under `'Device Simulator Express: Debugger Server Port'`. You can either change it (usually ports above 5000 could work) or try to free it, then start debugging again.

Expand Down
67 changes: 54 additions & 13 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export async function activate(context: vscode.ExtensionContext) {
// Add our library path to settings.json for autocomplete functionality
updatePythonExtraPaths();

// ignore import errors so that adafruit_circuitplayground library
// doesn't trigger lint errors
updatePylintArgs(context);

pythonExecutableName = await utils.setPythonExectuableName();

await utils.checkPythonDependencies(context, pythonExecutableName);
Expand Down Expand Up @@ -973,21 +977,58 @@ const checkForTelemetry = (sensorState: any) => {
};

const updatePythonExtraPaths = () => {
const pathToLib: string = __dirname;
const currentExtraPaths: string[] =
vscode.workspace
.getConfiguration()
.get("python.autoComplete.extraPaths") || [];
if (!currentExtraPaths.includes(pathToLib)) {
currentExtraPaths.push(pathToLib);
}
updateConfigLists(
"python.autoComplete.extraPaths",
[__dirname],
vscode.ConfigurationTarget.Global
);
};

const updatePylintArgs = (context: vscode.ExtensionContext) => {
const outPath: string = createEscapedPath(
context.extensionPath,
CONSTANTS.FILESYSTEM.OUTPUT_DIRECTORY
);
const pyLibsPath: string = createEscapedPath(
context.extensionPath,
CONSTANTS.FILESYSTEM.OUTPUT_DIRECTORY,
CONSTANTS.FILESYSTEM.PYTHON_LIBS_DIR
);

// update pylint args to extend system path
// to include python libs local to extention
updateConfigLists(
"python.linting.pylintArgs",
[
"--init-hook",
`import sys; sys.path.extend([\"${outPath}\",\"${pyLibsPath}\"])`,
],
vscode.ConfigurationTarget.Workspace
);
};

const createEscapedPath = (...pieces: string[]) => {
const initialPath: string = path.join(...pieces);

// escape all instances of backslashes
return initialPath.replace(/\\/g, "\\\\");
};

const updateConfigLists = (
section: string,
newItems: string[],
scope: vscode.ConfigurationTarget
) => {
// function for adding elements to configuration arrays
const currentExtraItems: string[] =
vscode.workspace.getConfiguration().get(section) || [];
const extraItemsSet: Set<string> = new Set(
currentExtraItems.concat(newItems)
);

vscode.workspace
.getConfiguration()
.update(
"python.autoComplete.extraPaths",
currentExtraPaths,
vscode.ConfigurationTarget.Global
);
.update(section, Array.from(extraItemsSet), scope);
};

function getWebviewContent(context: vscode.ExtensionContext) {
Expand Down