diff --git a/README.md b/README.md index 242aaa9..740c63a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# CodeGra.atom +# CodeGrade.atom The Atom plugin to communicate with [CodeGra.de](https://codegra.de/)'s filesystem: [CodeGra.fs](https://github.com/CodeGra-de/CodeGra.de). @@ -10,35 +10,35 @@ CodeGra.fs must be installed and both `cgfs` and the helper program ## Usage -Mount your CodeGra.de account to a directory and open Atom in one of +Mount your CodeGrade account to a directory and open Atom in one of the filesystem's subdirectories: ```sh -$ cgfs ~/CodeGra.de +$ cgfs ~/CodeGrade Mounting... Mounted -$ atom ~/CodeGra.de/// +$ atom ~/CodeGrade/// ``` The following commands are now available in Atom when editing a file in a -CodeGra.de filesystem: +CodeGrade filesystem: | Command | `--fixed`1 | Description | |---|---|---| -| codegra-atom:edit-line-comment | ✓ | Edit the comment(s) on the line(s) with a cursor on them. | -| codegra-atom:delete-line-comment | ✓ | Delete the comment(s) on the line(s) with a cursor on them. | -| codegra-atom:open-rubric-editor | ✗ | Edit the rubric of the assignment of the current file. | -| codegra-atom:open-rubric-selector | ✗ | Open the rubric selector file to fill in the rubric for the current submission. | -| codegra-atom:edit-geedback | ✗ | Edit the current submission's global feedback. | -| codegra-atom:edit-grade | ✗ | Edit the current submission's grade. | -| codegra-atom:select-rubric-item | ✗ | Select the rubric item that the cursor is on, deselecting any other item in the same group. | -| codegra-atom:goto-prev-rubric-header | ✗ | Go to the previous header in a rubric file. | -| codegra-atom:goto-next-rubric-header | ✗ | Go to the next header in a rubric file. | -| codegra-atom:goto-prev-rubric-item | ✗ | Go to the previous item in a rubric file. | -| codegra-atom:goto-next-rubric-item | ✗ | Go to the next item in a rubric file. | +| codegrade:edit-line-comment | ✓ | Edit the comment(s) on the line(s) with a cursor on them. | +| codegrade:delete-line-comment | ✓ | Delete the comment(s) on the line(s) with a cursor on them. | +| codegrade:open-rubric-editor | ✗ | Edit the rubric of the assignment of the current file. | +| codegrade:open-rubric-selector | ✗ | Open the rubric selector file to fill in the rubric for the current submission. | +| codegrade:edit-geedback | ✗ | Edit the current submission's global feedback. | +| codegrade:edit-grade | ✗ | Edit the current submission's grade. | +| codegrade:select-rubric-item | ✗ | Select the rubric item that the cursor is on, deselecting any other item in the same group. | +| codegrade:goto-prev-rubric-header | ✗ | Go to the previous header in a rubric file. | +| codegrade:goto-next-rubric-header | ✗ | Go to the next header in a rubric file. | +| codegrade:goto-prev-rubric-item | ✗ | Go to the previous item in a rubric file. | +| codegrade:goto-next-rubric-item | ✗ | Go to the next item in a rubric file. | 1: Require the filesystem to be mounted with the `--fixed` flag to use this feature. ## License -CodeGra.atom is released under [LICENSE](AGPL-v3.0). +CodeGrade.atom is released under [LICENSE](AGPL-v3.0). diff --git a/docs/index.rst b/docs/index.rst index c7e43a5..e2e8b9b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -19,7 +19,7 @@ The code of the CodeGrade Atom plug-in is open-source and can be found on .. toctree:: :maxdepth: 2 - :caption: CodeGrade Emacs Plug-in + :caption: CodeGrade Atom Plug-in install usage diff --git a/docs/install.rst b/docs/install.rst index 7bb65bf..53acded 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -8,9 +8,9 @@ Installing the CodeGrade Atom Plugin (or CodeGra.Atom) can be done via the command line or using the Atom GUI. Installation via the command line is done -with the following command: ``apm install codegra-atom``. +with the following command: ``apm install codegrade-atom``. Installing using the Atom GUI can be done in the ``Install`` tab in the ``Settings`` or -``Preferences`` screen. Search for ``codegra-atom`` in the search dialog and +``Preferences`` screen. Search for ``codegrade-atom`` in the search dialog and press ``Install`` to install the plugin. diff --git a/docs/usage.rst b/docs/usage.rst index 042303f..f15773e 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -5,30 +5,30 @@ make use of the plugin with the command ``atom mnt/``. The following commands are available in Atom when editing a file in the CodeGrade filesystem: -+--------------------------------------+-------------+---------------------------------------------------------------------------------------------+ -| Command | ``--fixed`` | Description | -+======================================+=============+=============================================================================================+ -| codegra-atom:edit-line-comment | ✓ | Edit the comment(s) on the line(s) with a cursor on them. | -+--------------------------------------+-------------+---------------------------------------------------------------------------------------------+ -| codegra-atom:delete-line-comment | ✓ | Delete the comment(s) on the line(s) with a cursor on them. | -+--------------------------------------+-------------+---------------------------------------------------------------------------------------------+ -| codegra-atom:open-rubric-editor | ✗ | Edit the rubric of the assignment of the current file. | -+--------------------------------------+-------------+---------------------------------------------------------------------------------------------+ -| codegra-atom:open-rubric-selector | ✗ | Open the rubric selector file to fill in the rubric for the current submission. | -+--------------------------------------+-------------+---------------------------------------------------------------------------------------------+ -| codegra-atom:edit-geedback | ✗ | Edit the current submission's global feedback. | -+--------------------------------------+-------------+---------------------------------------------------------------------------------------------+ -| codegra-atom:edit-grade | ✗ | Edit the current submission's grade. | -+--------------------------------------+-------------+---------------------------------------------------------------------------------------------+ -| codegra-atom:select-rubric-item | ✗ | Select the rubric item that the cursor is on, deselecting any other item in the same group. | -+--------------------------------------+-------------+---------------------------------------------------------------------------------------------+ -| codegra-atom:goto-prev-rubric-header | ✗ | Go to the previous header in a rubric file. | -+--------------------------------------+-------------+---------------------------------------------------------------------------------------------+ -| codegra-atom:goto-next-rubric-header | ✗ | Go to the next header in a rubric file. | -+--------------------------------------+-------------+---------------------------------------------------------------------------------------------+ -| codegra-atom:goto-prev-rubric-item | ✗ | Go to the previous item in a rubric file. | -+--------------------------------------+-------------+---------------------------------------------------------------------------------------------+ -| codegra-atom:goto-next-rubric-item | ✗ | Go to the next item in a rubric file. | -+--------------------------------------+-------------+---------------------------------------------------------------------------------------------+ ++--------------------------------------+-------------+------------------------------------------------------------------------------------------+ +| Command | ``--fixed`` | Description | ++======================================+=============+==========================================================================================+ +| codegrade:edit-line-comment | ✓ | Edit the comment(s) on the line(s) with a cursor on them. | ++--------------------------------------+-------------+------------------------------------------------------------------------------------------+ +| codegrade:delete-line-comment | ✓ | Delete the comment(s) on the line(s) with a cursor on them. | ++--------------------------------------+-------------+------------------------------------------------------------------------------------------+ +| codegrade:open-rubric-editor | ✗ | Edit the rubric of the assignment of the current file. | ++--------------------------------------+-------------+------------------------------------------------------------------------------------------+ +| codegrade:open-rubric-selector | ✗ | Open the rubric selector file to fill in the rubric for the current submission. | ++--------------------------------------+-------------+------------------------------------------------------------------------------------------+ +| codegrade:edit-geedback | ✗ | Edit the current submission's global feedback. | ++--------------------------------------+-------------+------------------------------------------------------------------------------------------+ +| codegrade:edit-grade | ✗ | Edit the current submission's grade. | ++--------------------------------------+-------------+------------------------------------------------------------------------------------------+ +| codegrade:select-rubric-item | ✗ | Select the rubric item that the cursor is on, deselecting any other item in the same group. | ++--------------------------------------+-------------+------------------------------------------------------------------------------------------+ +| codegrade:goto-prev-rubric-header | ✗ | Go to the previous header in a rubric file. | ++--------------------------------------+-------------+------------------------------------------------------------------------------------------+ +| codegrade:goto-next-rubric-header | ✗ | Go to the next header in a rubric file. | ++--------------------------------------+-------------+------------------------------------------------------------------------------------------+ +| codegrade:goto-prev-rubric-item | ✗ | Go to the previous item in a rubric file. | ++--------------------------------------+-------------+------------------------------------------------------------------------------------------+ +| codegrade:goto-next-rubric-item | ✗ | Go to the next item in a rubric file. | ++--------------------------------------+-------------+------------------------------------------------------------------------------------------+ .. note:: The ``--fixed`` flag when mounting is required to use line comment commands. diff --git a/lib/codegra-atom.js b/lib/codegrade-atom.js similarity index 83% rename from lib/codegra-atom.js rename to lib/codegrade-atom.js index a6e2ca9..36dbd41 100644 --- a/lib/codegra-atom.js +++ b/lib/codegrade-atom.js @@ -1,4 +1,4 @@ -'use babel'; +'use babel'; /* -*- mode: js; indent-tabs-mode: t; tab-width: 4; -*- */ import child_process from 'child_process'; import fs from 'fs'; @@ -6,7 +6,7 @@ import os from 'os'; import path from 'path'; import tmp from 'tmp'; -import { CompositeDisposable, Range } from 'atom'; +import { CompositeDisposable } from 'atom'; import { install as installDeps } from 'atom-package-deps'; let subscriptions = null; @@ -32,21 +32,36 @@ export function serialize() { } export function consumeLinter(registerLinter) { - linter = registerLinter({ - name: 'CodeGra.de', + linter = registerLinter({ + name: 'CodeGrade', }); subscriptions.add(linter); } +function getPathParts(pathName) { + const parts = []; + while (pathName) { + const parsed = path.parse(pathName) + if (pathName === parsed.dir) { + parts.push(parsed.root); + break; + } + parts.push(parsed.base) + pathName = parsed.dir; + } + parts.reverse(); + return parts; +} + // Searches from the root directory of the filesystem up to `toPath` // to find the first directory containing a file named `fileName`. function findDirWithFile(toPath, fileName) { const absPath = path.resolve(toPath); - const parts = absPath.split(path.sep); + const parts = getPathParts(absPath) function testDir(i) { return new Promise((resolve, reject) => { - const dir = '/' + parts.slice(0, i).join(path.sep); + const dir = parts.slice(0, i).join(path.sep); fs.access(path.join(dir, fileName), (err) => { err ? reject(err) : resolve(dir); }); @@ -66,7 +81,7 @@ function findDirWithFile(toPath, fileName) { // and retrieve their comments function initTextEditor(editor) { const filePath = editor.getPath(); - if (filePath == null) { + if (filePath == null) { return; } @@ -75,17 +90,18 @@ function initTextEditor(editor) { const editorSubs = new CompositeDisposable(); editorSubs.add(atom.commands.add(editorView, { - 'codegra-atom:open-rubric-editor': () => + 'codegrade:open-rubric-editor': () => openRubricEditor(editor), - 'codegra-atom:open-rubric-selecter': () => + 'codegrade:open-rubric-selecter': () => openRubricSelecter(editor), - 'codegra-atom:edit-feedback': () => + 'codegrade:edit-feedback': () => openFeedbackFile(editor), - 'codegra-atom:edit-grade': () => + 'codegrade:edit-grade': () => openGradeFile(editor), })); const cmdOut = child_process.spawnSync('cgapi-consumer', ['is-file', filePath]); + if (cmdOut.status == 0) { initFileComments(filePath); editor.onDidDestroy(() => linter.setMessages(filePath, [])); @@ -98,9 +114,9 @@ function initTextEditor(editor) { } editorSubs.add(atom.commands.add(editorView, { - 'codegra-atom:edit-line-comment': () => + 'codegrade:edit-line-comment': () => editComments(editor), - 'codegra-atom:delete-line-comment': () => + 'codegrade:delete-line-comment': () => deleteComments(editor), })); }); @@ -108,15 +124,15 @@ function initTextEditor(editor) { if (editor.getTitle() == '.cg-rubric.md') { editorSubs.add(atom.commands.add(editorView, { - 'codegra-atom:select-rubric-item': () => + 'codegrade:select-rubric-item': () => selectRubricItem(editor), - 'codegra-atom:goto-prev-rubric-item': () => + 'codegrade:goto-prev-rubric-item': () => gotoPrevRubricItem(editor), - 'codegra-atom:goto-next-rubric-item': () => + 'codegrade:goto-next-rubric-item': () => gotoNextRubricItem(editor), - 'codegra-atom:goto-prev-rubric-header': () => + 'codegrade:goto-prev-rubric-header': () => gotoPrevRubricHeader(editor), - 'codegra-atom:goto-next-rubric-header': () => + 'codegrade:goto-next-rubric-header': () => gotoNextRubricHeader(editor), })); } @@ -145,7 +161,7 @@ function makeComment(filePath, line, content) { severity: 'info', location: { file: filePath, - position: Range([[line, 0], [line, 1000]]), + position: [[line, 0], [line, 1000]], }, excerpt: content, }; @@ -158,22 +174,21 @@ function getFileComments(filePath) { function addFileComments(filePath, newComments) { let comments = []; - getFileComments(filePath).forEach((comment) => - comments[comment.location.position.start.row] = comment); - newComments.forEach((comment) => - comments[comment.location.position.start.row] = comment); + // Overwrite old comments with new comments. + for (let comment of getFileComments(filePath)) { + comments[comment.location.position.start.row] = comment; + } + for (let comment of newComments) { + comments[comment.location.position[0][0]] = comment; + } // Condense sparse array - comments = comments.filter((x) => true); + comments = comments.filter(() => true); linter.setMessages(filePath, comments); } function deleteFileComments(filePath, lineNrs) { - let comments = []; - getFileComments(filePath).forEach((comment) => - comments[comment.location.position.start.row] = comment); - lineNrs.forEach((line) => delete comments[line]); - // Condense sparse array - comments = comments.filter((x) => true); + let comments = getFileComments(filePath); + comments = comments.filter((msg) => lineNrs.indexOf(msg.location.position.start.row) < 0); linter.setMessages(filePath, comments); } @@ -190,7 +205,7 @@ function editComments(editor) { ); } - tmp.file((err, path, fd, cleanupTmpFile) => { + tmp.file((err, path, fd, cleanupTmpFile) => { atom.workspace.open(path, { split: 'down', }).then((commentEditor) => { @@ -219,7 +234,7 @@ function saveComments(filePath, lineNrs, commentText) { } if (errors.length > 0) { atom.notifications.addError( - 'CodeGra.atom: ERROR: ' + errors.join('\n'), + 'CodeGrade-atom: ERROR: ' + errors.join('\n'), ); } }); @@ -266,7 +281,7 @@ function deleteComments(editor) { } if (errors.length > 0) { atom.notifications.addError( - 'CodeGra.atom: ERROR: ' + errors.join('\n'), + 'CodeGrade-atom: ERROR: ' + errors.join('\n'), ); } }); @@ -386,7 +401,7 @@ function gotoNextRubricItem(editor) { function openFeedbackFile(editor) { findDirWithFile(editor.getPath(), '.cg-submission-id').then((subDir) => { - const feedbackFile = path.join(subDir, '.cg-rubric.md'); + const feedbackFile = path.join(subDir, '.cg-feedback'); atom.workspace.open(feedbackFile, { split: 'down' }); }, (err) => { atom.notifications.addError(err.message); @@ -395,7 +410,7 @@ function openFeedbackFile(editor) { function openGradeFile(editor) { findDirWithFile(editor.getPath(), '.cg-submission-id').then((subDir) => { - const gradeFile = path.join(subDir, '.cg-rubric.md'); + const gradeFile = path.join(subDir, '.cg-grade'); atom.workspace.open(gradeFile, { split: 'down' }); }, (err) => { atom.notifications.addError(err.message); diff --git a/package.json b/package.json index 2320ab1..bf95d26 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "CodeGra-atom", - "main": "./lib/codegra-atom", + "name": "CodeGrade-atom", + "main": "./lib/codegrade-atom", "version": "0.2.1", "description": "The CodeGra.fs Atom plugin", "keywords": [