diff --git a/Scripts/commands/RailsAlternateFile.js b/Scripts/commands/RailsAlternateFile.js index 190ecdb..6fdf8ef 100644 --- a/Scripts/commands/RailsAlternateFile.js +++ b/Scripts/commands/RailsAlternateFile.js @@ -1,3 +1,5 @@ +const SETTINGS = require("../settings") + exports.RailsAlternateFile = class RailsAlternateFile { constructor() { // FIXME: Handle running the command while something else than a file is active (like a terminal) @@ -7,23 +9,25 @@ exports.RailsAlternateFile = class RailsAlternateFile { // TODO: Refactor and improve code quality alternate() { + var testType = (SETTINGS.general.alternateFileType == "rspec" ? "spec" : "test"); + // If neither app nor test are found in the path, can't find associated file - if (this.splitPath.indexOf("app") === -1 && this.splitPath.indexOf("test") === -1) { + if (this.splitPath.indexOf("app") === -1 && this.splitPath.indexOf(testType) === -1) { this.showError("Couldn't find alternate files. Does the workspace contain a Rails project?") return } - const rootIndex = this.splitPath.indexOf("app") === -1 ? this.splitPath.indexOf("test") : this.splitPath.indexOf("app") + const rootIndex = this.splitPath.indexOf("app") === -1 ? this.splitPath.indexOf(testType) : this.splitPath.indexOf("app") const rootDir = this.splitPath[rootIndex] - const associatedDir = rootDir === "app" ? "test" : "app" + const associatedDir = rootDir === "app" ? testType : "app" const currentFileName = this.splitPath[this.splitPath.length - 1] let associatedFileName - if (associatedDir === "test") { - associatedFileName = currentFileName.slice(0, -3).concat("_test.rb") + if (associatedDir === testType) { + associatedFileName = currentFileName.slice(0, -3).concat("_${testType}.rb") } else { - associatedFileName = currentFileName.replace("_test", "") + associatedFileName = currentFileName.replace("_${testType}", "") } let newSplitPath = this.splitPath diff --git a/Scripts/settings.js b/Scripts/settings.js index 9aea483..1e80397 100644 --- a/Scripts/settings.js +++ b/Scripts/settings.js @@ -1,5 +1,6 @@ // EXTENSION const { statusNotifications } = require("./settings/general/statusNotifications") +const { alternateFileType } = require("./settings/general/alternateFileType") // SOLARGRAPH const { autoFormat } = require("./settings/solargraph/autoFormat") const { bundlerPath } = require("./settings/solargraph/bundlerPath") @@ -23,6 +24,7 @@ const { autocorrectDisableUncorrectable } = require("./settings/rubocop/autocorr module.exports = { statusNotifications, + alternateFileType, solargraph: { autoFormat, bundlerPath, diff --git a/Scripts/settings/general/alternateFileType.js b/Scripts/settings/general/alternateFileType.js new file mode 100644 index 0000000..86a1dae --- /dev/null +++ b/Scripts/settings/general/alternateFileType.js @@ -0,0 +1,32 @@ +function reload() { + nova.commands.invoke("tommasonegri.rails.commands.reload") +} + +nova.config.onDidChange("tommasonegri.rails.config.general.alternateFileType", reload) +nova.workspace.config.onDidChange("tommasonegri.rails.config.general.alternateFileType", reload) + +function getExtensionSetting() { + return nova.config.get("tommasonegri.rails.config.general.alternateFileType", "boolean") +} + +function getWorkspaceSetting() { + const str = nova.workspace.config.get("tommasonegri.rails.config.general.alternateFileType", "string") + + switch (str) { + case "Global Default": + return null + case "minitest": + return "minitest" + case "rspec": + return "rspec" + default: + return null + } +} + +exports.statusNotialternateFileTypefications = function() { + const workspaceConfig = getWorkspaceSetting() + const extensionConfig = getExtensionSetting() + + return workspaceConfig === null ? extensionConfig : workspaceConfig +} diff --git a/extension.json b/extension.json index 104b6c7..9e9382d 100644 --- a/extension.json +++ b/extension.json @@ -385,6 +385,15 @@ "type": "boolean", "default": true }, + { + "key": "tommasonegri.rails.config.general.alternateFileType", + "title": "Alternate File type", + "description": "Select whether 'Open Alternate File' should use minitest or rspec.", + "type": "enum", + "values": ["minitest", "rspec"], + "radio": false, + "default": "minitest" + }, { "title": "Solargraph", "description": "Solargraph is a Ruby language server and suite of static analysis tools. The language server provides intellisense, autocompletion, diagnostics, and other language features for editors and IDEs with language client capabilities. The static analysis tools check code for type safety.", @@ -557,6 +566,15 @@ "radio": false, "default": "Global Default" }, + { + "key": "tommasonegri.rails.config.general.alternateFileType", + "title": "Alternate File type", + "description": "Select whether 'Open Alternate File' should use minitest or rspec.", + "type": "enum", + "values": ["Global Default", "minitest", "rspec"], + "radio": false, + "default": "Global Default" + }, { "title": "Solargraph settings", "description": "Solargraph is a Ruby language server and suite of static analysis tools. The language server provides intellisense, autocompletion, diagnostics, and other language features for editors and IDEs with language client capabilities. The static analysis tools check code for type safety.",