This repository was archived by the owner on Jun 7, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 223
Code coach modularize #1396
Merged
bnmnetp
merged 9 commits into
RunestoneInteractive:master
from
ascholerChemeketa:code-coach-modularize
Apr 7, 2023
Merged
Code coach modularize #1396
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c6ba968
Get rid of col-md-12 in interactives
ascholerChemeketa 8f3eea2
Margin tweaks for activecode
ascholerChemeketa c7206fd
Activecode - remove useless divs. Add class to codelens and codecoach…
ascholerChemeketa 7edee14
Remove alignVertical from activecode
ascholerChemeketa d9d8f9a
Merge branch 'python-check'
ascholerChemeketa 5d30f41
Merge remote-tracking branch 'origin/master'
ascholerChemeketa bd74a56
Refactor Pyflakes code coach
ascholerChemeketa 30982ff
Remove old checkPythonSyntax
ascholerChemeketa 180192e
Filter "import *" related messages in Pyflakes code coach
ascholerChemeketa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| $.i18n().load({ | ||
| en: { | ||
| msd_pyflakes_coach_line: "Line", | ||
| }, | ||
| }); | ||
|
|
||
| export default class PyflakesCoach { | ||
| async check(code) { | ||
| let promise = new Promise(function (resolve, reject) { | ||
| fetch('/ns/coach/python_check', { | ||
| method: 'POST', | ||
| body: code | ||
| }) | ||
| .then((response) => { | ||
| return response.json(); | ||
| }) | ||
| .then((data) => { | ||
| if(data.trim() !== '') { | ||
| let message = ""; | ||
| //clean up returned text | ||
| let errorLines = data.split("\n"); | ||
| let codeLines = code.split("\n"); | ||
| for(let line of errorLines) { | ||
| if(line.indexOf(".py:") != -1) { | ||
| //old pyflakes returns "file:line:col error" | ||
| //new pyflakes returns "file:line:col: error" | ||
| //handle either | ||
| const cleaner = /[^.]*.py:(\d+):(\d+):? (.*)/i; | ||
| let lineParts = line.match(cleaner); //[1]: line, [2]: col, [3]: error | ||
|
|
||
| //for now, filter messages about star imports | ||
| if(!lineParts[3].includes("defined from star imports") | ||
| && !lineParts[3].includes("*' used; unable to detect undefined names")) | ||
| { | ||
| message += $.i18n("msd_pyflakes_coach_line") + lineParts[1] + ": " + lineParts[3] + "\n"; | ||
| message += codeLines[lineParts[1] - 1] + "\n"; | ||
| message += " ".repeat(lineParts[2] - 1) + "^\n"; | ||
| } | ||
| } else { | ||
| message += line + "\n"; | ||
| } | ||
| } | ||
| message = message.slice(0,-1); //remove trailing newline | ||
| resolve(message); | ||
| } | ||
| resolve(null); | ||
| }) | ||
| .catch(err => { | ||
| reject("Error in Pyflakes Coach: " + err); | ||
| }) | ||
| }); | ||
| return promise; | ||
| } | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a method to add a coach? If I'm thinking about the future and adding a new coach I would want to have a method to do that so I don't have to modify this code...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No one should have to touch that code.
Coaches are added up in the constructor (line 143). I'm not sure where else they would be injected from - that was one of my questions. I don't have a good sense of how to make creating coaches more modular.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm, can't figure out how to quote in those lines without starting a new conversation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was imagining a method on the Activecode instance, but then I'm not sure what other object would call it, so having it in the constructor is fine for now.