-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#148] Refactor findTopSection into findSection which uses relative path
- Loading branch information
Showing
13 changed files
with
122 additions
and
108 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -7,4 +7,5 @@ debug.log | |
npm-debug.log | ||
__pycache__ | ||
.coverage | ||
example/.vscode | ||
example/.vscode | ||
venv |
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,2 +1,6 @@ | ||
python modules: | ||
- `pytest` | ||
- `pytest-cov` | ||
|
||
Use the command below to generate a test xml file | ||
```py.test foobar --cov-report xml:cov.xml --cov foobar``` |
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
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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {Section} from "lcov-parse"; | ||
import {extname} from "path"; | ||
import {TextEditor, Uri, workspace} from "vscode"; | ||
import {OutputChannel} from "vscode"; | ||
import {normalizeFileName} from "./helpers"; | ||
import {Reporter} from "./reporter"; | ||
|
||
export class SectionFinder { | ||
|
||
private outputChannel: OutputChannel; | ||
private eventReporter: Reporter; | ||
|
||
constructor( | ||
outputChannel: OutputChannel, | ||
eventReporter: Reporter, | ||
) { | ||
this.outputChannel = outputChannel; | ||
this.eventReporter = eventReporter; | ||
} | ||
|
||
/** | ||
* Compare the paths using relative logic or absolute | ||
* @param textEditor editor with current active file | ||
* @param sections sections to compare against open editors | ||
*/ | ||
public findSectionForEditor( | ||
textEditor: TextEditor, | ||
sections: Map<string, Section>, | ||
): Section | undefined { | ||
function findSection(section): boolean { | ||
const editorFileUri = Uri.file(textEditor.document.fileName); | ||
const workspaceFolder = workspace.getWorkspaceFolder(editorFileUri); | ||
if (!workspaceFolder) { return false; } | ||
|
||
const workspaceFolderName = workspaceFolder.name; | ||
const sectionFile = normalizeFileName(section.file); | ||
const editorFile = normalizeFileName(textEditor.document.fileName); | ||
|
||
try { | ||
const relativeSectionFile = sectionFile.split(workspaceFolderName)[1]; | ||
const relativeEditorFile = editorFile.split(workspaceFolderName)[1]; | ||
|
||
if (relativeSectionFile === relativeEditorFile) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} catch (error) { | ||
// catch possible index out of bounds errors | ||
return false; | ||
} | ||
} | ||
|
||
const sectionsArray = Array.from(sections.values()); | ||
const foundSection = sectionsArray.find(findSection); | ||
|
||
if (!foundSection) { return ; } | ||
|
||
const filePath = foundSection.file; | ||
const template = `[${Date.now()}][renderer][section file path]: `; | ||
const message = template + `${filePath}`; | ||
this.outputChannel.appendLine(message); | ||
|
||
// log file type | ||
this.eventReporter.sendEvent("system", "renderer-fileType", extname(filePath)); | ||
|
||
return foundSection; | ||
} | ||
|
||
} |
This file was deleted.
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
Oops, something went wrong.