-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from Code-Inspect/46-diff-viewer-for-sliced-code
Diff viewer for sliced code
- Loading branch information
Showing
8 changed files
with
141 additions
and
71 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"vscode-flowr.verboseLog": true | ||
"vscode-flowr.verboseLog": true, | ||
"vscode-flowr.style.sliceDisplay": "diff" | ||
} |
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,28 @@ | ||
library(cranlogs) | ||
|
||
# retrieve top N packages | ||
N <- 500 | ||
|
||
# Get the names of all packages | ||
pkgnames <- available.packages(repos="https://cloud.r-project.org")[,1] | ||
|
||
# init result | ||
download_numbers <- data.frame() | ||
|
||
stepsize <- 750 | ||
for (i in seq(1, length(pkgnames), by = stepsize)) { | ||
start <- i | ||
end <- min(i+stepsize-1, length(pkgnames)) | ||
cat("Retrieving download numbers for packages", start, "to", end, "from total", length(pkgnames), "\n") | ||
data <- cran_downloads(packages = pkgnames[start:end], when="last-month") | ||
download_numbers <- rbind(download_numbers, data) | ||
} | ||
|
||
# now packages appear often as they are with different days in the data, therefore we aggregate | ||
download_numbers <- aggregate(count ~ package, data=download_numbers, sum) | ||
|
||
# sort download numbers | ||
download_numbers <- download_numbers[order(-download_numbers$count),] | ||
print(download_numbers[1:N,]) | ||
|
||
write.table(download_numbers[1:N,], file="top-r-downloads.txt", quote=FALSE, sep=",", row.names=FALSE, col.names=FALSE) |
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,79 @@ | ||
import * as vscode from 'vscode' | ||
import type { NodeId } from '@eagleoutice/flowr' | ||
import type { SourceRange } from '@eagleoutice/flowr/util/range' | ||
import { establishInternalSession, flowrSession, getConfig } from './extension' | ||
import type { SliceDisplay } from './settings' | ||
import { Settings } from './settings' | ||
|
||
export let sliceDecoration: vscode.TextEditorDecorationType | ||
|
||
export function registerSliceCommands(context: vscode.ExtensionContext) { | ||
context.subscriptions.push(vscode.commands.registerCommand('vscode-flowr.slice.cursor', async() => { | ||
const activeEditor = vscode.window.activeTextEditor | ||
if(activeEditor?.selection) { | ||
if(!flowrSession) { | ||
await establishInternalSession() | ||
} | ||
void flowrSession?.retrieveSlice(activeEditor.selection.active, activeEditor, true) | ||
} | ||
})) | ||
context.subscriptions.push(vscode.commands.registerCommand('vscode-flowr.slice.clear', () => { | ||
const activeEditor = vscode.window.activeTextEditor | ||
if(activeEditor) { | ||
activeEditor.setDecorations(sliceDecoration, []) | ||
} | ||
})) | ||
context.subscriptions.push(vscode.commands.registerCommand('vscode-flowr.slice.cursor-reconstruct', async() => { | ||
const activeEditor = vscode.window.activeTextEditor | ||
if(activeEditor) { | ||
if(!flowrSession) { | ||
await establishInternalSession() | ||
} | ||
const code = await flowrSession?.retrieveSlice(activeEditor.selection.active, activeEditor, false) | ||
const doc = await vscode.workspace.openTextDocument({language: 'r', content: code}) | ||
void vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside) | ||
} | ||
})) | ||
|
||
recreateSliceDecorationType() | ||
vscode.workspace.onDidChangeConfiguration(e => { | ||
if(e.affectsConfiguration(`${Settings.Category}.${Settings.StyleSliceOpacity}`)) { | ||
recreateSliceDecorationType() | ||
} | ||
}) | ||
context.subscriptions.push(new vscode.Disposable(() => sliceDecoration.dispose())) | ||
} | ||
|
||
export async function displaySlice(editor: vscode.TextEditor, sliceElements: { id: NodeId, location: SourceRange }[]) { | ||
const sliceLines = new Set<number>(sliceElements.map(s => s.location.start.line - 1)) | ||
switch(getConfig().get<SliceDisplay>(Settings.StyleSliceDisplay)) { | ||
case 'text': { | ||
const decorations: vscode.DecorationOptions[] = [] | ||
for(let i = 0; i < editor.document.lineCount; i++) { | ||
if(!sliceLines.has(i)) { | ||
decorations.push({range: new vscode.Range(i, 0, i, editor.document.lineAt(i).text.length)}) | ||
} | ||
} | ||
editor.setDecorations(sliceDecoration, decorations) | ||
break | ||
} | ||
case 'diff': { | ||
const sliceContent = [] | ||
for(let i = 0; i < editor.document.lineCount; i++){ | ||
if(!sliceLines.has(i)){ | ||
sliceContent.push(editor.document.lineAt(i).text) | ||
} | ||
} | ||
const sliceDoc = await vscode.workspace.openTextDocument({language: 'r', content: sliceContent.join('\n')}) | ||
void vscode.commands.executeCommand('vscode.diff', sliceDoc.uri, editor.document.uri) | ||
break | ||
} | ||
} | ||
} | ||
|
||
function recreateSliceDecorationType() { | ||
sliceDecoration?.dispose() | ||
sliceDecoration = vscode.window.createTextEditorDecorationType({ | ||
opacity: getConfig().get<number>(Settings.StyleSliceOpacity)?.toString() | ||
}) | ||
} |