-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
118 additions
and
95 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 |
---|---|---|
@@ -1,42 +1,63 @@ | ||
import { debounce } from "underscore"; | ||
import { IAnnotation } from "./App"; | ||
const CPP_ERROR_REGEX = /^[a-zA-Z0-9/\-.]+.cpp:([0-9]+): (.*)/; | ||
const JAVA_ERROR_REGEX = /^[a-zA-Z0-9/\-.[\] ]+.java:([0-9]+):[0-9:]* (.*)/; | ||
|
||
// tslint:disable-next-line: variable-name | ||
const _getLintResults = (code: string, lang: string): Promise<IAnnotation[]> => { | ||
const options = { | ||
method: 'post', | ||
body: `code=${encodeURI(code)}&lang=${lang}`, | ||
headers: { | ||
'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8' | ||
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8" | ||
}, | ||
body: `code=${encodeURI(code)}&lang=${lang}` | ||
} | ||
method: "post" | ||
}; | ||
return new Promise((resolve, reject) => { | ||
fetch(`${process.env.REACT_APP_API_URI}/lint`, options).then((res) => { | ||
res.json().then(json => { | ||
switch(json.lang) { | ||
case "cpp": | ||
const errors = json.errors.split("\n").filter((line: string) => line.length !== 0).map((line: string) => { | ||
const match = line.match(CPP_ERROR_REGEX); | ||
if (match != null) { | ||
return { row: Number(match[1]) - 1, column: 0, type: "error", text: match[2] } | ||
} else return {} | ||
}); | ||
resolve(errors); | ||
break; | ||
case "java": | ||
if (json.errors.length > 0) | ||
reject("There are syntactic errors"); | ||
console.log(json) | ||
break; | ||
|
||
} | ||
|
||
fetch(`${process.env.REACT_APP_API_URI}/lint`, options) | ||
.then(res => { | ||
res.json().then(json => { | ||
switch (json.lang) { | ||
case "cpp": | ||
const cppErrors = json.errors | ||
.split("\n") | ||
.filter((line: string) => line.length !== 0) | ||
.map((line: string) => { | ||
const match = line.match(CPP_ERROR_REGEX); | ||
if (match != null) { | ||
return { row: Number(match[1]) - 1, column: 0, type: "error", text: match[2] }; | ||
} else { | ||
return {}; | ||
} | ||
}); | ||
resolve(cppErrors); | ||
break; | ||
case "java": | ||
if (json.errors.length > 0) { | ||
reject("There are syntactic errors"); | ||
return; | ||
} | ||
const javaErrors = json.completed | ||
.replace("Starting audit...", "") | ||
.replace("Audit done.", "") | ||
.split("\n") | ||
.filter((line: string) => line.length !== 0) | ||
.map((line: string) => { | ||
const match = line.match(JAVA_ERROR_REGEX); | ||
if (match != null) { | ||
return { row: Number(match[1]) - 1, column: 0, type: "error", text: match[2] }; | ||
} else { | ||
return {}; | ||
} | ||
}); | ||
resolve(javaErrors); | ||
break; | ||
} | ||
}); | ||
}) | ||
}).catch(err => { | ||
reject(err) | ||
}) | ||
}) | ||
.catch(err => { | ||
reject(err); | ||
}); | ||
}); | ||
}; | ||
|
||
} | ||
|
||
export const getLintResults = debounce(_getLintResults, 100, true); | ||
export const getLintResults = debounce(_getLintResults, 100, true); |
This file contains 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 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