Skip to content

Commit

Permalink
#5 customizable settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Almenon committed Feb 10, 2018
1 parent 7e0fa01 commit 64109cc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,19 @@ You can activate AREPL directly by using control-shift-a or command-shift-a if o
see [AREPL-backend](https://github.com/Almenon/AREPL-backend) for the npm package that executes the python code

AREPL is also availible as a standalone [app](https://github.com/Almenon/AREPL)

### Settings:

AREPL offers the following customizable settings:

// delay in ms before executing code after typing
> "AREPL.delay": 300,
// 70 fits in 1280 screen
> "AREPL.max_string_length": 70,
// when restart mode is active we add this to delay to delay longer
> "AREPL.restartDelay": 300,
// 2 shows x=1 and x=[1,2], provides option to expand deeply nested data like x=[[1]]
> "AREPL.show_to_level": 2
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,32 @@
],
"main": "./out/src/extension",
"contributes": {
"configuration": {
"type": "object",
"title": "AREPL configuration",
"properties": {
"AREPL.delay": {
"type": "number",
"default": 300,
"description": "delay in ms before executing code after typing"
},
"AREPL.restartDelay": {
"type": "number",
"default": 300,
"description": "when restart mode is active we add this to delay to delay longer"
},
"AREPL.show_to_level": {
"type": "number",
"default": 2,
"description": "2 shows x=1 and x=[1,2], provides option to expand deeply nested data like x=[[1]]"
},
"AREPL.max_string_length": {
"type": "number",
"default": 70,
"description": "70 fits in 1280 screen"
}
}
},
"commands": [
{
"command": "extension.evalPythonInRealTime",
Expand Down
6 changes: 4 additions & 2 deletions src/HTMLDocumentContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ export default class HtmlDocumentContentProvider implements vscode.TextDocumentC
errorContainer = ''
userVarContainer = `<div id="results"></div>`;
printContainer = `<br><b>Print Output:</b><div id="print"></div>`;
settings:vscode.WorkspaceConfiguration;

constructor(private context: vscode.ExtensionContext) {
this._onDidChange = new vscode.EventEmitter<vscode.Uri>();
this.css = `<link rel="stylesheet" type="text/css" href="${this.getMediaPath("pythonPreview.css")}">`
this.jsonRendererScript = `<script src="${this.getMediaPath('jsonRenderer.js')}"></script>`
this.settings = vscode.workspace.getConfiguration('AREPL');
}

provideTextDocumentContent(uri: vscode.Uri): string {
Expand Down Expand Up @@ -90,8 +92,8 @@ export default class HtmlDocumentContentProvider implements vscode.TextDocumentC
let jsonRendererCode = `<script>
${userVarsCode}
let jsonRenderer = renderjson.set_icons('+', '-') // default icons look a bit wierd, overriding
.set_show_to_level(2)
.set_max_string_length(150);
.set_show_to_level(${this.settings.get('show_to_level')})
.set_max_string_length(${this.settings.get('max_string_length')});
document.getElementById("results").appendChild(jsonRenderer(userVars));
</script>`

Expand Down
6 changes: 4 additions & 2 deletions src/PreviewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ export default class PreviewManager {
this.pythonEvaluator = new PythonEvaluator()
this.pythonEditor = vscode.window.activeTextEditor.document;

const settings = vscode.workspace.getConfiguration('AREPL');

vscode.workspace.registerTextDocumentContentProvider(HtmlDocumentContentProvider.scheme, this.pythonPreviewContentProvider);

/////////////////////////////////////////////////////////
// python
/////////////////////////////////////////////////////////
let self:PreviewManager = this;
let debounce = 300;
let restartExtraDebounce = 300;
let debounce = settings.get<number>('delay');
let restartExtraDebounce = settings.get<number>('restartDelay');

this.pythonEvaluator.startPython()
this.pythonEvaluator.pyshell.childProcess.on('error', err => {
Expand Down

0 comments on commit 64109cc

Please # to comment.