From 2f66a0fe0343c2912d98ebbf67e2e5a840877991 Mon Sep 17 00:00:00 2001 From: Tommaso Negri Date: Thu, 6 May 2021 14:17:09 +0000 Subject: [PATCH] feat: various features + prepare for alpha release --- .gitignore | 3 +- CHANGELOG.md | 12 ++ LICENSE | 21 ++ README.md | 39 ++++ Rails.novaextension/.gitignore | 3 + Rails.novaextension/CHANGELOG.md | 13 +- Rails.novaextension/README.md | 39 ++++ Rails.novaextension/Tests/ruby.rb | 3 + Rails.novaextension/extension.json | 59 +++-- package.json | 6 +- .../config/general/statusNotifications.js | 44 ++++ .../config/solargraph/solargraphHover.js | 41 ++++ src/Scripts/helpers.js | 40 ++++ src/Scripts/main.js | 51 +++-- src/Scripts/{ => other}/RailsTaskProvider.js | 4 +- src/Scripts/other/RubyLanguageServer.js | 202 ++++++++++++++++++ src/Scripts/registerCommands.js | 2 +- src/Scripts/solargraph.js | 179 ---------------- 18 files changed, 523 insertions(+), 238 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 Rails.novaextension/Tests/ruby.rb create mode 100644 src/Scripts/config/general/statusNotifications.js create mode 100644 src/Scripts/config/solargraph/solargraphHover.js rename src/Scripts/{ => other}/RailsTaskProvider.js (78%) create mode 100644 src/Scripts/other/RubyLanguageServer.js delete mode 100644 src/Scripts/solargraph.js diff --git a/.gitignore b/.gitignore index 510278f..2fe2240 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -main.dist.js \ No newline at end of file +main.dist.js +.DS_Store diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1408de8 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +## Version 0.5 - Alpha + +### FEATURES + +- Added Rails project detection +- Added Rails Server Task +- Added Rails About sidebar +- Added Rails Documentation search +- Added Rails list and last migration commands +- Added Rails alternate file command +- Added Erb Tag Switcher +- Added Status Notifications diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f9e8d2e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Tommaso Negri + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..db91933 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# Ruby on Rails for Nova editor - ALPHA + +This extension is still in Alpha and various features will be added later on. If you have any suggestion or you have some free time you are free to contribute. + +## Features + +### Rails Server Task + +Automatically generate a Task for running the Rails Server command. + +### Search in various documentations + +Run the Search Documentation command for searching in different documentations online. + +### Open the last migration or list them all + +Run the Last Migration or the List Migrations commands for streamlining those operations. + +### Open Alternate File + +Run the Open Alternate File for rapidly switching between tests and model/controller/etc files. + +### ERB Tag Switcher + +Quickly switch between `<%`, `<%=` & `<%#` with a single shortcut. + +Select a text to wrap it in ERB tags or just use `⌘-shift->` to create a tag and start typing the expression. + +## Features on their way + +- Solargraph support +- Solargrah settings exposed +- Scaffolding Solargraph Files for better Rails Support + +## Contributors + +You are welcome to contribute in any way you can think of! + +Thanks to @devjah, @jonathanpike and @Wylan for their work on different extensions which have been integrated in this suite. diff --git a/Rails.novaextension/.gitignore b/Rails.novaextension/.gitignore index e43b0f9..35bc53b 100644 --- a/Rails.novaextension/.gitignore +++ b/Rails.novaextension/.gitignore @@ -1 +1,4 @@ +CHANGELOG.md +README.md +LICENSE .DS_Store diff --git a/Rails.novaextension/CHANGELOG.md b/Rails.novaextension/CHANGELOG.md index cc688d6..1408de8 100644 --- a/Rails.novaextension/CHANGELOG.md +++ b/Rails.novaextension/CHANGELOG.md @@ -1,3 +1,12 @@ -## Version 1.0 +## Version 0.5 - Alpha -Initial release +### FEATURES + +- Added Rails project detection +- Added Rails Server Task +- Added Rails About sidebar +- Added Rails Documentation search +- Added Rails list and last migration commands +- Added Rails alternate file command +- Added Erb Tag Switcher +- Added Status Notifications diff --git a/Rails.novaextension/README.md b/Rails.novaextension/README.md index e69de29..db91933 100644 --- a/Rails.novaextension/README.md +++ b/Rails.novaextension/README.md @@ -0,0 +1,39 @@ +# Ruby on Rails for Nova editor - ALPHA + +This extension is still in Alpha and various features will be added later on. If you have any suggestion or you have some free time you are free to contribute. + +## Features + +### Rails Server Task + +Automatically generate a Task for running the Rails Server command. + +### Search in various documentations + +Run the Search Documentation command for searching in different documentations online. + +### Open the last migration or list them all + +Run the Last Migration or the List Migrations commands for streamlining those operations. + +### Open Alternate File + +Run the Open Alternate File for rapidly switching between tests and model/controller/etc files. + +### ERB Tag Switcher + +Quickly switch between `<%`, `<%=` & `<%#` with a single shortcut. + +Select a text to wrap it in ERB tags or just use `⌘-shift->` to create a tag and start typing the expression. + +## Features on their way + +- Solargraph support +- Solargrah settings exposed +- Scaffolding Solargraph Files for better Rails Support + +## Contributors + +You are welcome to contribute in any way you can think of! + +Thanks to @devjah, @jonathanpike and @Wylan for their work on different extensions which have been integrated in this suite. diff --git a/Rails.novaextension/Tests/ruby.rb b/Rails.novaextension/Tests/ruby.rb new file mode 100644 index 0000000..7bea11a --- /dev/null +++ b/Rails.novaextension/Tests/ruby.rb @@ -0,0 +1,3 @@ +chars = 'a,b,c' + +chars.split(',').length diff --git a/Rails.novaextension/extension.json b/Rails.novaextension/extension.json index 41c7210..1de08a3 100644 --- a/Rails.novaextension/extension.json +++ b/Rails.novaextension/extension.json @@ -3,7 +3,7 @@ "name": "Ruby on Rails", "organization": "Tommaso Negri", "description": "Ruby on Rails and Ruby support for Nova editor.", - "version": "0.1", + "version": "0.5", "main": "main.dist.js", "license": "MIT", "keywords": [ @@ -12,7 +12,6 @@ "nova", "syntax", "ruby on rails", - "solargraph", "migrations", "documentation" ], @@ -21,7 +20,6 @@ "funding": "https://www.paypal.com/paypalme/tommasonegri/15EUR", "bugs": "https://github.com/tommasongr/nova-rails/issues", "categories": [ - "languages", "clips", "commands", "completions", @@ -83,8 +81,8 @@ ], "editor": [ { - "title": "Rails ERB Tag Switcher", - "command": "tommasonegri.rails.erb.tagSwitcher", + "title": "ERB Tag Switcher", + "command": "tommasonegri.rails.commands.erb.tagSwitcher", "shortcut": "cmd-shift->", "when": "editorHasFocus", "filters": { @@ -130,35 +128,36 @@ ], "config": [ { - "title": "General", - "description": "VLS (Vue Language Server) is a language server implementation compatible with Language Server Protocol. It is developed as part of the Vetur project.", - "type": "section", - "children": [ - { - "key": "tommasonegri.rails.config.general.task.railsServerProvider", - "title": "Provide Task for Rails Server", - "description": "Include completion for module export and auto import them.", - "type": "boolean", - "default": true - } - ] + "key": "tommasonegri.rails.config.general.task.railsServerProvider", + "title": "Provide Task for Rails Server", + "description": "Generate a Task for starting the Rails Server.", + "type": "boolean", + "default": true + }, + { + "key": "tommasonegri.rails.config.general.statusNotifications", + "title": "Status Notifications", + "description": "Show a notification when the server changes status. For example on realod, stop and start. If disabled you will only be notified on crashes or errors.", + "type": "boolean", + "default": true } ], "configWorkspace": [ { - "title": "General", - "description": "VLS (Vue Language Server) is a language server implementation compatible with Language Server Protocol. It is developed as part of the Vetur project.", - "type": "section", - "children": [ - { - "key": "tommasonegri.rails.config.general.task.railsServerProvider", - "title": "Provide Task for Rails Server", - "description": "Include completion for module export and auto import them.", - "type": "enum", - "values": ["Global Default", "Enable", "Disable"], - "default": "Global Default" - } - ] + "key": "tommasonegri.rails.config.general.task.railsServerProvider", + "title": "Provide Task for Rails Server", + "description": "Generate a Task for starting the Rails Server.", + "type": "enum", + "values": ["Global Default", "Enable", "Disable"], + "default": "Global Default" + }, + { + "key": "tommasonegri.rails.config.general.statusNotifications", + "title": "Status Notifications", + "description": "Show a notification when the server changes status. For example on realod, stop and start. If disabled you will only be notified on crashes or errors.", + "type": "enum", + "values": ["Global Default", "Enable", "Disable"], + "default": "Global Default" } ] } diff --git a/package.json b/package.json index 9d63bce..516768c 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "nova-rails", - "version": "0.1.0", - "description": "Rails support for Nova Editor.", + "version": "0.5.0", + "description": "Ruby on Rails and Ruby support for Nova editor.", "main": "src/Scripts/main.js", "scripts": { - "build": "npx rollup -c", + "build": "npx rollup -c && cp CHANGELOG.md README.md LICENSE Rails.novaextension", "watch": "onchange -i \"src/**/*.js\" \"src/**/*.json\" -- npm run build", "publish": "npx rollup -v", "develop": "rollup -c" diff --git a/src/Scripts/config/general/statusNotifications.js b/src/Scripts/config/general/statusNotifications.js new file mode 100644 index 0000000..c104422 --- /dev/null +++ b/src/Scripts/config/general/statusNotifications.js @@ -0,0 +1,44 @@ +function reload() { + nova.commands.invoke("tommasonegri.rails.commands.reload"); +} + +nova.config.onDidChange( + "tommasonegri.rails.config.general.statusNotifications", + reload +); +nova.workspace.config.onDidChange( + "tommasonegri.rails.config.general.statusNotifications", + reload +); + +function getExtensionSetting() { + return nova.config.get( + "tommasonegri.rails.config.general.statusNotifications", + "boolean" + ); +} + +function getWorkspaceSetting() { + const str = nova.workspace.config.get( + "tommasonegri.rails.config.general.statusNotifications", + "string" + ); + + switch (str) { + case "Global Default": + return null; + case "Enable": + return true; + case "Disable": + return false; + default: + return null; + } +} + +export default function statusNotificationsSetting() { + const workspaceConfig = getWorkspaceSetting(); + const extensionConfig = getExtensionSetting(); + + return workspaceConfig === null ? extensionConfig : workspaceConfig; +} diff --git a/src/Scripts/config/solargraph/solargraphHover.js b/src/Scripts/config/solargraph/solargraphHover.js new file mode 100644 index 0000000..3c29e04 --- /dev/null +++ b/src/Scripts/config/solargraph/solargraphHover.js @@ -0,0 +1,41 @@ +function reload() { + nova.commands.invoke("tommasonegri.rails.commands.reload"); +} + +nova.config.onDidChange("tommasonegri.rails.config.solargraph.hover", reload); +nova.workspace.config.onDidChange( + "tommasonegri.rails.config.solargraph.hover", + reload +); + +function getExtensionSetting() { + return nova.config.get( + "tommasonegri.rails.config.solargraph.hover", + "boolean" + ); +} + +function getWorkspaceSetting() { + const str = nova.workspace.config.get( + "tommasonegri.rails.config.solargraph.hover", + "string" + ); + + switch (str) { + case "Global Default": + return null; + case "Enable": + return true; + case "Disable": + return false; + default: + return null; + } +} + +export default function solargraphHoverSetting() { + const workspaceConfig = getWorkspaceSetting(); + const extensionConfig = getExtensionSetting(); + + return workspaceConfig === null ? extensionConfig : workspaceConfig; +} diff --git a/src/Scripts/helpers.js b/src/Scripts/helpers.js index a066e6b..9e8a605 100644 --- a/src/Scripts/helpers.js +++ b/src/Scripts/helpers.js @@ -1,3 +1,43 @@ +import statusNotificationsSetting from "./config/general/statusNotifications"; + +/** + * @param {string} id Notification ID + * @param {string} title Notification Title + * @param {boolean} showAlways Whether to override the user notifications settings + * @param {string=} body Notification Body + * @param {[string]=} actions Notification Action + * @param {function(any)=} handler Notification Handler + */ +export function showNotification( + id, + title, + showAlways, + body, + actions, + handler +) { + if (showAlways || statusNotificationsSetting()) { + let request = new NotificationRequest(id); + + request.title = title; + if (body) { + request.body = body; + } + if (actions) { + request.actions = actions; + } + + nova.notifications + .add(request) + .then((reply) => { + if (handler) { + handler(reply); + } + }) + .catch((err) => console.error(err, err.stack)); + } +} + export function isRailsInProject() { const gemfilePath = nova.workspace.path + "/Gemfile"; diff --git a/src/Scripts/main.js b/src/Scripts/main.js index da87aeb..1092e64 100644 --- a/src/Scripts/main.js +++ b/src/Scripts/main.js @@ -1,6 +1,10 @@ import registerCommands from "./registerCommands"; import RailsInformationView from "./sidebar/RailsInformationView"; -import RailsTaskProvider from "./RailsTaskProvider"; +import RailsTaskProvider from "./other/RailsTaskProvider"; + +import { isRailsInProject, showNotification } from "./helpers"; + +// import RubyLanguageServer from "./other/RubyLanguageServer"; //********* REGISTRATIONS *********// @@ -29,14 +33,27 @@ nova.assistants.registerTaskAssistant(new RailsTaskProvider(), { //********* INITIALIZATION *********// +// let langserver; + // Initialize a new Nova Disposable object const compositeDisposable = new CompositeDisposable(); async function asyncActivate() { + if (isRailsInProject()) { + showNotification( + "rails-detected", + "Ruby on Rails Found in Project 🎉", + false, + "Specific features will be enabled..." + ); + } + const railsInformationView = new RailsInformationView( aboutRailsSidebarReloadEmitter ); compositeDisposable.add(railsInformationView); + + // langserver = new RubyLanguageServer(); } export function activate() { @@ -44,7 +61,7 @@ export function activate() { return asyncActivate() .then(() => { - console.log("Hello from Rails 💎"); + console.log("Hello from Ruby on Rails 💎"); }) .catch((err) => { console.error("Failed to activate with error:", err); @@ -53,36 +70,30 @@ export function activate() { } export function deactivate() { - // Clean up state before the extension is deactivated - // if (langserver) { - // langserver.stop(); - // langserver = null; - // - // // Used for the when clause of the start/stop server command - // nova.workspace.config.set("tommasonegri.vue.serverRunning", false); - // } - // + // if (langserver) { + // langserver.deactivate(); + // langserver = null; + // } compositeDisposable.dispose(); - console.log("Goodbye from Ruby 👋"); + console.log("Goodbye from Ruby on Rails 👋"); } async function reload() { deactivate(); console.log("Reloading Ruby Language Server..."); - // showNotification( - // "vue-reload", - // "Vue is Reloading...", - // false, - // "Don't worry, it won't take a while." - // ); - // + showNotification( + "rails-reload", + "Ruby on Rails is Reloading...", + false, + "Don't worry, it won't take a while." + ); await asyncActivate() .then(() => { - console.log("Hello from Rails 💎"); + console.log("Hello from Ruby on Rails 💎"); }) .catch((err) => { console.error("Failed to activate with error:", err); diff --git a/src/Scripts/RailsTaskProvider.js b/src/Scripts/other/RailsTaskProvider.js similarity index 78% rename from src/Scripts/RailsTaskProvider.js rename to src/Scripts/other/RailsTaskProvider.js index 3e549ba..cbbbce8 100644 --- a/src/Scripts/RailsTaskProvider.js +++ b/src/Scripts/other/RailsTaskProvider.js @@ -1,5 +1,5 @@ -import { isRailsInProject } from "./helpers"; -import isTaskRailsServerProviderEnabled from "./config/general/taskRailsServerProvider"; +import { isRailsInProject } from "../helpers"; +import isTaskRailsServerProviderEnabled from "../config/general/taskRailsServerProvider"; export default class RailsTaskProvider { constructor() {} diff --git a/src/Scripts/other/RubyLanguageServer.js b/src/Scripts/other/RubyLanguageServer.js new file mode 100644 index 0000000..396ad80 --- /dev/null +++ b/src/Scripts/other/RubyLanguageServer.js @@ -0,0 +1,202 @@ +import solargraphHoverSetting from "../config/solargraph/solargraphHover"; + +export default class RubyLanguageServer { + constructor() { + // Observe the configuration setting for the server's location, and restart the server on change + nova.config.observe( + "tommasonegri.rails.config.solargraph.path", + function (path) { + this.start(path); + }, + this + ); + } + + get isBundled() { + if (typeof this._isBundled !== "undefined") { + return Promise.resolve(this._isBundled); + } + + if ( + !( + nova.workspace.contains(nova.workspace.path + "/Gemfile") || + nova.workspace.contains(nova.workspace.path + "/gems.rb") + ) + ) { + this._isBundled = false; + return Promise.resolve(false); + } + + return new Promise((resolve) => { + const process = new Process("bundle", { + args: ["exec", "solargraph", "--version"], + cwd: nova.workspace.path, + shell: true, + }); + + let output = ""; + process.onStdout((line) => (output += line.trim())); + process.onDidExit((status) => { + if (status === 0) { + console.log(`Found Solargraph ${output} (Bundled)`); + resolve((this._isBundled = true)); + } else { + resolve((this._isBundled = false)); + } + }); + + process.start(); + }); + } + + get globalPath() { + if (typeof this._globalPath !== "undefined") { + return Promise.resolve(this._globalPath); + } + + return new Promise((resolve) => { + const process = new Process("which", { + args: ["solargraph"], + shell: true, + }); + + let path = ""; + process.onStdout((line) => (path += line.trim())); + process.onDidExit((status) => { + if (status === 0) { + const versionProcess = new Process(path, { + args: ["--version"], + shell: true, + }); + + let output = ""; + versionProcess.onStdout((line) => (output += line.trim())); + versionProcess.onDidExit((status) => { + if (status === 0) { + console.log(`Found Solargraph ${output} (Global)`); + resolve((this._globalPath = path)); + } else { + resolve((this._globalPath = false)); + } + }); + + versionProcess.start(); + } else { + resolve((this._globalPath = false)); + } + }); + + process.start(); + }); + } + + async commandArgs(commandArguments) { + if (await this.isBundled) { + commandArguments.unshift( + nova.workspace.path + "/bin/bundle", + "exec", + "solargraph" + ); + } else if (await this.globalPath) { + commandArguments.unshift(await this.globalPath); + } + + // commandArguments.unshift("/usr/bin/env"); + const args = commandArguments; + return args; + } + + notifyUserOfMissingCommand() { + if (this.isNotified) return; + + const request = new NotificationRequest("solargraph-not-found"); + request.title = nova.localize("Solargraph Not Found"); + request.body = nova.localize( + 'The "solargraph" command could not be found in your environment.' + ); + request.actions = [nova.localize("OK"), nova.localize("Help")]; + + const notificationPromise = nova.notifications.add(request); + notificationPromise + .then((response) => { + if (response.actionIdx === 1) { + // Help + nova.openConfig(); + } + }) + .catch((error) => { + console.error(error); + }) + .finally(() => { + this.isNotified = true; + }); + } + + deactivate() { + this.stop(); + } + + async start(path) { + if (this.languageClient) { + this.languageClient.stop(); + nova.subscriptions.remove(this.languageClient); + } + + // Use the default server path + if (!path) { + path = nova.workspace.path + "/bin/bundle"; + } + + const defaultArguments = ["stdio"]; + const allArgs = await this.commandArgs(defaultArguments); + if (!allArgs) return; + + // Create the client + var serverOptions = { + path: allArgs.shift(), + args: allArgs, + }; + var clientOptions = { + // The set of document syntaxes for which the server is valid + syntaxes: ["ruby"], + initializationOptions: { + enablePages: true, + hover: false, + completion: false, + logLevel: "info", + hover: false, + completion: false, + diagnostics: true, + }, + }; + var client = new LanguageClient( + "ruby", + "Ruby Language Server", + serverOptions, + clientOptions + ); + + try { + // Start the client + client.start(); + + // Add the client to the subscriptions to be cleaned up + nova.subscriptions.add(client); + this.languageClient = client; + } catch (err) { + // If the .start() method throws, it's likely because the path to the language server is invalid + + if (nova.inDevMode()) { + console.error(err); + } + } + } + + stop() { + if (this.languageClient) { + this.languageClient.stop(); + nova.subscriptions.remove(this.languageClient); + this.languageClient = null; + } + } +} diff --git a/src/Scripts/registerCommands.js b/src/Scripts/registerCommands.js index eb223fe..1ad85a2 100644 --- a/src/Scripts/registerCommands.js +++ b/src/Scripts/registerCommands.js @@ -5,7 +5,7 @@ import RailsDocumentation from "./commands/RailsDocumentation"; export default function registerCommands() { nova.commands.register( - "tommasonegri.rails.erb.tagSwitcher", + "tommasonegri.rails.commands.erb.tagSwitcher", async (editor) => { erbTagSwitcher(editor); } diff --git a/src/Scripts/solargraph.js b/src/Scripts/solargraph.js deleted file mode 100644 index d57405a..0000000 --- a/src/Scripts/solargraph.js +++ /dev/null @@ -1,179 +0,0 @@ -let langserver = null; - -// Initialize a new Nova Disposable object -const compositeDisposable = new CompositeDisposable(); - -async function asyncActivate() { - // Instantiate the Information Sidebar - const informationView = new InformationView(); - compositeDisposable.add(informationView); - - informationView.status = "Warming up..."; - - // If VLS isn't found, install it - try { - await dependencyManagement.installWrappedDependencies( - compositeDisposable, - { - console: { - log: (...args) => { - if (nova.inDevMode()) { - console.log("dependencyManagement:", ...args); - } - }, - info: (...args) => { - if (nova.inDevMode()) { - console.info("dependencyManagement:", ...args); - } - }, - warn: (...args) => { - console.warn("dependencyManagement:", ...args); - }, - }, - } - ); - } catch (err) { - informationView.status = "Failed to install"; - throw err; - } - - // Retrieve the VLS path - const vlsPath = nova.path.join( - dependencyManagement.getDependencyDirectory(), - "node_modules", - ".bin", - "vls" - ); - - // If VLS hasn't been installed, display an error message and quit - if (!vlsPath) { - informationView.status = "VLS not found"; - - showNotification( - "vls-not-found", - "VLS Not Found", - true, - "The Vue Language Server hasn't been installed correctly. You may want to restart the server or open an issue. I'm sorry for this...", - ["Restart", "Open Issue", "Ignore"], - (reply) => { - console.log(reply.actionIdx); - switch (reply.actionIdx) { - case 0: - nova.commands.invoke( - "tommasonegri.vue.commands.reload" - ); - break; - case 1: - nova.openURL( - "https://github.com/tommasongr/nova-vue/issues" - ); - break; - case 2: - break; - } - } - ); - - return; - } else { - if (nova.inDevMode()) { - console.info("Using VLS at:", vlsPath); - } - } - - // Instantiate the Vue Language Server - var serverOptions = { - path: vlsPath, - }; - - var clientOptions = { - // The set of document syntaxes for which the server is valid - syntaxes: ["ruby"], - initializationOptions: { - config: { - vetur: { - completion: { - autoImport: isCompletionAutoImportEnabled(), - tagCasing: isCompletionTagCasingEnabled(), - }, - languageFeatures: { - codeActions: isLanguageFeaturesCodeActionsEnabled(), - updateImportOnFileMove: isLanguageFeaturesUpdateImportOnFileMoveEnabled(), - }, - // Disabled by default for preventing xxx errors to show up - validation: { - interpolation: isValidationInterpolationEnabled(), - script: isValidationScriptEnabled(), - style: isValidationStyleEnabled(), - template: isValidationTemplateEnabled(), - templateProps: isValidationTemplatePropsEnabled(), - }, - experimental: { - templateInterpolationService: isExperimentalTemplateInterpolationServiceEnabled(), - }, - dev: { - logLevel: isDevLogLevelEnabled(), - }, - format: { - enable: false, - }, - ignoreProjectWarning: isMiscIgnoreProjectWarningEnabled(), - useWorkspaceDependencies: isMiscUseWorkspaceDependenciesEnabled(), - }, - }, - }, - }; - - langserver = new LanguageClient( - "tommasonegri.ruby", - "Ruby Language Server", - serverOptions, - clientOptions - ); - - // Add an event listener for when Vue Language Server stops - compositeDisposable.add( - langserver.onDidStop((err) => { - informationView.status = "Stopped"; - - // Display an error message and a restart button if the server stopped unexpectedly - if (err) { - let message = "Vue Language Server stopped unexpectedly"; - message += `:\n\n${err.toString()}`; - message += - "\n\nPlease report this, along with any output in the Extension Console."; - - nova.workspace.showActionPanel( - message, - { - buttons: ["Restart", "Ignore"], - }, - (index) => { - if (index == 0) { - nova.commands.invoke( - "tommasonegri.vue.commands.reload" - ); - } - } - ); - } - }) - ); - - langserver.start(); - - // Retrieve the running VLS version to display in the Information Sidebar - getVlsVersion() - .then((version) => { - console.log("VLS Version", version); - informationView.vlsVersion = version; - }) - .catch((err) => { - console.log("No VLS Version:", err); - }); - - informationView.status = "Running"; - - // Used for the when clause of the start/stop server command - nova.workspace.config.set("tommasonegri.vue.serverRunning", true); -}