├── .gitignore ├── CHANGELOG.md ├── extension.png ├── extension@2x.png ├── jsconfig.json ├── copilot └── dist │ ├── tree-sitter.wasm │ ├── tree-sitter-go.wasm │ ├── tree-sitter-ruby.wasm │ ├── tree-sitter-python.wasm │ ├── tree-sitter-javascript.wasm │ ├── tree-sitter-typescript.wasm │ └── agent.js.LICENSE.txt ├── Tests ├── example_controller.js └── index.html ├── Scripts ├── copilot │ ├── support.js │ ├── commands.js │ └── LanguageServer.js ├── types │ ├── Types.js │ └── nova.d.ts ├── CompletionProvider.js ├── main.js └── helpers.js ├── .editorconfig ├── .github └── ISSUE_TEMPLATE │ ├── task.yml │ ├── bug_report.yml │ └── feature_request.yml ├── extension.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .nova 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Version 1.0 2 | 3 | Initial release 4 | -------------------------------------------------------------------------------- /extension.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gobijan/nova-copilot-lsp/HEAD/extension.png -------------------------------------------------------------------------------- /extension@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gobijan/nova-copilot-lsp/HEAD/extension@2x.png -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "checkJs": true 5 | } 6 | } -------------------------------------------------------------------------------- /copilot/dist/tree-sitter.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gobijan/nova-copilot-lsp/HEAD/copilot/dist/tree-sitter.wasm -------------------------------------------------------------------------------- /Tests/example_controller.js: -------------------------------------------------------------------------------- 1 | // Initiliaze a stimulusJs controller 2 | function hello() { 3 | console.log("hello") 4 | } 5 | -------------------------------------------------------------------------------- /copilot/dist/tree-sitter-go.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gobijan/nova-copilot-lsp/HEAD/copilot/dist/tree-sitter-go.wasm -------------------------------------------------------------------------------- /copilot/dist/tree-sitter-ruby.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gobijan/nova-copilot-lsp/HEAD/copilot/dist/tree-sitter-ruby.wasm -------------------------------------------------------------------------------- /copilot/dist/tree-sitter-python.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gobijan/nova-copilot-lsp/HEAD/copilot/dist/tree-sitter-python.wasm -------------------------------------------------------------------------------- /copilot/dist/tree-sitter-javascript.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gobijan/nova-copilot-lsp/HEAD/copilot/dist/tree-sitter-javascript.wasm -------------------------------------------------------------------------------- /copilot/dist/tree-sitter-typescript.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gobijan/nova-copilot-lsp/HEAD/copilot/dist/tree-sitter-typescript.wasm -------------------------------------------------------------------------------- /Scripts/copilot/support.js: -------------------------------------------------------------------------------- 1 | /** @enum {string} */ 2 | module.exports.AccountRequirement = { 3 | SignedIn: "SIGNED_IN", 4 | Authorized: "AUTHORIZED", 5 | SignedOut: "SIGNED_OUT" 6 | } 7 | -------------------------------------------------------------------------------- /Tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Tests 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 4 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | 15 | [*.yml] 16 | indent_style = space 17 | indent_size = 2 -------------------------------------------------------------------------------- /Scripts/types/Types.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef CopilotCompletion 3 | * @property {number} docVersion 4 | * @property {{ start: { line: number, character: number }, end: { line: number, character: number } }} range 5 | * @property {string} text 6 | * @property {string} displayText 7 | * @property {{ line: number, character: number }} position 8 | * @property {string} uuid 9 | */ 10 | 11 | module.exports = {} 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/task.yml: -------------------------------------------------------------------------------- 1 | name: 🛠️ Task 2 | description: Used to assign tasks or responsibilities to specific team members, such as code reviews, testing, or deployment. 3 | title: "" 4 | labels: [🤔 Unrefined, 🛠️ Task] 5 | body: 6 | - type: textarea 7 | attributes: 8 | label: Overview 9 | description: A concise description of what needs to be done 10 | validations: 11 | required: true 12 | - type: textarea 13 | attributes: 14 | label: Background 15 | description: A short history or background of what this task is or why it is being done. 16 | validations: 17 | required: false 18 | 19 | - type: textarea 20 | attributes: 21 | label: References 22 | description: Useful information or related issues/conversations 23 | validations: 24 | required: false 25 | 26 | - type: textarea 27 | attributes: 28 | label: Acceptance Criteria 29 | description: What needs to be completed for this to be considered done? 30 | placeholder: | 31 | "- [ ] First Thing" 32 | "- [ ] Second Thing" 33 | "- [ ] Third Thing" 34 | "- [ ] Fourth Thing" 35 | validations: 36 | required: true 37 | -------------------------------------------------------------------------------- /Scripts/CompletionProvider.js: -------------------------------------------------------------------------------- 1 | const { rangeToLspRange } = require("./helpers") 2 | /** @typedef {import("./copilot/LanguageServer")} LanguageServer */ 3 | 4 | /** @implements {CompletionAssistant} */ 5 | class CompletionProvider { 6 | /** @param {LanguageServer} langserver */ 7 | constructor(langserver) { 8 | this.langserver = langserver 9 | } 10 | 11 | /** 12 | * @param {TextEditor} editor 13 | * @param {CompletionContext} context 14 | * @returns {Promise<CompletionItem[]|null>} 15 | */ 16 | async provideCompletionItems(editor, context) { 17 | 18 | // if (context.reason == CompletionReason.Character) return null 19 | 20 | const range = new Range(context.position, context.position) 21 | const completions = await this.langserver.getAllCompletions(editor, range) 22 | 23 | const completionItems = completions.map(completion => { 24 | const item = new CompletionItem(context.text, CompletionItemKind.Expression) 25 | item.insertText = completion.text 26 | item.documentation = completion.displayText 27 | item.detail = 'Copilot' 28 | return item 29 | }) 30 | return completionItems 31 | } 32 | } 33 | 34 | module.exports = CompletionProvider 35 | -------------------------------------------------------------------------------- /Scripts/main.js: -------------------------------------------------------------------------------- 1 | const LanguageServer = require("./copilot/LanguageServer") 2 | const CompletionProvider = require("./CompletionProvider") 3 | const { applyCompletionCommand, signInCommand, signOutCommand } = require("./copilot/commands") 4 | 5 | /** @type {LanguageServer} */ 6 | let langserver = null 7 | 8 | const syntaxes = ["javascript", "python", "ruby", "go", "rust", "java", "php", "html", "css", "typescript", "json", "txt", "md"] 9 | 10 | /** Activate the extension. */ 11 | exports.activate = function() { 12 | langserver = new LanguageServer() 13 | 14 | nova.assistants.registerCompletionAssistant(syntaxes, new CompletionProvider(langserver)) 15 | } 16 | 17 | /** Deactivate the extension. */ 18 | exports.deactivate = function() { 19 | // Clean up state before the extension is deactivated 20 | if (langserver) { 21 | langserver.deactivate() 22 | langserver = null 23 | } 24 | } 25 | 26 | nova.subscriptions.add( 27 | nova.commands.register("screenisland.novacopilotlsp.signIn", () => signInCommand(langserver)) 28 | ) 29 | 30 | nova.subscriptions.add( 31 | nova.commands.register("screenisland.novacopilotlsp.signOut", () => signOutCommand(langserver)) 32 | ) 33 | 34 | nova.subscriptions.add( 35 | nova.commands.register("screenisland.novacopilotlsp.applyCompletion", async (editor) => applyCompletionCommand(editor, langserver)) 36 | ) 37 | -------------------------------------------------------------------------------- /extension.json: -------------------------------------------------------------------------------- 1 | { 2 | "identifier": "screenisland.novacopilotlsp", 3 | "name": "Copilot for Nova", 4 | "organization": "Screen Island", 5 | "description": "Nova plugin for GitHub Copilot.", 6 | "version": "1.0.2", 7 | "categories": [ 8 | "languages" 9 | ], 10 | "bugs": "https://github.com/gobijan/nova-copilot-lsp/issues", 11 | "main": "main.js", 12 | "entitlements": { 13 | "process": true, 14 | "filesystem": "readonly", 15 | "clipboard": true 16 | }, 17 | "commands": { 18 | "extensions": [ 19 | { 20 | "title": "Sign In", 21 | "command": "screenisland.novacopilotlsp.signIn" 22 | }, 23 | { 24 | "title": "Sign Out", 25 | "command": "screenisland.novacopilotlsp.signOut" 26 | } 27 | ], 28 | "editor": [ 29 | { 30 | "title": "Apply Completion", 31 | "command": "screenisland.novacopilotlsp.applyCompletion", 32 | "shortcut": "cmd-opt-'" 33 | } 34 | ] 35 | }, 36 | "config": [ 37 | { 38 | "key": "screenisland.novacopilotlsp.node-path", 39 | "title": "node path", 40 | "type": "path", 41 | "placeholder": "/opt/homebrew/bin/node" 42 | } 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /copilot/dist/agent.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | * buildToken 3 | * Builds OAuth token prefix (helper function) 4 | * 5 | * @name buildToken 6 | * @function 7 | * @param {GitUrl} obj The parsed Git url object. 8 | * @return {String} token prefix 9 | */ 10 | 11 | /** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */ 12 | 13 | /** @preserve 14 | * Counter block mode compatible with Dr Brian Gladman fileenc.c 15 | * derived from CryptoJS.mode.CTR 16 | * Jan Hruby jhruby.web@gmail.com 17 | */ 18 | 19 | /** @preserve 20 | (c) 2012 by Cédric Mesnil. All rights reserved. 21 | 22 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 23 | 24 | - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 25 | - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: 🐛 Bug Report 2 | description: File a bug/issue 3 | title: "[BUG] <title>" 4 | labels: [🐛 Bug,🤔 Unrefined] 5 | 6 | body: 7 | - type: checkboxes 8 | attributes: 9 | label: Is there an existing issue for this? 10 | description: Please search to see if an issue already exists for the bug you encountered. 11 | options: 12 | - label: I have searched the existing issues 13 | required: true 14 | - type: textarea 15 | attributes: 16 | label: Current Behavior 17 | description: A concise description of what you're experiencing. 18 | validations: 19 | required: false 20 | - type: textarea 21 | attributes: 22 | label: Expected Behavior 23 | description: A concise description of what you expected to happen. 24 | validations: 25 | required: false 26 | - type: textarea 27 | attributes: 28 | label: Steps To Reproduce 29 | description: Steps to reproduce the behavior. 30 | placeholder: | 31 | 1. In this environment... 32 | 2. With this config... 33 | 3. Run '...' 34 | 4. See error... 35 | validations: 36 | required: false 37 | - type: textarea 38 | attributes: 39 | label: Environment 40 | description: | 41 | examples: 42 | - **OS** : Ubuntu 20.04 43 | - **Node** : 13.14.0 44 | - **npm** : 7.6.3 45 | value: | 46 | - OS: 47 | - Node: 48 | - npm: 49 | render: markdown 50 | validations: 51 | required: false 52 | - type: textarea 53 | id: logs 54 | attributes: 55 | label: Relevant log output 56 | description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. 57 | render: shell 58 | - type: textarea 59 | attributes: 60 | label: Anything else? 61 | description: | 62 | Links? References? Anything that will give us more context about the issue you are encountering! 63 | 64 | Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in. 65 | validations: 66 | required: false 67 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: 🚀 Feature Request or Improvement 2 | description: Use to submit ideas for improved functionality or new features for the NOVA Github Copilot extension. 3 | title: "<Title of Feature Request>" 4 | labels: [🤔 Unrefined,🧚 Feature Request,🗳️ Feedback Needed] 5 | body: 6 | 7 | - type: textarea 8 | attributes: 9 | label: Problem 10 | description: A concise description of what you're experiencing or what you want done. 11 | placeholder: Currently, the extension settings are unclear, causing onboarding difficulty. 12 | validations: 13 | required: true 14 | 15 | - type: textarea 16 | attributes: 17 | label: Solution 18 | description: Describe your proposed solution or approach for addressing the problem. 19 | placeholder: Improve extension documentation & include more detail in extension package. 20 | validations: 21 | required: false 22 | 23 | - type: textarea 24 | attributes: 25 | label: Benefits 26 | description: What benefits does your solution provide to users and what potential impact does it have on the extension? 27 | placeholder: The proposed solution would improve onboarding, which could save users time and provide a more enjable developer experience. 28 | validations: 29 | required: true 30 | 31 | - type: textarea 32 | attributes: 33 | label: Acceptance Criteria 34 | description: Define the criteria that the proposed feature or improvement should meet before it is considered complete. 35 | placeholder: 36 | \- [ ] Extension package descriptions improved 37 | - [ ] Github docs improved 38 | - [ ] Resources audited and updated as necessary 39 | validations: 40 | required: false 41 | 42 | - type: textarea 43 | attributes: 44 | label: Resources/Additional Info 45 | description: Provide any relevant resources or additional information in order to support your proposal. 46 | placeholder: \- [Building NOVA Extensions](https://docs.nova.app/extensions/) 47 | - [NOVA Extension Manifest Docs](https://docs.nova.app/extensions/manifest/) 48 | validations: 49 | required: false 50 | -------------------------------------------------------------------------------- /Scripts/helpers.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Convert a Nova Range into an LSP compatible Range 3 | * @param {TextDocument} document 4 | * @param {Range} range 5 | * @returns {?{ start: { line: number, character: number }, end: { line: number, character: number } }} 6 | */ 7 | exports.rangeToLspRange = (document, range) => { 8 | const fullContents = document.getTextInRange(new Range(0, document.length)) 9 | let chars = 0 10 | let startLspRange 11 | 12 | const lines = fullContents.split(document.eol) 13 | 14 | for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) { 15 | const lineLength = lines[lineIndex].length + document.eol.length 16 | 17 | if (!startLspRange && chars + lineLength >= range.start) { 18 | const character = range.start - chars 19 | startLspRange = { line: lineIndex, character } 20 | } 21 | if (startLspRange && chars + lineLength >= range.end) { 22 | const character = range.end - chars 23 | return { start: startLspRange, end: { line: lineIndex, character } } 24 | } 25 | 26 | chars += lineLength 27 | } 28 | return null 29 | } 30 | 31 | /** 32 | * Convert an LSP compatible Range into a Nova Range 33 | * @param {TextDocument} document 34 | * @param {{ start: { line: number, character: number }, end: { line: number, character: number } }} range 35 | * @returns {Range} 36 | */ 37 | exports.lspRangeToRange = (document, range) => { 38 | const fullContents = document.getTextInRange(new Range(0, document.length)) 39 | let rangeStart = 0 40 | let rangeEnd = 0 41 | let chars = 0 42 | 43 | const lines = fullContents.split(document.eol) 44 | 45 | for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) { 46 | const lineLength = lines[lineIndex].length + document.eol.length 47 | 48 | if (range.start.line === lineIndex) { 49 | rangeStart = chars + range.start.character 50 | } 51 | if (range.end.line === lineIndex) { 52 | rangeEnd = chars + range.end.character 53 | break 54 | } 55 | 56 | chars += lineLength 57 | } 58 | 59 | return new Range(rangeStart, rangeEnd) 60 | } 61 | -------------------------------------------------------------------------------- /Scripts/copilot/commands.js: -------------------------------------------------------------------------------- 1 | const { AccountRequirement } = require("./support") 2 | const { rangeToLspRange } = require("../helpers") 3 | /** @typedef {import("./LanguageServer")} LanguageServer */ 4 | /** @typedef {import("../types/Types").CopilotCompletion} CopilotCompletion */ 5 | 6 | /** 7 | * Ask Copilot to apply the first available completion 8 | * @param {TextEditor} editor 9 | * @param {LanguageServer} langserver 10 | */ 11 | exports.applyCompletionCommand = async (editor, langserver) => { 12 | const completion = await langserver.getCompletion(editor) 13 | if (completion) editor.insert(completion.displayText) 14 | } 15 | 16 | /** 17 | * Sign in to Github Copilot 18 | * @param {LanguageServer} langserver 19 | */ 20 | exports.signInCommand = async (langserver) => { 21 | if (!langserver.accountMeetsRequirement(AccountRequirement.SignedOut)) { 22 | nova.workspace.showInformativeMessage("You are already logged into your Copilot account.") 23 | console.log("Already signed in") 24 | return 25 | } 26 | 27 | try { 28 | const signInInitiateResponse = await langserver.languageClient.sendRequest("signInInitiate", {}) 29 | 30 | const verificationURI = signInInitiateResponse["verificationUri"] 31 | const userCode = signInInitiateResponse["userCode"] 32 | 33 | if (!verificationURI || !userCode) return 34 | 35 | nova.clipboard.writeText(userCode) 36 | nova.openURL(verificationURI) 37 | 38 | /** @type {any} */ 39 | const signInConfirmResponse = await langserver.languageClient.sendRequest("signInConfirm", { "userCode": userCode }) 40 | 41 | if (signInConfirmResponse.status == "OK") { 42 | langserver.checkStatus() 43 | nova.workspace.showInformativeMessage("Signed into your Copilot account.") 44 | console.log("Signed in") 45 | } 46 | } catch (error) { 47 | console.error(error) 48 | } 49 | } 50 | 51 | /** 52 | * Sign out from Github Copilot 53 | * @param {LanguageServer} langserver 54 | */ 55 | exports.signOutCommand = async (langserver) => { 56 | if (!langserver.accountMeetsRequirement(AccountRequirement.SignedIn)) { 57 | nova.workspace.showInformativeMessage("You are already logged out of your Copilot account.") 58 | console.log("Already signed out") 59 | return 60 | } 61 | 62 | try { 63 | /** @type {any} */ 64 | const response = await langserver.languageClient.sendRequest("signOut", {}) 65 | 66 | if (response?.status == "NotSignedIn") { 67 | langserver.checkStatus() 68 | nova.workspace.showInformativeMessage("Signed out from your Copilot account.") 69 | console.log("Signed out") 70 | } 71 | } catch (error) { 72 | console.error(error) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | <!-- 2 | 👋 Hello! As Nova users browse the extensions library, a good README can help them understand what your extension does, how it works, and what setup or configuration it may require. 3 | 4 | Not every extension will need every item described below. Use your best judgement when deciding which parts to keep to provide the best experience for your new users. 5 | 6 | 💡 Quick Tip! As you edit this README template, you can preview your changes by selecting **Extensions → Activate Project as Extension**, opening the Extension Library, and selecting "nova-copilot-lsp" in the sidebar. 7 | 8 | Let's get started! 9 | --> 10 | 11 | <!-- 12 | 🎈 Include a brief description of the features your extension provides. For example: 13 | --> 14 | 15 | **DEPRECATED**: This extension is now deprectated. Use https://github.com/besya/nova-copilot 16 | 17 | **nova-copilot-lsp** aims to provide deep integration with **Github Copilot**, including the most important features. 18 | 19 | Right now it is partly functional but the foundation is there by embedding a working copilot language server extracted from https://github.com/github/copilot.vim 20 | 21 | 22 | ## Requirements 23 | 24 | <!-- 25 | 🎈 If your extension depends on external processes or tools that users will need to have, it's helpful to list those and provide links to their installers: 26 | --> 27 | 28 | nova-copilot-lsp requires some additional tools to be installed on your Mac: 29 | 30 | - [Node.js 8.2.0](https://nodejs.org) and NPM 5.2.0 or newer 31 | 32 | <!-- 33 | ✨ Providing tips, tricks, or other guides for installing or configuring external dependencies can go a long way toward helping your users have a good setup experience: 34 | --> 35 | 36 | > To install the current stable version of Node, click the "Recommended for Most Users" button to begin the download. When that completes, double-click the **.pkg** installer to begin installation. 37 | 38 | ## Usage 39 | 40 | <!-- 41 | 🎈 If your extension provides features that are invoked manually, consider describing those options for users: 42 | --> 43 | 44 | nova-copilot-lsp runs any time you open a local project with supported file extensions. 45 | 46 | 47 | ### Configuration 48 | 49 | <!-- 50 | 🎈 If your extension offers global- or workspace-scoped preferences, consider pointing users toward those settings. For example: 51 | --> 52 | 53 | To configure global preferences, open **Extensions → Extension Library...** then select nova-copilot-lsp's **Preferences** tab. 54 | 55 | You can also configure preferences on a per-project basis in **Project → Project Settings...** 56 | 57 | <!-- 58 | 👋 That's it! Happy developing! 59 | 60 | P.S. If you'd like, you can remove these comments before submitting your extension 😉 61 | --> 62 | 63 | Copilot Completions should be in the Completion Provider list. 64 | Additionally you can trigger them with `CMD+OPTION+'`. 65 | 66 | Have fun. 67 | -------------------------------------------------------------------------------- /Scripts/copilot/LanguageServer.js: -------------------------------------------------------------------------------- 1 | const { AccountRequirement } = require("./support") 2 | const { rangeToLspRange } = require("../helpers") 3 | /** @typedef {import("../types/Types").CopilotCompletion} CopilotCompletion */ 4 | 5 | class LanguageServer { 6 | constructor() { 7 | /** @type {LanguageClient} */ 8 | this.languageClient = null 9 | 10 | /** @type {boolean} */ 11 | this.signedIn = false 12 | /** @type {boolean} */ 13 | this.authorized = false 14 | 15 | // Observe the configuration setting for the server's location, and restart the server on change 16 | nova.config.observe("screenisland.novacopilotlsp.node-path", function(path) { 17 | this.activate(path) 18 | }, this) 19 | } 20 | 21 | async activate(path) { 22 | if (nova.inDevMode()) console.log("Activating Copilot...") 23 | 24 | if (this.languageClient) { 25 | this.languageClient.stop() 26 | nova.subscriptions.remove(this.languageClient) 27 | } 28 | 29 | // Use the default server path 30 | if (!path) { 31 | path = "/opt/homebrew/bin/node" 32 | } 33 | 34 | // Create the client 35 | const serverOptions = { 36 | path: path, 37 | args: [nova.path.join(nova.extension.path, "copilot/dist/agent.js"), "--stdio"], 38 | type: "stdio" 39 | }; 40 | const clientOptions = { 41 | // The set of document syntaxes for which the server is valid 42 | syntaxes: ["javascript", "python", "ruby", "go", "rust", "java", "php", "html", "css", "typescript", "json", "txt", "md"], 43 | debug: false 44 | }; 45 | const client = new LanguageClient("copilot", "GitHub Copilot Language Server", serverOptions, clientOptions); 46 | 47 | try { 48 | // Start the client 49 | client.start() 50 | 51 | // Add the client to the subscriptions to be cleaned up 52 | nova.subscriptions.add(client) 53 | this.languageClient = client 54 | 55 | if (nova.inDevMode()) { 56 | this.languageClient.onNotification("statusNotification", (notification) => { 57 | console.log(JSON.stringify(notification)) 58 | }) 59 | this.languageClient.onNotification("PanelSolution", (notification) => { 60 | console.log(JSON.stringify(notification)) 61 | }) 62 | this.languageClient.onNotification("PanelSolutionsDone", (notification) => { 63 | console.log(JSON.stringify(notification)) 64 | }) 65 | this.languageClient.onNotification("LogMessage", (notification) => { 66 | console.log(JSON.stringify(notification)) 67 | }) 68 | } 69 | 70 | await this.initialize() 71 | await this.checkStatus() 72 | await this.setEditorInfo() 73 | } catch (err) { 74 | // If the .start() method throws, it's likely because the path to the language server is invalid 75 | if (nova.inDevMode()) { 76 | console.error(err) 77 | } 78 | } 79 | } 80 | 81 | deactivate() { 82 | if (nova.inDevMode()) console.log("Deactivating Copilot...") 83 | 84 | if (this.languageClient) { 85 | this.languageClient.stop() 86 | nova.subscriptions.remove(this.languageClient) 87 | this.languageClient = null 88 | } 89 | } 90 | 91 | /** @private */ 92 | async initialize() { 93 | try { 94 | const params = { "capabilities": { "workspace": { "workspaceFolders": true } } } 95 | await this.languageClient.sendRequest("initialize", params) 96 | } catch (error) { 97 | console.error(error) 98 | } 99 | } 100 | 101 | async checkStatus() { 102 | try { 103 | const response = await this.languageClient.sendRequest("checkStatus", {}) 104 | 105 | const status = response["status"] 106 | const signedIn = ["NotAuthorized", "OK"].includes(status) ? true : false 107 | const authorized = status == "OK" ? true : false 108 | 109 | this.accountStatus = { signedIn, authorized } 110 | } catch (error) { 111 | console.error(error) 112 | } 113 | } 114 | 115 | /** @private */ 116 | async setEditorInfo() { 117 | try { 118 | await this.languageClient.sendRequest("setEditorInfo", this.editorInfo) 119 | } catch (error) { 120 | console.error(error) 121 | } 122 | } 123 | 124 | /** @private @readonly */ 125 | get editorInfo() { 126 | return { 127 | editorInfo: { 128 | name: "Nova", 129 | version: nova.versionString, 130 | }, 131 | editorPluginInfo: { 132 | name: nova.extension.name, 133 | version: nova.extension.version, 134 | }, 135 | } 136 | } 137 | 138 | /** 139 | * Object representing the current account status. 140 | * @type {{ signedIn: boolean, authorized: boolean }} 141 | */ 142 | get accountStatus() { 143 | return { 144 | signedIn: this.signedIn, 145 | authorized: this.authorized 146 | } 147 | } 148 | 149 | /** 150 | * Set the current account status. 151 | * @param {{ signedIn: ?boolean, authorized: ?boolean }} newStatus 152 | */ 153 | set accountStatus(newStatus) { 154 | if (newStatus.signedIn != null) this.signedIn = newStatus.signedIn 155 | if (newStatus.authorized != null) this.authorized = newStatus.authorized 156 | 157 | if (!this.signedIn) { 158 | console.warn("Copilot: has NOT been signed in.") 159 | } else if (!this.authorized) { 160 | console.warn("Copilot: has signed in but not authorized.") 161 | } else { 162 | console.log("Copilot: has been signed in and authorized") 163 | } 164 | } 165 | 166 | /** 167 | * Check if the current Account meets the specified requirement 168 | * @param {AccountRequirement} requirement 169 | * @returns {boolean} 170 | */ 171 | accountMeetsRequirement(requirement) { 172 | switch (requirement) { 173 | case AccountRequirement.SignedIn: 174 | return this.accountStatus.signedIn 175 | case AccountRequirement.Authorized: 176 | return this.accountStatus.authorized 177 | case AccountRequirement.SignedOut: 178 | return !this.accountStatus.signedIn 179 | default: 180 | return false 181 | } 182 | } 183 | 184 | /** 185 | * Ask Copilot for the first available completions 186 | * @param {TextEditor} editor 187 | * @param {?Range} range 188 | * @returns {Promise<?[CopilotCompletion]>} 189 | */ 190 | async getAllCompletions(editor, range = null) { 191 | const completions = await this.getCompletions(editor, range) 192 | console.log(JSON.stringify(completions)) 193 | return completions.completions || null 194 | } 195 | 196 | /** 197 | * Ask Copilot for the first available completion 198 | * @param {TextEditor} editor 199 | * @param {?Range} range 200 | * @returns {Promise<?CopilotCompletion>} 201 | */ 202 | async getCompletion(editor, range = null) { 203 | const completions = await this.getAllCompletions(editor, range) 204 | return completions[0] || null 205 | } 206 | 207 | /** 208 | * Ask Copilot for available completions 209 | * @param {TextEditor} editor 210 | * @param {?Range} range 211 | * @returns {Promise<Object>} 212 | */ 213 | async getCompletions(editor, range = null) { 214 | try { 215 | const position = rangeToLspRange(editor.document, range || editor.selectedRange) 216 | const params = { 217 | "doc": { 218 | "source": editor.document.getTextInRange(new Range(0, editor.document.length)), 219 | "tabSize": editor.tabLength, 220 | "indentSize": 1, // there is no such concept in ST 221 | "insertSpaces": editor.softTabs, 222 | "path": editor.document.path, 223 | "uri": editor.document.uri, 224 | "relativePath": editor.document.path, 225 | "languageId": editor.document.syntax, 226 | "position": { "line": position.end.line + 1, "character": position.end.character + 1 }, 227 | // Buffer Version. Generally this is handled by LSP, but we need to handle it here 228 | // Will need to test getting the version from LSP 229 | "version": 0, 230 | } 231 | } 232 | return await this.languageClient.sendRequest("getCompletions", params) 233 | } catch (error) { 234 | console.error(error) 235 | } 236 | } 237 | } 238 | 239 | module.exports = LanguageServer 240 | -------------------------------------------------------------------------------- /Scripts/types/nova.d.ts: -------------------------------------------------------------------------------- 1 | /*~*~* REFRESH_TOKEN: 7bd50adbbfba08ffa3d1 *~*~*/ 2 | /***** UP TO DATE WITH NOVA: 10.6 *****/ 3 | 4 | // DO NOT CHANGE OR MOVE THE REFRESH TOKEN ABOVE. 5 | // Nova Types uses it to determine if the types are up to date. 6 | 7 | // Project: https://docs.nova.app/api-reference/ 8 | // Definitions by: Tommaso Negri <https://github.com/tommasongr> 9 | // Minimum TypeScript Version: 3.3 10 | 11 | /// https://docs.nova.app/extensions/#javascript-runtime 12 | 13 | // This runs in an extension of Apple's JavaScriptCore, manually set libs 14 | 15 | /// <reference no-default-lib="true"/> 16 | /// <reference lib="es7" /> 17 | 18 | /// https://docs.nova.app/api-reference/assistants-registry/ 19 | 20 | type AssistantsRegistrySelector = string | string[] | { syntax: string } 21 | 22 | /** The `AssistantsRegistry` class is used to register and invoke assistants, which can provide specific extension functionality within the editor. A shared instance of the class is always available as the `nova.assistants` environment property. */ 23 | interface AssistantsRegistry { 24 | /** 25 | * Registers a color assistant, which can provide document color information to the editor’s color picker. 26 | * 27 | * The object provided should conform to the following interface: 28 | * @example 29 | * interface ColorAssistant { 30 | * provideColors(editor, context); 31 | * provideColorPresentations(color, editor, context); 32 | * } 33 | * @since 5.0 34 | */ 35 | registerColorAssistant( 36 | selector: AssistantsRegistrySelector, 37 | object: ColorAssistant 38 | ): Disposable 39 | 40 | /** 41 | * Registers a completion assistant, which can provide completion items to the editor’s autocomplete list. 42 | * 43 | * The object provided should conform to the following interface: 44 | * @example 45 | * interface CompletionAssistant { 46 | * provideCompletionItems(editor, context); 47 | * } 48 | */ 49 | registerCompletionAssistant( 50 | selector: AssistantsRegistrySelector, 51 | object: CompletionAssistant, 52 | options?: { 53 | /** 54 | * A [Charset](https://docs.nova.app/api-reference/charset) object that defines characters, other than *identifier* characters, which trigger completions to be requested (such as `.`, `:`, etc.) 55 | * @since 3.0 56 | */ 57 | triggerChars?: Charset 58 | } 59 | ): Disposable 60 | 61 | /** 62 | * Registers an issue assistant, which can provide diagnostic issues to the editor. 63 | * 64 | * The object provided should conform to the following interface: 65 | * @example 66 | * interface IssueAssistant { 67 | * provideIssues(editor); 68 | * } 69 | */ 70 | registerIssueAssistant( 71 | selector: AssistantsRegistrySelector, 72 | object: IssueAssistant, 73 | options?: { 74 | /** 75 | * The event for which issues are requested. 76 | * 77 | * The `event` option for issue assistants provided at registration time can affect when the editor asks for issues from the assistant: 78 | * - `"onChange"`: Issues are requested shortly after the user stops typing (this is the default) 79 | * - `"onSave"`: Issues are requested after each time the document is saved 80 | * 81 | * Some issue assistants may be better suited to operating when the user saves a document as opposed to when the user `changes` a document. For best results, consider offering an option in an extension’s global or workspace configuration that allows this to be changed by the user. 82 | */ 83 | event?: "onChange" | "onSave" 84 | } 85 | ): Disposable 86 | 87 | /** 88 | * Registers a [Task Assistant](https://docs.nova.app/extensions/run-configurations/#defining-a-task-assistant), which can provide tasks to the IDE. 89 | * 90 | * The object provided should conform to the following interface: 91 | * interface TaskAssistant { 92 | * provideTasks(); 93 | * } 94 | * @since 2.0 95 | */ 96 | registerTaskAssistant( 97 | object: TaskAssistant, 98 | options?: { 99 | /** An identifier for the assistant, which can be passed to `nova.workspace.reloadTasks()` */ 100 | identifier?: string 101 | 102 | /** A user-readable name for the assistant displayed above its tasks */ 103 | name?: string 104 | } 105 | ): Disposable 106 | } 107 | 108 | type AssistantArray<T> = ReadonlyArray<T> | Promise<ReadonlyArray<T>> 109 | 110 | /** @since 5.0 */ 111 | interface ColorAssistant { 112 | /** 113 | * This method requests document color information for an editor. 114 | * 115 | * The `provideColors` method of the assistant should take as an argument the [TextEditor](https://docs.nova.app/api-reference/text-editor) instance requesting color information, and a [ColorInformationContext](https://docs.nova.app/api-reference/color-information-context) providing contextual information, and then return an array of [ColorInformation](https://docs.nova.app/api-reference/color-information) objects, or a `Promise` resolving to such. 116 | */ 117 | provideColors(editor: TextEditor, context: ColorInformationContext): AssistantArray<ColorInformation> 118 | 119 | /** 120 | * This method requests color presentations for a color object. 121 | * 122 | * The `provideColorPresentations` method of the assistant should take as an argument the [Color](https://docs.nova.app/api-reference/color) instance being transformed, the [TextEditor](https://docs.nova.app/api-reference/text-editor) instance that is requesting presentations, and a [ColorPresentationContext](https://docs.nova.app/api-reference/color-presentation-context) providing contextual information, and then return an array of [ColorPresentation](https://docs.nova.app/api-reference/color-presentation) objects, or a `Promise` resolving to such. 123 | * 124 | * An assistant may return one or more color presentation objects for the color to represent different “formats” the color may be represented as, such as the various color functions in CSS (`rgb()`, `rgba()`, `hsl()`, etc.). 125 | */ 126 | provideColorPresentations(color: Color, editor: TextEditor, context: ColorPresentationContext): AssistantArray<ColorPresentation> 127 | } 128 | 129 | interface CompletionAssistant { 130 | /** 131 | * The `provideCompletionItems` method of the assistant should take as an argument the [TextEditor](https://docs.nova.app/api-reference/text-editor) instance requesting completion, and a [CompletionContext](https://docs.nova.app/api-reference/completion-context) object. 132 | * 133 | * This method should return an array of the following object types, or a `Promise` resolving to such: 134 | * - [CompletionItem](https://docs.nova.app/api-reference/completion-item): A completions item that can be inserted into the editor. 135 | * - [CompletionColorPop](https://docs.nova.app/api-reference/completion-color-pop): A color pop that can be displayed to mix and choose colors. 136 | */ 137 | provideCompletionItems(editor: TextEditor, context: CompletionContext): AssistantArray<CompletionItem | CompletionColorPop> 138 | } 139 | 140 | interface IssueAssistant { 141 | /** The `provideIssues` method of the assistant should take as an argument the [TextEditor](https://docs.nova.app/api-reference/text-editor) instance requesting completion and return an array of [Issue](https://docs.nova.app/api-reference/issue) objects, or a `Promise` resolving to such. */ 142 | provideIssues(editor: TextEditor): AssistantArray<Issue> 143 | } 144 | 145 | /** @since 2.0 */ 146 | interface TaskAssistant { 147 | /** The `provideTasks` method of the assistant should return an array of [Task](https://docs.nova.app/api-reference/task) objects. */ 148 | provideTasks(): AssistantArray<Task> 149 | 150 | /** 151 | * Invoked when a [TaskResolvableAction](https://docs.nova.app/api-reference/task-resolvable-action) is run by the user to provide the actual action that should be invoked. 152 | * 153 | * The context parameter is an instance of the [TaskActionResolveContext](https://docs.nova.app/api-reference/task-action-resolve-context) class, and provides contextual information about the action being resolved. 154 | * 155 | * This method should return a more concrete instance of a task action (such as a [TaskProcessAction](https://docs.nova.app/api-reference/task-process-action), which will be invoked as if it had been provided when the task was created. This method may also return a `Promise` that resolves to such an action. 156 | * 157 | * Returning `null`, `undefined`, or another instance of a resolvable action will cause the task invocation to fail. 158 | * @since 4.0 159 | */ 160 | resolveTaskAction?<T extends Transferrable>( 161 | context: TaskActionResolveContext<T> 162 | ): ResolvedTaskAction | Promise<ResolvedTaskAction> 163 | } 164 | 165 | /// https://docs.nova.app/api-reference/charset/ 166 | 167 | /** 168 | * A `Charset` object represents a set of Unicode characters that can be used with Scanner objects to parse strings for specific ranges of a string that match the characters in the charset. 169 | * 170 | * The `Charset` class is not subclassable. 171 | */ 172 | declare class Charset { 173 | /** Creates a new `Charset` object that contains all of the characters present in the provided string (or, if no string is provided, no characters). */ 174 | constructor(characters?: string) 175 | 176 | /** The character set containing all alphanumeric characters, as defined in Unicode General Category L*, M*, and N*. */ 177 | static alphanumeric: Charset 178 | 179 | /** The character set containing all decimal digit characters, as defined in Unicode Category Decimal Numbers. */ 180 | static digits: Charset 181 | 182 | /** The character set containing all letter characters, as defined in Unicode General Category L* & M*. */ 183 | static letters: Charset 184 | 185 | /** The character set containing all lowercase letter characters, as defined in Unicode General Category Ll. */ 186 | static lower: Charset 187 | 188 | /** The character set containing all newline characters (U+000A ~ U+000D, U+0085, U+2028, and U+2029). */ 189 | static newlines: Charset 190 | 191 | /** The character set containing all symbol characters, as defined in Unicode General Category S*. */ 192 | static symbols: Charset 193 | 194 | /** The character set containing all uppercase letter characters, as defined in Unicode General Category Lu and Lt. */ 195 | static upper: Charset 196 | 197 | /** The character set containing all whitespace characters, as defined in Unicode General Category Zs and CHARACTER TABULATION (U+0009). */ 198 | static whitespace: Charset 199 | 200 | /** The character set containing all whitespace and newline characters, as defined in Unicode General Category Z*, U+000A ~ U+000D, and U+0085. */ 201 | static whitespaceAndNewlines: Charset 202 | 203 | /** Returns a new character set that concatenates all characters in the receiver as well as any other charsets provided as arguments. */ 204 | concat(...charsets: Charset[]): Charset 205 | 206 | /** Returns a new character set that forms an intersection of the receiver as well as any other charsets provided as arguments. */ 207 | intersect(...charsets: Charset[]): Charset 208 | 209 | /** Returns a new character set that represents the inverse of the receiver. */ 210 | invert(): Charset 211 | } 212 | 213 | /// https://docs.nova.app/api-reference/clipboard/ 214 | 215 | interface Clipboard { 216 | /** Returns a `Promise` object that resolves to the current text on the user’s clipboard. If the data on the clipboard is not text, or there is no data on the clipboard, the promise resolves to an empty string. */ 217 | readText(): Promise<string> 218 | /** Writes text to the user’s pasteboard, replacing its contents. Returns a `Promise` that resolves when writing is complete. */ 219 | writeText(text: string): Promise<void> 220 | } 221 | 222 | /// https://docs.nova.app/api-reference/color/ 223 | 224 | /** @since 3.0 */ 225 | enum ColorFormat { 226 | /** sRGB color space, 3-component RGB format */ 227 | rgb = "rgb", 228 | 229 | /** sRGB color space, 3-component HSL format */ 230 | hsl = "hsl", 231 | 232 | /** sRGB color space, 3-component HSB format */ 233 | hsb = "hsb", 234 | 235 | /** Display P3 color space, 3-component RGB format */ 236 | displayP3 = "p3", 237 | } 238 | 239 | type ColorComponents = [number, number, number, number?] 240 | 241 | /** 242 | * A `Color` object represents a color that can be displayed to the user. 243 | * 244 | * The `Color` class is not subclassable. 245 | * @example 246 | * let color = new Color(ColorFormat.rgb, [1, 0, 0.5, 1]); 247 | * 248 | * color.format == ColorFormat.rgb ==> true; 249 | * 250 | * let red = color.components[0]; 251 | * let green = color.components[1]; 252 | * let blue = color.components[2]; 253 | * let alpha = color.components[3]; 254 | */ 255 | declare class Color { 256 | /** 257 | * Creates a new `Color` object in a supported format using the provided components. The components must be an array of numbers, and contain only as many components as required by the format chosen. 258 | * 259 | * Currently, all formats supported require at least 3 components, and most support up to 4 (three color values and an alpha value). 260 | * @throws An attempt to create a color object with the incorrect number of components will raise an `Error`. 261 | */ 262 | constructor(format: ColorFormat, components: ColorComponents) 263 | 264 | /** The format of the color, as a string. */ 265 | readonly format: ColorFormat 266 | 267 | /** The array of component numbers for the color. */ 268 | readonly components: ColorComponents 269 | 270 | /** 271 | * Creates a new color using the RGB format and sRGB color space, with an optional alpha value. If the alpha value is not specified, 1.0 will be used. 272 | * @since 3.0 273 | */ 274 | static rgb(red: number, green: number, blue: number, alpha: number = 1.0): Color 275 | 276 | /** 277 | * Creates a new color using the HSL format and sRGB color space, with an optional alpha value. If the alpha value is not specified, 1.0 will be used. 278 | * @since 3.0 279 | */ 280 | static hsl(hue: number, saturation: number, luminance: number, alpha: number = 1.0): Color 281 | 282 | /** 283 | * Creates a new color using the HSB format and sRGB color space, with an optional alpha value. If the alpha value is not specified, 1.0 will be used. 284 | * @since 3.0 285 | */ 286 | static hsb(hue: number, saturation: number, brightness: number, alpha: number = 1.0): Color 287 | 288 | /** 289 | * Creates a new color using the Display P3 format and color space, with an optional alpha value. If the alpha value is not specified, 1.0 will be used. 290 | * @since 3.0 291 | */ 292 | static displayP3(red: number, green: number, blue: number, alpha: number = 1.0): Color 293 | 294 | /** Converts the receiver into a different color format, returning a new `Color` object. */ 295 | convert(format: ColorFormat): Color 296 | } 297 | 298 | /// https://docs.nova.app/api-reference/color-candidate/ 299 | 300 | /** 301 | * A `ColorCandidate` object represents a range of text within a document that could possibly be parsed into a [ColorInformation](https://docs.nova.app/api-reference/color-information) object to provide live color annotations in an editor. 302 | * 303 | * Color candidates can be automatically parsed from a document for any syntax tree nodes which utilize the `value.color` selector classes. Color assistants may then use these candidates for quicker parsing of [ColorInformation](https://docs.nova.app/api-reference/color-information) objects, as opposed to parsing the entire contents of the editor. 304 | * 305 | * The `ColorCandidate` class is not subclassable. 306 | * @since 5.0 307 | */ 308 | interface ColorCandidate { 309 | /** The range of the document where the color exists, as a [Range](https://docs.nova.app/api-reference/range) object. */ 310 | range: Range 311 | // TODO: Check for undefined 312 | 313 | /** The textual contents of the document at the candidate’s range as a `String`. */ 314 | text: string 315 | // TODO: Check if it is settable since undocumented 316 | // TODO: Check for undefined 317 | } 318 | 319 | /// https://docs.nova.app/api-reference/color-information/ 320 | 321 | /** 322 | * A `ColorInformation` object represents an instance of a [Color](https://docs.nova.app/api-reference/color) within a document, and defines the text range at which the color is located. 323 | * 324 | * The `ColorInformation` class is not subclassable. 325 | * @since 5.0 326 | * @example 327 | * let color = new Color(ColorFormat.rgb, [1, 0, 0.5, 1]); 328 | * let range = new Range(100, 107); 329 | * let colorInfo = new ColorInformation(range, color, "hex"); 330 | */ 331 | declare class ColorInformation { 332 | /** 333 | * Creates a new `ColorInformation` object with the provided [Range](https://docs.nova.app/api-reference/range) and [Color](https://docs.nova.app/api-reference/color) values. 334 | * 335 | * The optional `kind` argument should be a string that represents the “type” of color presentation the created color information object represents. 336 | */ 337 | constructor(range: Range, color: Color, kind?: string) 338 | 339 | /** The color represented by the object as a [Color](https://docs.nova.app/api-reference/color) object. */ 340 | color: Color 341 | 342 | /** 343 | * The presentation kind that by which the color information is represented. 344 | * 345 | * This value will be used by the editor color picker to automatically select the first [ColorPresentation](https://docs.nova.app/api-reference/color-presentation) object returned from the relevant color assistant that matches this `kind`. This way, as a user alters the value of a color, the text presentation of the new color can be consistent. If this value is not provided, then no attempt to match presentation kinds will be attempted. 346 | */ 347 | kind?: string 348 | 349 | /** The range of the document where the color exists, as a [Range](https://docs.nova.app/api-reference/range) object. */ 350 | range: Range 351 | 352 | /** A boolean value indicating whether the color information uses floating-point values for its components (not including alpha), such as an RGB presentation that uses floating point values between `0.0` and `1.0`. This property may be provided as a hint as to which editing controls should be displayed when the color information is chosen. If not provided, it is assumed this value is `false`. */ 353 | usesFloats?: boolean 354 | } 355 | 356 | /// https://docs.nova.app/api-reference/color-information-context/ 357 | 358 | /** 359 | * A `ColorInformationContext` object contains contextual information about a request to provide a set of [ColorInformation](https://docs.nova.app/api-reference/color-information) for a [TextEditor](https://docs.nova.app/api-reference/text-editor). A color information context is provided as part of an invocation of the `provideColors(editor, context)` for a color assistant. 360 | * 361 | * The `ColorInformationContext` class is not subclassable. 362 | * @since 5.0 363 | */ 364 | interface ColorInformationContext { 365 | /** 366 | * An array of [ColorCandidate](https://docs.nova.app/api-reference/color-candidate) objects representing *possible* colors in the document based on the available syntax grammar. 367 | * 368 | * These candidates, if available, are automatically parsed from the document for any syntax tree nodes using the `value.color` selector classes. Color assistants may use these values for quicker parsing of color values as opposed to parsing the entire contents of the editor. 369 | * 370 | * If no color information could be parsed from the syntax tree, this property will be an empty array. 371 | */ 372 | readonly candidates: ReadonlyArray<ColorCandidate> 373 | } 374 | 375 | /// https://docs.nova.app/api-reference/color-presentation/ 376 | 377 | /** 378 | * A `ColorPresentation` object represents a single way a [Color](https://docs.nova.app/api-reference/color) object can be represented in the text of a document. Examples of this include the various CSS color types (#HEX, rgb(), rgba(), etc.). 379 | * 380 | * The `ColorPresentation` class is not subclassable. 381 | * @since 5.0 382 | * @example 383 | * let string = "#000000"; 384 | * let presentation = new ColorPresentation(string, "hex"); 385 | */ 386 | declare class ColorPresentation { 387 | /** 388 | * Creates a new `ColorPresentation` object with the provided label string. 389 | * 390 | * The optional `kind` argument may be a string that represents the “type” of the color presentation. This value will be used by a color picker to automatically select the most consistent representation based on any existing color at the relevant location when performing color mixing. This string is arbitrary and can be decided by the extension. 391 | */ 392 | constructor(label: string, kind?: string) 393 | 394 | /** An array of [TextEdit](https://docs.nova.app/api-reference/text-edit) objects describing additional changes to apply to the editor when this presentation is chosen, unrelated to the change made via the `textEdit` or `label` properties. The ranges of these edits must not intersect each other nor the current editor selection. */ 395 | additionalTextEdits?: TextEdit[] 396 | 397 | /** The closest [Color Format](https://docs.nova.app/api-reference/color/#formats) for which the provided color presentation represents. This property may be provided as a hint as to which editing controls should be displayed when the presentation is chosen. If not provided, the color picker will attempt to interpret to the best of its ability. */ 398 | format?: ColorFormat 399 | 400 | /** The text used when inserting the presentation into the editor. If not specified, `label` will be used. */ 401 | insertText?: string 402 | 403 | /** 404 | * The presentation kind may be a string that represents the “type” of the color presentation. 405 | * 406 | * This value will be used by a color picker to automatically select the most consistent representation based on any existing color at the relevant location when performing color mixing. This string is arbitrary and can be decided by the extension. 407 | */ 408 | kind?: string 409 | 410 | /** The user-readable label for the presentation. This will be displayed in the color picker’s presentations list. */ 411 | label: string 412 | 413 | /** 414 | A boolean value indicating whether the presentation uses floating-point values for its components (not including alpha), such as an RGB presentation that uses floating point values between `0.0` and `1.0`. This property may be provided as a hint as to which editing controls should be displayed when the presentation is chosen. If not provided, it is assumed this value is `false`. */ 415 | usesFloats?: boolean 416 | } 417 | 418 | /// https://docs.nova.app/api-reference/color-presentation-context/ 419 | 420 | /** 421 | * A `ColorPresentationContext` object contains contextual information about a request to provide a set of [ColorPresentation](https://docs.nova.app/api-reference/color-presentation) for a [Color](https://docs.nova.app/api-reference/color) object. A color presentation context is provided as part of an invocation of the `provideColorPresentations(color, editor, context)` for a color assistant. 422 | * 423 | * The `ColorPresentationContext` class is not subclassable. 424 | * @since 5.0 425 | */ 426 | interface ColorPresentationContext { 427 | /** The range of text within the editor into which a presentation will be inserted if accepted by the user, as a [Range](https://docs.nova.app/api-reference/range). This value may be used to compute a [TextEdit](https://docs.nova.app/api-reference/text-edit) object to assign to a color presentation. */ 428 | readonly range: Range 429 | } 430 | 431 | /// https://docs.nova.app/api-reference/commands-registry/ 432 | 433 | type Transferrable = 434 | | Transferrable[] 435 | | ReadonlyArray<Transferrable> 436 | | Date 437 | | null 438 | | number 439 | | { [key: string]: Transferrable } 440 | | RegExp 441 | | string 442 | | Color 443 | | Range 444 | 445 | /** The `CommandsRegistry` class is used to register and invoke extension commands. A shared instance of the class is always available as the `nova.commands` environment property. */ 446 | interface CommandsRegistry { 447 | /** 448 | * Registers a command with the registry, making it available for binding to command palette and menu items declared in the extension’s `extension.json` file. 449 | * 450 | * If the command should be user-visible, the `name` argument should match a command declared in the [extension manifest](https://docs.nova.app/extensions/commands/#defining-a-command). 451 | * 452 | * The `callable` will be invoked with a different first argument depending on the category / context in which the command is defined: 453 | * - Commands that are present in the Editor menu (using the `editor` [commands category](https://docs.nova.app/extensions/commands/#defining-a-command)) will receive the focused [TextEditor](https://docs.nova.app/api-reference/text-editor) object 454 | * - Commands appearing in all other categories will receive the current [Workspace](https://docs.nova.app/api-reference/workspace) object 455 | * - Commands that are not defined in the manifest will receive the current [Workspace](https://docs.nova.app/api-reference/workspace) object 456 | * 457 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 458 | */ 459 | register<T>(name: string, callable: (this: T, ...params: any[]) => void, thisValue?: T): Disposable 460 | 461 | /** 462 | * Invokes the command registered for a given name, if any. 463 | * 464 | * The command’s callback will be invoked as if the user had chosen it from the Extensions menu (or command palette). 465 | * 466 | * The first argument the command’s callback receives will be the current [Workspace](https://docs.nova.app/api-reference/workspace). Additional arguments provided to this method will be delivered to the command after this workspace argument, assuming they are [valid to be transferred to the command](https://docs.nova.app/api-reference/commands-registry/#supported-types-for-arguments). 467 | * 468 | * This method returns a `Promise` object that resolves to the result of invoking the command. If no command is registered for the name, the promise will be rejected with an error. 469 | */ 470 | invoke(name: string, ...arguments: Transferrable[]): Promise<unknown> 471 | } 472 | 473 | /// https://docs.nova.app/api-reference/completion-color-pop/ 474 | 475 | /** 476 | * A `CompletionColorPop` object defines a color pop. By creating and returning a color pop object as part of the completions, an extension indicates that a color pop should be offered to the user to mix and choose colors. 477 | * 478 | * The `CompletionColorPop` class is not subclassable. 479 | * @since 5.0 480 | */ 481 | declare class CompletionColorPop { 482 | /** Creates a new color pop. Color pops do not currently have any further properties or options. */ 483 | constructor() 484 | } 485 | 486 | /// https://docs.nova.app/api-reference/completion-context/ 487 | 488 | declare enum CompletionReason { 489 | /** Completion was triggered direct by the user, such as by hitting the escape key. */ 490 | Invoke, 491 | 492 | /** Completion was triggered by the user typing a character. */ 493 | Character 494 | } 495 | 496 | /** A `CompletionContext` object defines information about the request for completion items within an editor. A completion context is used when building [CompletionItem](https://docs.nova.app/api-reference/completion-item) objects. */ 497 | interface CompletionContext { 498 | /** The word immediately proceeding the cursor, or an empty string if no word exists. The cursor will be positioned directly after the last character in this string. */ 499 | readonly text: string 500 | 501 | /** The text of the entire line preceding the cursor, not including indentation whitespace. The cursor will be positioned directly after the last character in this string. */ 502 | readonly line: string 503 | 504 | /** 505 | * A [Charset](https://docs.nova.app/api-reference/charset) object defining the set of identifier characters valid for the syntax used for the completion request. This represents the set of characters that are normally valid for automatically invoking completion requests. 506 | * @since 3.0 507 | */ 508 | readonly identifierChars: Charset 509 | 510 | /** The character position of the cursor within the requesting text editor, as a number. */ 511 | readonly position: number 512 | 513 | /** The reason the completion was triggered, as a value from the `CompletionReason` enumeration. */ 514 | readonly reason: CompletionReason 515 | 516 | /** An array of [ScopeSelector](https://docs.nova.app/api-reference/scope-selector) objects that reflect the tree of syntax grammar selectors for the completion position. The array will be ordered depth, with deepest first, where the first item in the array is the syntax scope encompassing the completion position, the next item is its ancestor, onwards to the final item which represents the root of the tree. */ 517 | readonly selectors: ReadonlyArray<ScopeSelector> 518 | 519 | /** 520 | * The character that triggered the completion request as a `String`. If the request was not triggered by a character (such as if the `reason` is `Invoke`), this will return `null` or `undefined`. 521 | * @since 3.0 522 | */ 523 | readonly triggerCharacter?: string | null 524 | } 525 | 526 | /// https://docs.nova.app/api-reference/completion-item/ 527 | 528 | /** 529 | * A `CompletionItem` object defines a single item displayed in the editor completions (autocomplete) list. Items define what happens when the user selects the item, such as replacing text at the cursor position and invoking an extension command. 530 | * 531 | * The `CompletionItem` class is not subclassable. 532 | */ 533 | declare class CompletionItem { 534 | /** 535 | * Creates a new completion item. 536 | * @example 537 | * let item = new CompletionItem("foobar()", CompletionItemKind.Function); 538 | * 539 | * item.documentation = "Performs the foobar request."; 540 | * item.insertText = "foobar(${0:args})"; 541 | * item.insertTextFormat = InsertTextFormat.Snippet; 542 | */ 543 | constructor(label: string, kind: CompletionItemKind) 544 | 545 | /** 546 | * An array of [TextEdit](https://docs.nova.app/api-reference/text-edit) objects describing additional changes to apply to the editor when this item is chosen, unrelated to the change made to the completion position. The ranges of these edits must not intersect each other nor the `range` of the completion item’s primary edit. 547 | * @since 2.0 548 | */ 549 | additionalTextEdits?: TextEdit[] 550 | 551 | /** 552 | * A [Color](https://docs.nova.app/api-reference/color) object to display as a swatch in place of a symbol icon, if the item’s kind is set to `Color`. 553 | * @since 1.2 554 | */ 555 | color?: Color 556 | 557 | /** A [Charset](https://docs.nova.app/api-reference/charset) object that specify the character set that, if typed while the item is highlighted, will accept the completion before inserting the typed character. */ 558 | commitChars?: Charset 559 | 560 | /** An additional label for the item that is displayed alongside it, such as its type name. */ 561 | detail?: string 562 | 563 | /** A user-visible documentation string displayed at the bottom of the completions panel when the item is highlighted. */ 564 | documentation?: string 565 | 566 | /** The text used when filtering the item. If not specified, `label` will be used. */ 567 | filterText?: string 568 | 569 | /** The text used when inserting the item into the editor. If not specified, `label` will be used. */ 570 | insertText?: string 571 | 572 | /** 573 | * The format used when inserting the item’s `insertText`, specified using the `InsertTextFormat` enum. 574 | * @since 1.2 575 | */ 576 | insertTextFormat?: InsertTextFormat 577 | 578 | /** The kind of item, specified using the `CompletionItemKind` enum, which affects things such as the icon displayed beside the item, such as `CompletionItemKind.Function`. */ 579 | readonly kind: CompletionItemKind 580 | 581 | /** The user-visible name of the item in the completions list. By default, this is the text that is also inserted into the editor when the item is chosen. */ 582 | readonly label: string 583 | 584 | /** 585 | * If the item’s kind is `CompletionItemKind.File` and this property is set to a file path, the file’s icon will be used for the completion item (as long as the `image` is not also set). 586 | * 587 | * Additionally, the file path may be shown beside the completion item to indicate the full path it represents (if, for example, the item’s name is just the file or module name). 588 | * @since 7.0 589 | */ 590 | path?: string 591 | 592 | /** A [Range](https://docs.nova.app/api-reference/range) value that describes the textual range within the editor that should be replaced when the item is chosen. If not specified, the word preceeding the cursor will be replaced. */ 593 | range?: Range 594 | 595 | /** 596 | * **This property is deprecated as of Nova 1.2. Consider using the insertTextFormat property instead.** 597 | * 598 | * Whether the text inserted by the completion should parsed for a special tokenization format. 599 | * 600 | * If `true`, then occurrences of the format `$[value]` (a name surrounded by brackets and prefixed with a dollar sign) will be replaced by editor tokens containing the name `value`, where `value` may be any string that contains any characters other than `$`, `[` and `]`. By default this property is false. 601 | * 602 | * For backwards compatibility, settings this value to `true` will modify the `insertTextFormat` to a private value representing this format. This format may not be used alongside other insertion formats and its use is discouraged going forward. 603 | * @deprecated since 1.2 604 | */ 605 | tokenize?: boolean 606 | } 607 | 608 | declare enum CompletionItemKind { 609 | // Types 610 | 611 | /** A generic object type or metatype. */ 612 | Type, 613 | /** An object class type. */ 614 | Class, 615 | /** An extension to a type. */ 616 | Category, 617 | /** An interface of type conformance. */ 618 | Interface, 619 | /** An enumeration of values. */ 620 | Enum, 621 | /** A union of types. */ 622 | Union, 623 | /** A simple type structure. */ 624 | Struct, 625 | 626 | // Types 627 | 628 | /** A self-contained callable. */ 629 | Function, 630 | /** A callable member of an object. */ 631 | Method, 632 | /** A self-contained closure. */ 633 | Closure, 634 | /** An object type constructor. */ 635 | Constructor, 636 | /** 637 | * An object type destructor. 638 | * @since 4.0 639 | */ 640 | Destructor, 641 | /** An object property getter. */ 642 | Getter, 643 | /** An object property setter. */ 644 | Setter, 645 | /** 646 | * A static callable member of a type. 647 | * @since 4.0 648 | */ 649 | StaticMethod, 650 | 651 | // Values 652 | 653 | /** A non-modifyable value. */ 654 | Constant, 655 | /** A modifyable value. */ 656 | Variable, 657 | /** An object property value. */ 658 | Property, 659 | /** An argument passed to a callable. */ 660 | Argument, 661 | /** A color value. */ 662 | Color, 663 | /** A member value of an enumeration. */ 664 | EnumMember, 665 | /** 666 | * A static type property value. 667 | * @since 4.0 668 | */ 669 | StaticProperty, 670 | 671 | // Expressions 672 | 673 | /** An inline expression. */ 674 | Expression, 675 | /** An inline statement. */ 676 | Statement, 677 | /** A logical code package. */ 678 | Package, 679 | /** A referenced document. */ 680 | File, 681 | /** An external reference. */ 682 | Reference, 683 | /** A syntactic keyword. */ 684 | Keyword, 685 | 686 | // StyleSheets 687 | 688 | /** A set of rules, such as CSS attributes. */ 689 | StyleRuleset, 690 | /** A set of directives, such as a CSS @at-rule. */ 691 | StyleDirective, 692 | /** A style ID selector. */ 693 | StyleID, 694 | /** A style class selector. */ 695 | StyleClass, 696 | /** 697 | * A style pseudo-class selector. 698 | * @since 4.0 699 | */ 700 | StylePseudoClass, 701 | /** 702 | * A style pseudo-element selector. 703 | * @since 4.0 704 | */ 705 | StylePseudoElement, 706 | 707 | // Tags 708 | 709 | /** A generic markup tag. */ 710 | Tag, 711 | /** 712 | * A document head (metadata) tag. 713 | * @since 4.0 714 | */ 715 | TagHead, 716 | /** 717 | * A document title tag. 718 | * @since 4.0 719 | */ 720 | TagTitle, 721 | /** 722 | * A document metadata item tag. 723 | * @since 4.0 724 | */ 725 | TagMeta, 726 | /** 727 | * An external resource reference tag (link). 728 | * @since 4.0 729 | */ 730 | TagLink, 731 | /** 732 | * A document body tag. 733 | * @since 4.0 734 | */ 735 | TagBody, 736 | /** 737 | * An scripting reference tag. 738 | * @since 4.0 739 | */ 740 | TagScript, 741 | /** 742 | * A styleset reference tag. 743 | * @since 4.0 744 | */ 745 | TagStyle, 746 | /** 747 | * A heading tag (h1, etc.). 748 | * @since 4.0 749 | */ 750 | TagHeading, 751 | /** 752 | * A section tag (section, nav, etc.). 753 | * @since 4.0 754 | */ 755 | TagSection, 756 | /** 757 | * A generic container tag (div, span). 758 | * @since 4.0 759 | */ 760 | TagContainer, 761 | /** 762 | * An unordered list tag. 763 | * @since 4.0 764 | */ 765 | TagUnorderedList, 766 | /** 767 | * An ordered list tag. 768 | * @since 4.0 769 | */ 770 | TagOrderedList, 771 | /** 772 | * A list item tag. 773 | * @since 4.0 774 | */ 775 | TagListItem, 776 | /** 777 | * An external resource anchor tag (a). 778 | * @since 4.0 779 | */ 780 | TagAnchor, 781 | /** 782 | * An external image reference tag (img). 783 | * @since 4.0 784 | */ 785 | TagImage, 786 | /** 787 | * An external media asset reference tag (audio, etc.). 788 | * @since 4.0 789 | */ 790 | TagMedia, 791 | /** 792 | * A form tag. 793 | * @since 4.0 794 | */ 795 | TagForm, 796 | /** 797 | * A form field tag. 798 | * @since 4.0 799 | */ 800 | TagFormField, 801 | /** 802 | * A framework tag (PHP, etc). 803 | * @since 4.0 804 | */ 805 | TagFramework, 806 | } 807 | 808 | declare enum InsertTextFormat { 809 | /** Inserts as plain text. This is the default. */ 810 | PlainText, 811 | 812 | /** Inserts text using the [Snippets](https://docs.nova.app/extensions/snippets) format. Snippet placeholders will be resolved into editor tokens. */ 813 | Snippet, 814 | } 815 | 816 | /// https://docs.nova.app/api-reference/composite-disposable/ 817 | 818 | /** 819 | * A `CompositeDisposable` collects together multiple [Disposable](https://docs.nova.app/api-reference/disposable) objects, ensuring that when the composite is disposed, the objects contained therein are also disposed appropriately. 820 | * 821 | * The `CompositeDisposable` class is not subclassable. 822 | * @implements {Disposable} 823 | */ 824 | interface CompositeDisposable extends Disposable { 825 | /** Adds an object to the receiver, which will receive a call to `dispose()` when the composite object is disposed. Calling this method multiple times with the same object will only add it once. If the composite has already been disposed, this effectively does nothing. */ 826 | add(object: Disposable): void 827 | 828 | /** Removes an object from the receiver, so that it will not receive a call to `dispose()` when the composite is disposed. If the composite has already been disposed, this effectively does nothing. */ 829 | remove(object: Disposable): void 830 | 831 | /** An alias for `remove()`. */ 832 | delete(object: Disposable): void 833 | 834 | /** Removes all objects from the receiver, so that they will not receive a call to `dispose()` when the composite is disposed. If the composite has already been disposed, this effectively does nothing. */ 835 | clear(): void 836 | } 837 | 838 | /// https://docs.nova.app/api-reference/configuration/ 839 | 840 | type ConfigurationValue = string | number | boolean | string[] 841 | 842 | /** 843 | * A `Configuration` is a key-value storage that can be persistently saved on disk. Configurations are provided by the extension API for the user’s global preferences (see [Environment](https://docs.nova.app/api-reference/environment)) and [Workspace](https://docs.nova.app/api-reference/workspace) preferences. 844 | * 845 | * Keys in a configuration can optionally have a default value set by either the application or an extension. In this case, calls to `get` for a configuration that does not have an explicit value set will return the default value. 846 | */ 847 | interface Configuration { 848 | /** 849 | * Adds an event listener that invokes the provided `callback` when a specific configuration key is changed. The callback will receive the new and old values of the key. 850 | * 851 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 852 | */ 853 | onDidChange<T, V>(key: string, callback: (this: T, newValue: V, oldValue: V) => void, thisValue?: T): Disposable 854 | 855 | /** 856 | * Adds an event listener that invokes the provided `callback` when a specific configuration key is changed. The callback will receive the new and old values of the key. Similar to `onDidChange()`, except that this method immediate invokes the callback with the current value of the key. Returns a [Disposable](https://docs.nova.app/api-reference/disposable) object that can be used to cancel the event listener. 857 | * 858 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 859 | */ 860 | observe<T, V>(key: string, callback: (this: T, newValue: V, oldValue: V) => void, thisValue?: T): Disposable 861 | 862 | /** 863 | * Gets the current value of a key in the configuration. Returns null if no value and no default is set. 864 | * 865 | * If the optional `coerce` argument is provided, the value can be automatically coerced to ensure a specific type. The following coercion types are supported: 866 | * - “string”: ensures that the value is a String, otherwise returning `null` 867 | * - “number”: ensures that the value is a Number, otherwise returning `null` 868 | * - “array”: ensures that the value is an Array of String, otherwise returning `null` 869 | * - “boolean”: ensures that the value is a Boolean, otherwise returning `null` 870 | */ 871 | get(key: string): ConfigurationValue | null 872 | get(key: string, coerce: "string"): string | null 873 | get(key: string, coerce: "number"): number | null 874 | get(key: string, coerce: "array"): string[] | null 875 | get(key: string, coerce: "boolean"): boolean | null 876 | 877 | /** 878 | * Sets the value of the provided key in the configuration. If `value` is `undefined`, this will effectively remove the key from the configuration, returning it to its default value (if any). 879 | * 880 | * @throws This method will throw an `Error` if the provided value is not a `String`, `Number`, `Boolean`, `Array` of `String`, `null`, or `undefined`. 881 | */ 882 | set(key: string, value?: ConfigurationValue | null): void 883 | 884 | /** Removes the value for the provided key in the configuration, returning it to its default value (if any). This is effectively the same as passing `undefined` to the `.set()` method. */ 885 | remove(key: string): void 886 | } 887 | 888 | /// https://docs.nova.app/api-reference/console/ 889 | 890 | /** The `Console`, like its browser counterpart, exposes API related to logging information to the built-in extension console. An instance is always available via the `console` global object. */ 891 | interface Console { 892 | /** Asserts that an expression evaluates to `true`. If additional arguments are provided, they will be formatted as arguments in the same way as `log()`. 893 | * @throws If not, the provided `message` will be used to raise an `Error`. 894 | */ 895 | assert(condition: () => unknown, message: string, ...params: unknown[]): void 896 | 897 | /** Clears all console messages dispatched from the current extension. */ 898 | clear(): void 899 | 900 | /** Logs the provided `message` to the console. If additional arguments are provided, they will be used as substring formatting for the message using JavaScript substring semantics. */ 901 | log(message: unknown, ...params: unknown[]): void 902 | 903 | /** Logs an informative message to the console. Informative messages are of a lower priority than standard log messages, warnings, or errors, and will never alert the user in any way. This method otherwise behaves very similarly to `log()`. */ 904 | info(message: unknown, ...params: unknown[]): void 905 | 906 | /** Logs a warning message to the console. Warning messages are of a higher priority than standard log messages, but lower priority than errors, and may alert the user in some way. They should be used to indicate that an operation encountered an unexpected state, but can safely continue. This method otherwise behaves very similarly to `log()`. */ 907 | warn(message: unknown, ...params: unknown[]): void 908 | 909 | /** Logs an error message to the console. Error messages are of the highest priority in the console, and may alert the user in some way. They should be used to indicate that an operation encountered an unexpected state and cannot continue. This method otherwise behaves very similarly to `log()`. */ 910 | error(message: unknown, ...params: unknown[]): void 911 | 912 | /** Begins a logging group. Multiple calls to this method will increase the nested group level by one, and should be balanced by an equal number of calls to `groupEnd()`. */ 913 | group(): void 914 | 915 | /** Ends the deepest nested logging group. Calls to `group()` must be balanced by an equal number of calls to this method. */ 916 | groupEnd(): void 917 | 918 | /** Logs the number of times this method has been invoked with the provided label. If no label is provided, this method will log the number of times it has been invoked at the current line. */ 919 | count(label?: string): void 920 | 921 | /** Starts a timer with a provided label. When a call to `timeEnd()` is made using the same label, the total elapsed duration of the timer in milliseconds will be logged to the console. */ 922 | time(label: string): void 923 | 924 | /** Ends the timer with a provided label, logging the total elapsed duration of the timer in milliseconds to the console. */ 925 | timeEnd(label: string): void 926 | 927 | /** Logs the current elapsed duration of a timer with the provided label to the console, without ending the timer. If no label is provided, this method will log the current elapsed duration of all running timers. */ 928 | timeStamp(label?: string): void 929 | 930 | /** Outputs a stack trace to the console. */ 931 | trace(): void 932 | } 933 | 934 | declare const console: Console 935 | 936 | /// https://docs.nova.app/api-reference/credentials/ 937 | 938 | type User = unknown 939 | 940 | interface Credentials { 941 | /** 942 | * Retrieves a password for a given service and user, returning a `String`, or `null` if no password was found. 943 | * @throws Will raise an `Error` if communication with the Keychain API fails. 944 | */ 945 | getPassword(service: string, user: User): string | null 946 | 947 | /** 948 | * Sets a password for a given service and user. The password must be a `String` value. 949 | * @throws Will raise an `Error` if communication with the Keychain API fails. 950 | */ 951 | setPassword(service: string, user: User, password: string): null 952 | 953 | /** 954 | * Removes a password for a given service and user. 955 | * @throws Will raise an `Error` if communication with the Keychain API fails. 956 | */ 957 | removePassword(service: string, user: User): null 958 | } 959 | 960 | /// https://docs.nova.app/api-reference/crypto/ 961 | 962 | type IntegerTypedArray = 963 | | Int8Array 964 | | Uint8Array 965 | | Uint8ClampedArray 966 | | Int16Array 967 | | Uint16Array 968 | | Int32Array 969 | | Uint32Array 970 | // | BigInt64Array 971 | // | BigUint64Array 972 | // TODO: Int64 arrays are not resolved 973 | 974 | /** 975 | * The `nova.crypto` global object is used to generate cryptographic primitives for use in secure operations. 976 | * @since 10.0 977 | */ 978 | interface Crypto { 979 | /** Fills the provided [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays) with cryptographically-sound random values. The provided array should be one of the JavaScript integer-based typed arrays, such as `Int8Array`, `Uint8Array`, `Int16Array`, etc. All elements of the array will be overwritten. This method returns the same array instance as was passed as an argument. */ 980 | getRandomValues<T extends IntegerTypedArray>(typedArray: T): T 981 | 982 | /** Returns a randomly generated, 36-character UUID v4 identifier string. */ 983 | randomUUID(): string 984 | } 985 | 986 | /// https://docs.nova.app/api-reference/debug-session/ 987 | 988 | /** 989 | * A `DebugSession` object represents a single debug session running in tandem with an [adapter](https://docs.nova.app/extensions/debug-adapters) conforming to the [Debug Adapter Protocol](https://microsoft.github.io/debug-adapter-protocol/). Instances of this class can be used to send custom requests to and receive custom events from the adapter. 990 | * 991 | * The target of a debug session (or the *debuggee*) can be many things, such as an external process, a web page running within a browser, or a script running on a remote host. 992 | * 993 | * Debug sessions are started by providing a [TaskDebugAdapterAction](https://docs.nova.app/api-reference/task-debug-adapter-action) object when resolving an action via the [Tasks API](https://docs.nova.app/extensions/run-configurations). 994 | * 995 | * Debug session objects can be received from the [Workspace](https://docs.nova.app/api-reference/workspace) via the `debugSessions` property or the `onDidStartDebugSession()` and `onDidEndDebugSession()` methods. 996 | * 997 | * The `DebugSession` class is not subclassable. 998 | * @since 9.0 999 | */ 1000 | interface DebugSession { 1001 | /** The identifier of the debug session. Each session has an identifier that is unique to the workspace. Since multiple sessions may be started for a single debug adapter this value is not the same as the debug adapter’s identifier. */ 1002 | readonly identifier: string 1003 | 1004 | /** The user-readable name for the debug session as determined by the task invoked by the user to start the session. */ 1005 | readonly name: string 1006 | 1007 | /** The type string of the debug adapter coordinating the session. This value is the same as the `adapterType` argument provided when creating a [TaskDebugAdapterAction](https://docs.nova.app/api-reference/task-debug-adapter-action) object. */ 1008 | readonly type: string 1009 | 1010 | /** 1011 | * Adds an event listener that invokes the provided `callback` when a custom event is received from the adapter. The callback will receive as an argument a [DebugSessionCustomEvent](https://docs.nova.app/api-reference/debug-session-custom-event) object representing the event that was received. 1012 | * 1013 | * A custom event is any event not explicitly defined by the [Debug Adapter Protocol](https://microsoft.github.io/debug-adapter-protocol/). No assumptions should be made that callbacks registered with this method will receive events explicitly defined by the protocol, even those that Nova may not yet handle natively (as support for them may be added in the future). If new events are defined in a future version of the protocol this callback *may* be invoked until support for that event is adopted by Nova itself. 1014 | * 1015 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 1016 | */ 1017 | onCustomEvent<T>(event: string, callback: (this: T, event: DebugSessionCustomEvent) => void, thisValue?: T): Disposable 1018 | 1019 | /** 1020 | * Sends a request to the debug adapter. This request may be a custom request not defined by the Debug Adapter Protocol. 1021 | * 1022 | * The `command` argument should be a string representing the request to invoke. 1023 | * 1024 | * The `arguments` object can be any JSON-codable value that the adapter expects as the arguments to the request. 1025 | * 1026 | * This method returns a `Promise` object which will resolve or reject when the request is handled by the adapter. It may also be rejected if the debug session ends before a response is received. The resolved value will be the JSON value provided in the response object from the adapter. 1027 | */ 1028 | sendRequest(command: string, arguments: any): Promise<unknown> 1029 | 1030 | /** 1031 | * Starts a child session running within the scope of the receiver. Child sessions are coordinated as sub-tasks of a parent session to allow grouping multiple debugged targets together (such as a subprocess started by a debuggee). 1032 | * 1033 | * The `action` argument should be a [TaskDebugAdapterAction](https://docs.nova.app/api-reference/task-debug-adapter-action) defining how the IDE should connect to the child session. Most often, if a subprocess is started by the debuggee and forwarded by the adapter the child session will be started with an `attach` configuration to connect Nova to this new session already running. 1034 | * 1035 | * This method will return a `Promise` object which will resolve or reject when the child session either starts or fails to start, respectively. 1036 | * 1037 | * There is (as of early 2022) no mechanism within the Debug Adapter Protocol itself for forwarding notification of child sessions to the IDE. Adapters that utilize this behavior typically define a custom event that is sent when a child session in the IDE is requested. The extension can then use the `onCustomEvent()` method to listen for such events and start child sessions using this method. 1038 | */ 1039 | startChildSession(action: TaskDebugAdapterAction): Promise<void> 1040 | } 1041 | 1042 | /// https://docs.nova.app/api-reference/debug-session-custom-event/ 1043 | 1044 | /** 1045 | * A `DebugSessionCustomEvent` object represents a custom event sent from a debug adapter. 1046 | * 1047 | * Custom events can be received using the `onCustomEvent()` method of the DebugSession class. 1048 | * 1049 | * The `DebugSessionCustomEvent` class is not subclassable. 1050 | * @since 9.0 1051 | */ 1052 | interface DebugSessionCustomEvent { 1053 | /** The body of the event. This may be any JSON-codable value, including `null`. */ 1054 | body: any 1055 | // TODO: Check if it is settable 1056 | // TODO: Check for undefined 1057 | 1058 | /** The event name as a string. */ 1059 | event: string 1060 | // TODO: Check if it is settable 1061 | // TODO: Check for undefined 1062 | } 1063 | 1064 | /// https://docs.nova.app/api-reference/disposable/ 1065 | 1066 | /** 1067 | * A `Disposable` is any object that can be “disposed of” to relinquish its resources or cancel its task. The disposable interface is adopted by several objects returned from standard API methods. To conform to the disposable interface, an object needs only to implement a `dispose()` method. 1068 | * 1069 | * The `Disposable` interface is not subclassable. 1070 | */ 1071 | declare class Disposable { 1072 | /** Returns `true` if the argument provided is a disposable object which responds to `dispose()`. */ 1073 | static isDisposable(object: Object): boolean 1074 | 1075 | /** Relinquishes the object’s resources, which may include stopping a listener, cancelling a task, or some other “event”. Calling `dispose()` multiple times on an object is allowed, but will not affect the object after the first call. */ 1076 | dispose(): void 1077 | } 1078 | 1079 | /// https://docs.nova.app/api-reference/emitter/ 1080 | 1081 | /** 1082 | * An `Emitter` can dispatch events by name to registered listeners. The extension API defines several built-in emitters that are used to dispatch events, and extensions may also create their own emitters to use for event handling. 1083 | * 1084 | * The `Emitter` class is not subclassable. 1085 | * @implements {Disposable} 1086 | * @example 1087 | * let emitter = new Emitter(); 1088 | * 1089 | * emitter.on("myEvent", function(arg1, arg2, arg3) { 1090 | * console.log(arg1, arg2, arg3); 1091 | * }); 1092 | * 1093 | * function doTask() { 1094 | * emitter.emit("myEvent", "foo", "bar", 12); 1095 | * } 1096 | * 1097 | * doTask(); 1098 | * // Logs to console: "foo", "bar", 12 1099 | */ 1100 | declare class Emitter extends Disposable { 1101 | /** Creates a new Emitter object that may be used to register and emit events. */ 1102 | constructor() 1103 | 1104 | /** Adds a listener for the provided event name after any other current listeners. The `callback` argument will be called each time the emitter receives a matching event. */ 1105 | on(eventName: string, callback: (...args: any[]) => void): void 1106 | 1107 | /** Adds a listener for the provided event name after any other current listeners. The `callback` argument will be called the next time the emitter receives a matching event, after which it will be unregistered. */ 1108 | once(eventName: string, callback: (...args: any[]) => void): void 1109 | 1110 | /** Adds a listener for the provided event name before any other current listeners. The `callback` argument will be called each time the emitter receives a matching event. */ 1111 | preempt(eventName: string, callback: (...args: any[]) => void): void 1112 | 1113 | /** Emits a new event with the provided name, optionally including any other provided arguments to the event handler callbacks. */ 1114 | emit(eventName: string, ...args: unknown[]): void 1115 | 1116 | /** Removes all registered listeners for the provided event name, or all listeners if no event name is provided. */ 1117 | clear(eventName?: string): void 1118 | } 1119 | 1120 | /// https://docs.nova.app/api-reference/environment/ 1121 | 1122 | interface Environment { 1123 | /** The global instance AssistantsRegistry object used to register and interact with assistants. */ 1124 | readonly assistants: AssistantsRegistry 1125 | 1126 | /** 1127 | * The global instance Clipboard object. 1128 | * @since 1.2 1129 | */ 1130 | readonly clipboard: Clipboard 1131 | 1132 | /** The global instance CommandsRegistry object used to register and interact with commands. */ 1133 | readonly commands: CommandsRegistry 1134 | 1135 | /** 1136 | * The Configuration object for the application, written into the user’s global preferences. 1137 | * 1138 | * It is recommended that extensions prefix variables they define with a common string, followed by a dot, such as “my_extension.key_name”. 1139 | * 1140 | * Variables defined by an extension’s payload using the “configuration” key will automatically be shown in the extension’s global preferences UI. 1141 | */ 1142 | readonly config: Configuration 1143 | 1144 | /** 1145 | * The global instance Crypto object. 1146 | * @since 10.0 1147 | */ 1148 | readonly crypto: Crypto 1149 | 1150 | /** The global instance of the Credentials object used to interact with credential storage. */ 1151 | readonly credentials: Credentials 1152 | 1153 | /** An `Object` containing the environment variables available to task execution, such as invocations of the Process class. Most often, this includes the values made available to the user’s default login shell. As such, this value can change depending on the state of the user’s preferences for requesting environment from the default login shell. */ 1154 | readonly environment: { [key: string]: string } 1155 | 1156 | /** The current Extension instance representing the running extension. */ 1157 | readonly extension: Extension 1158 | 1159 | /** The global instance of the FileSystem object. */ 1160 | readonly fs: FileSystem 1161 | 1162 | /** An array of strings defining the user’s preferred languages, in BCP 47 format. */ 1163 | readonly locales: ReadonlyArray<string> 1164 | 1165 | /** The global instance of the Path object. */ 1166 | readonly path: Path 1167 | 1168 | /** A CompositeDisposable object that will be cleaned up automatically when the extension is deactivated. Extensions may add any disposable objects they wish to this composite. Built-in objects from the extension runtime do not need to be registered for deactivation (all built-in objects will be cleaned up automatically when an extension is deactivated.) However, custom objects implementing the Disposable interface may wish to receive a call to `dispose()` to perform some action when they are cleaned up. The extension itself should not attempt to dispose of this object, it will be done automatically by the extension runtime at a proper time. */ 1169 | readonly subscriptions: CompositeDisposable 1170 | 1171 | /** The current operation system version, an an `Array` of three `Number` values. Each number corresponds to the major, minor, and patch version of the operation system, respectively (e.g. for *macOS 10.14.0* the returned value would be `[10, 14, 0]`). */ 1172 | readonly systemVersion: [number, number, number] 1173 | 1174 | /** The current application version, as an `Array` of three `Number` values. Each number corresponds to the major, minor, and patch version of the application, respectively (e.g. for *Nova 1.0.2* the returned value would be `[1, 0, 2]`). This array will not reflect whether the application version contains a beta identifier (such as `1.0.2b3`). */ 1175 | readonly version: [number, number, number] 1176 | 1177 | /** The current application version (as a `String`). */ 1178 | readonly versionString: string 1179 | 1180 | /** The current Workspace instance representing the workspace in which the extension is executing. */ 1181 | readonly workspace: Workspace 1182 | 1183 | /** Alert the user by causing an auditory beep. */ 1184 | beep(): void 1185 | 1186 | /** 1187 | * Returns a localized version of the string designated by the specified key and residing in the specified localization table within the extension. 1188 | * 1189 | * This method searches each of the extension’s localizations (directories using an `.lproj` extension) for a JSON file with the name `tableName`. If `tableName` is not provided or `null`, it will search for a default file named `strings.json`. Localizations are searched in the preferred order based on the user’s preferred languages. 1190 | * 1191 | * The return value of this method depends on its arguments: 1192 | * - If `key` is `null` and `value` is `null`, returns an empty string. 1193 | * - If `key` is `null` and `value` is non-null, returns `value`. 1194 | * - If `key` is not found and `value` is `null` or an empty string, returns `key`. 1195 | * - If `key` is not found and `value` is non-null and not empty, return `value`. 1196 | */ 1197 | localize(key: string | null, value?: string | null, tableName?: string | null): string 1198 | 1199 | /** Whether the current application version is a fully-qualified release (`true`) or a pre-release (`false`). */ 1200 | isReleasedVersion(): boolean 1201 | 1202 | /** Whether the current extension is running in development (ad-hoc) mode. */ 1203 | inDevMode(): boolean 1204 | 1205 | /** Requests the application open the global settings view for a specified extension, by identifier. If no identifier is specified, the current extension’s global settings will be opened. */ 1206 | openConfig(identifier?: string): void 1207 | 1208 | /** 1209 | * Asks the application to open a url using the user’s preferred handler. For example, passing an HTTP URL to this method will open it the user’s default browser. 1210 | * 1211 | * The optional `callback` argument should be a callable, which will be invoked when the URL has been handled. The callback will be passed a boolean value indicating whether the URL was successfully opened (an example of failure would be if no application is installed to handle the URL). 1212 | */ 1213 | openURL(url: string, callback?: (success: boolean) => void): void 1214 | } 1215 | 1216 | declare const nova: Environment 1217 | 1218 | /// https://docs.nova.app/api-reference/extension/ 1219 | 1220 | /** The `Extension` class contains properties and method related to the current extension. A single instance is always available via the `nova.extension` global property. */ 1221 | interface Extension { 1222 | /** The identifier of the extension. */ 1223 | readonly identifier: string 1224 | 1225 | /** The user-visible name of the extension. */ 1226 | readonly name: string 1227 | 1228 | /** The vendor of the extension. */ 1229 | readonly vendor: string 1230 | 1231 | /** The version string of the extension. */ 1232 | readonly version: string 1233 | 1234 | /** The path to the extension on disk. */ 1235 | readonly path: string 1236 | 1237 | /** The path to a directory on disk where the extension can store global state. The directory itself may not exist, and it is up to the extension to create it, but the parent directory is guaranteed to exist. */ 1238 | readonly globalStoragePath: string 1239 | 1240 | /** The path to a workspace-specific directory on disk where the extension can store state. The directory itself may not exist, and it is up to the extension to create it, but the parent directory is guaranteed to exist. */ 1241 | readonly workspaceStoragePath: string 1242 | 1243 | /** Opens the extension’s changelog in the Extension Library (under the Release Notes pane). If the extension does not provide a changelog this method will do nothing. */ 1244 | openChangelog(): void 1245 | 1246 | /** Opens the extension’s help documentation in the Extension Library (under the Help pane). If the extension does not provide a help document this method will do nothing. */ 1247 | openHelp(): void 1248 | 1249 | /** Opens the extension’s readme in the Extension Library (under the Details pane). If the extension does not provide a readme this method will do nothing. */ 1250 | openReadme(): void 1251 | } 1252 | 1253 | /// https://docs.nova.app/api-reference/file/ 1254 | 1255 | /** A `File` object can be used to read and write to a location on disk. Files are generally created through the `nova.fs.open()` method of the FileSystem class. */ 1256 | interface File { 1257 | /** Whether the file has been closed. Once a file is closed, attempts to read, write, or seek within the file will throw an `Error`. */ 1258 | readonly closed: boolean 1259 | 1260 | /** The path to the file on disk, as a string. */ 1261 | readonly path: string 1262 | 1263 | /** Closes the file, releasing the underlying file descriptor. If the file is already closed, this method does nothing. Once a file is closed, attempts to read, write, or seek within the file will throw an `Error`. */ 1264 | close(): void 1265 | 1266 | /** Returns the current position within the file as a number. */ 1267 | tell(): number 1268 | 1269 | /** 1270 | * This method moves the object’s position forward or backward by an amount specified by the `offset` argument. By default, this is relative to the file’s current position. 1271 | * 1272 | * If the optional from argument is specified, the move can be relative to the start of the file (from == `nova.fs.START`), the current position (from == `nova.fs.CURRENT`), the end of the file (from == `nova.fs.END`). 1273 | */ 1274 | seek(offset: number, from?: number): void 1275 | 1276 | /** 1277 | * Writes the specified value to the file at the current offset. 1278 | * 1279 | * If the value is a ArrayBuffer, the value will be written as bytes no matter which mode the file is in. 1280 | * 1281 | * If the value is a string, the value will be written using the file’s default encoding, unless the optional `encoding` argument is used to choose a specific encoding for the write. 1282 | */ 1283 | write(value: string | ArrayBuffer, encoding?: string): void 1284 | 1285 | /** 1286 | * Reads a number of bytes from the file at the current offset. If the `size` argument is specified, the file will attempt to read up to that number of bytes. If no more bytes are available, `null` will be returned. 1287 | * 1288 | * When bytes are successfully read, if the file is in Binary mode, the returned object will be a [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) object. If it’s in Text mode, the returned object will be a string created using the file’s set encoding. 1289 | */ 1290 | read(size?: number): string | ArrayBuffer | null 1291 | 1292 | /** 1293 | * Reads a single line from the file, up to and including any newline. This can be used in a loop to read lines from a file efficiently. When reading the last line of a file, the returned string will not contain a newline. Thus, the return value should be unambiguous as to whether the end of the file has been reached. 1294 | * @throws This method is only valid for files in Text mode. Attempting to invoke this method on a file in Binary mode will throw an `Error`. 1295 | */ 1296 | readline(): string 1297 | 1298 | /** 1299 | * Reads all remaining lines from the file in a loop using the `readline()` method, returning them as an array of strings. 1300 | * @throws This method is only valid for files in Text mode. Attempting to invoke this method on a file in Binary mode will throw an `Error`. 1301 | */ 1302 | readlines(): string[] 1303 | } 1304 | 1305 | /// https://docs.nova.app/api-reference/file-stats/ 1306 | 1307 | /** The `FileStats` class details information about a file on disk. `FileStats` objects are returned by the FileSystem class method `nova.fs.stat()`. */ 1308 | interface FileStats { 1309 | /** The last access time of the file’s content, as a `Date` object. */ 1310 | readonly atime: Date 1311 | 1312 | /** The creation time of the file, as a `Date` object. */ 1313 | readonly birthtime: Date 1314 | 1315 | /** 1316 | * The last modification time of the file’s metadata, as a `Date` object. 1317 | * Note: This is not the creation date of the file. Use the `birthtime` property for that. On Unix systems, the “ctime” represents the last time the file’s metadata was modified, not necessarily when the file was created on disk. 1318 | */ 1319 | readonly ctime: Date 1320 | 1321 | /** 1322 | * The file mode (permissions mask), as a number. 1323 | * @since 9.0 1324 | */ 1325 | readonly mode: number 1326 | 1327 | /** The last modification time of the file’s content, as a `Date` object. */ 1328 | readonly mtime: Date 1329 | 1330 | /** The size of the file, in bytes, as a number. */ 1331 | readonly size: number 1332 | 1333 | /** Returns `true` if the path represents a directory. */ 1334 | isDirectory(): boolean 1335 | 1336 | /** Returns `true` if the path represents a regular file. */ 1337 | isFile(): boolean 1338 | 1339 | /** Returns `true` if the path represents a symbolic link. */ 1340 | isSymbolicLink(): boolean 1341 | } 1342 | 1343 | /// https://docs.nova.app/api-reference/file-system/ 1344 | 1345 | type FileSystemBitField = number & { __t: "FileSystemBitField" } 1346 | 1347 | type Encoding = "utf8" | "utf-8" | "ascii" | "utf16le" | "utf-16le" | "utf16be" | "utf-16be" | "latin1" | "hex" | "base64" 1348 | 1349 | interface FileSystem { 1350 | /** An object containing a set of common constants used with file system operations. */ 1351 | readonly constants: { 1352 | /** A bitfield value indicating that a file exists. */ 1353 | readonly F_OK: FileSystemBitField 1354 | 1355 | /** A bitfield value indicating that a file is readable. */ 1356 | readonly R_OK: FileSystemBitField 1357 | 1358 | /** A bitfield value indicating that a file is writable. */ 1359 | readonly W_OK: FileSystemBitField 1360 | 1361 | /** A bitfield value indicating that a file is executable. */ 1362 | readonly X_OK: FileSystemBitField 1363 | 1364 | /** Denotes the start of a file (used by `File.seek()`). */ 1365 | readonly START: FileSystemBitField 1366 | 1367 | /** Denotes the current location of a file (used by `File.seek()`). */ 1368 | readonly CURRENT: FileSystemBitField 1369 | 1370 | /** Denotes the end of a file (used by `File.seek()`). */ 1371 | readonly END: FileSystemBitField 1372 | } 1373 | 1374 | /** A bitfield value indicating that a file exists. */ 1375 | readonly F_OK: FileSystemBitField 1376 | 1377 | /** A bitfield value indicating that a file is readable. */ 1378 | readonly R_OK: FileSystemBitField 1379 | 1380 | /** A bitfield value indicating that a file is writable. */ 1381 | readonly W_OK: FileSystemBitField 1382 | 1383 | /** A bitfield value indicating that a file is executable. */ 1384 | readonly X_OK: FileSystemBitField 1385 | 1386 | /** Denotes the start of a file (used by `File.seek()`). */ 1387 | readonly START: FileSystemBitField 1388 | 1389 | /** Denotes the current location of a file (used by `File.seek()`). */ 1390 | readonly CURRENT: FileSystemBitField 1391 | 1392 | /** Denotes the end of a file (used by `File.seek()`). */ 1393 | readonly END: FileSystemBitField 1394 | 1395 | /** 1396 | * Returns the path to a directory which may contain temporary files. The path is guaranteed to be scoped to the current extension, but may be shared between multiple instances of the same extension running in different workspaces. 1397 | * 1398 | * To guarantee unique filenames when writing temporary files, consider using an API such as Crypto.randomUUID() to generate randomized components. 1399 | * @since 10.0 1400 | */ 1401 | readonly tempdir: string 1402 | 1403 | /** 1404 | * Determines if the file at a specified path is accessible via the specified mode(s). If the path matches the modes, the return value will be `true`, otherwise `false`. 1405 | * 1406 | * The `modes` argument is a bitfield created using the `F_OK`, `R_OK`, `W_OK`, and `X_OK` constants. 1407 | */ 1408 | access(path: string, modes: number): boolean 1409 | 1410 | /** 1411 | * Sets the permissions mask for a specified path. The `mode` argument should be a number representing a octal bitmask of standard Unix permissions. 1412 | * @throws Will raise an `Error` if the path does not exist. 1413 | * @since 9.0 1414 | */ 1415 | chmod(path: string, mode: number): void 1416 | 1417 | /** 1418 | * Copies a file at a source path to a destination path. 1419 | * @throws If no file exists at the source path, or if a file already exists at the destination path, this will throw an `Error`. 1420 | */ 1421 | copy(src: string, dest: string): void 1422 | 1423 | /** 1424 | * Copies a file at a source path to a destination path asynchronously. When the operation is complete, the `callback` will be called with an optional error argument (only if the operation failed). The optional `thisValue` argument can be used to bind a custom `this` within the invoked callback. 1425 | * @throws If no file exists at the source path, or if a file already exists at the destination path, this will return an `Error`. 1426 | */ 1427 | copyAsync(src: string, dest: string, callback: (err?: Error) => void): void 1428 | 1429 | /** 1430 | * Copies a file at a source path to a destination path asynchronously. When the operation is complete, the `callback` will be called with an optional error argument (only if the operation failed). The optional `thisValue` argument can be used to bind a custom `this` within the invoked callback. 1431 | * @throws If no file exists at the source path, or if a file already exists at the destination path, this will return an `Error`. 1432 | */ 1433 | copyAsync<T>(src: string, dest: string, callback: (this: T, err?: Error) => void, thisValue: T): void 1434 | 1435 | /** 1436 | * Ejects the disk at the provided path. 1437 | * @throws If the path does not refer to a mounted volume, this method will throw an `Error`. 1438 | */ 1439 | eject(path: string): void 1440 | 1441 | /** 1442 | * Returns an array of paths listing the contents of the specified directory. 1443 | * @throws If no directory exists at the path (or if it’s not a directory), this will throw an `Error`. 1444 | */ 1445 | listdir(path: string): string[] 1446 | 1447 | /** 1448 | * Creates a directory at path. 1449 | * @throws If a file already exists at the path, this will throw an `Error`. 1450 | */ 1451 | mkdir(path: string): void 1452 | 1453 | /** 1454 | * Moves a file at a source path to a destination path. 1455 | * @throws If no file exists at the source path, or if a file already exists at the destination path, this will throw an `Error`. 1456 | */ 1457 | move(src: string, dest: string): void 1458 | 1459 | /** 1460 | * Moves a file at a source path to a destination path asynchronously. When the operation is complete, the `callback` will be called with an optional error argument (only if the operation failed). The optional `thisValue` argument can be used to bind a custom `this` within the invoked callback. 1461 | * @throws If no file exists at the source path, or if a file already exists at the destination path, this will return an `Error`. 1462 | */ 1463 | moveAsync(src: string, dest: string, callback: (err?: Error) => void): void 1464 | 1465 | /** 1466 | * Moves a file at a source path to a destination path asynchronously. When the operation is complete, the `callback` will be called with an optional error argument (only if the operation failed). The optional `thisValue` argument can be used to bind a custom `this` within the invoked callback. 1467 | * @throws If no file exists at the source path, or if a file already exists at the destination path, this will return an `Error`. 1468 | */ 1469 | moveAsync<T>(src: string, dest: string, callback: (this: T, err?: Error) => void, thisValue: T): void 1470 | 1471 | /** 1472 | * Opens a file from the specified path, creating and returning a [File](https://docs.nova.app/api-reference/file) object. 1473 | * 1474 | * The mode string argument specifies in what way the file is opened. It can contain the following components: 1475 | * - **r**: Open for reading (default) 1476 | * - **w**: Open for writing, truncating the file first 1477 | * - **x**: Open for exclusive creation, failing if the file exists 1478 | * - **a**: Open for writing, appending to the end if it exists 1479 | * - **b**: Binary mode 1480 | * - **t**: Text mode (default) 1481 | * - **+**: Open for updating (reading and writing) 1482 | * 1483 | * The default mode is `'r'` (open for reading, synonym of `'rt'`). For binary read-write access, the mode `'w+b'` opens and truncates the file to 0 bytes. `'r+b'` opens the file in binary mode without truncation. 1484 | * 1485 | * Files can be created in one of two modes: “Binary Mode” or “Text Mode”. In Binary mode, reading from the file will read [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) objects. In Text mode, the file object will attempt to interpret read data in a specific encoding (specified when the file was created) and return string objects. By default, the encoding of a file in text mode with no encoding specified is UTF-8. 1486 | * 1487 | * For files opened in Text mode, the optional encoding argument can be used to set what encoding will be used to interpret read and (by default) written data. If this argument is not specified, UTF-8 will be used. 1488 | * 1489 | * Supported encodings include: 1490 | * - “utf8” / “utf-8” 1491 | * - “ascii” 1492 | * - “utf16le” / “utf-16le” 1493 | * - “utf16be” / “utf-16be” 1494 | * - “latin1” 1495 | * - “hex” 1496 | * - “base64” 1497 | */ 1498 | open(path: string, mode?: string, encoding?: Encoding): File 1499 | // TODO: Better mode selection by overloading modes. Needs all possible combination. 1500 | 1501 | /** 1502 | * Removes a file at a path. This method is only valid for regular files. If no file exists at the path, this method does nothing. 1503 | * @throws If the path represents a directory, this will throw an `Error` (use the `rmdir()` method instead). 1504 | */ 1505 | remove(path: string): void 1506 | 1507 | /** 1508 | * Removes a directory at a path. This method is only valid for directories. If no directory exists at the path, this method does nothing. 1509 | * @throws If the path is not a directory, this will throw an `Error`. 1510 | */ 1511 | rmdir(path: string): void 1512 | 1513 | /** Displays a Finder window and reveals the item represented by the provided path. */ 1514 | reveal(path: string): void 1515 | 1516 | /** Returns information about the file at a path as a FileStats object. If no file exists at the path, this method returns `null` or `undefined`. */ 1517 | stat(path: string): FileStats | null | undefined 1518 | 1519 | /** Creates a FileSystemWatcher object that observes changes to the file system relative to the workspace. The pattern is a glob pattern which specifies the files to observe. The pattern may be `null` to indicate that changes to all files and directories should be observed. The provided callable will be invoked when files are added, modified, or removed. */ 1520 | watch(pattern: string | null, callable: (path: string) => void): FileSystemWatcher 1521 | } 1522 | 1523 | /// https://docs.nova.app/api-reference/file-system-watcher/ 1524 | 1525 | /** 1526 | * A `FileSystemWatcher` observes changes to the file system relative to the current workspace, and invokes callbacks when items are added, changed, or deleted. 1527 | * 1528 | * File system watcher objects are created using the `watch()` method of the FileSystem class. 1529 | * @implements {Disposable} 1530 | */ 1531 | interface FileSystemWatcher extends Disposable { 1532 | /** Adds an event listener that invokes the provided `callback` when matching files are added, modified, or deleted from the filesystem. The callback will receive the path that was modified. Returns a Disposable object that can be used to cancel the event listener. */ 1533 | onDidChange(callback: (path: string) => void): Disposable 1534 | } 1535 | 1536 | /// https://docs.nova.app/api-reference/issue/ 1537 | 1538 | declare enum IssueSeverity { 1539 | /** Indicating an unrecoverable error (the highest priority). */ 1540 | Error, 1541 | 1542 | /** Indicating a recoverable warning. */ 1543 | Warning, 1544 | 1545 | /** Indicating a code hint. */ 1546 | Hint, 1547 | 1548 | /** Indicating an informative notice (lowest priority). */ 1549 | Info 1550 | } 1551 | 1552 | /** 1553 | * An `Issue` object defines a single result from a diagnostic pass within a file or workspace. For example, issues may represent parse errors, style warning, and code hints. Issues are delivered to the workspace using [IssueCollection](https://docs.nova.app/api-reference/issue-collection) objects or an issue assistant registered with the [AssistantsRegistry](https://docs.nova.app/api-reference/assistants-registry). 1554 | * 1555 | * The `Issue` class is not subclassable. 1556 | * @example 1557 | * let issue = new Issue(); 1558 | * 1559 | * issue.message = "Undefined name 'foobar'"; 1560 | * issue.code = "E12"; 1561 | * issue.severity = IssueSeverity.Error; 1562 | * issue.line = 10; 1563 | * issue.column = 12; 1564 | * 1565 | * issueCollection.set(fileURI, [issue]); 1566 | */ 1567 | declare class Issue { 1568 | /** Creates a new `Issue` object. */ 1569 | constructor() 1570 | 1571 | /** A client-defined value (string or number) that may be associated with an issue and used to reference the rule or configuration setting that triggered the issue. */ 1572 | code?: string | number 1573 | 1574 | /** The user-readable string that describes the issue. This value should most often be between one and three sentences for clarity. */ 1575 | message?: string 1576 | 1577 | /** The importance of the issue, and how prominently it will be displayed to the user. */ 1578 | severity?: IssueSeverity 1579 | 1580 | /** An optional value that allows the client to indicate from what tool or checker an issue originated, such as `"jslint"` or `"pyflakes"`. If `null`, the name of the extension will be displayed to the user. */ 1581 | source?: string | null 1582 | 1583 | /** 1584 | * A [Range](https://docs.nova.app/api-reference/range) value that describes the textual range within the relevant file in which the issue occurred. 1585 | * 1586 | * Note: the `textRange` property operates on linear character positions within the entire file. To report issues using a line-column position, see the `line`, `column`, `endLine`, and `endColumn` properties. 1587 | */ 1588 | textRange?: Range 1589 | 1590 | /** 1591 | * The line number within the relevant file on which the issue occurred (or starts, if used with `endRange`). Ignored if the `textRange` property is set. 1592 | * 1593 | * This value should be 1-based (The first line of a document is represented by the value `1`). 1594 | */ 1595 | line?: number 1596 | 1597 | /** 1598 | * The column number within the relevant file on which the issue occurred (or starts, if used with `endColumn`). Ignored unless the `line` property is also set. 1599 | * 1600 | * This value should be 1-based (The first column of a line is represented by the value `1`). 1601 | */ 1602 | column?: number 1603 | 1604 | /** 1605 | * The line number within the relevant file on which the issue ends. Ignored unless the `line` property is also set. 1606 | * 1607 | * This value should be 1-based (The first line of a document is represented by the value `1`). 1608 | */ 1609 | endLine?: number 1610 | 1611 | /** 1612 | * The column number within the relevant file on which the issue ends. Ignored unless the `line` and `endLine` properties are also set. 1613 | * 1614 | * This value should be 1-based (The first column of a line is represented by the value `1`). 1615 | */ 1616 | endColumn?: number 1617 | } 1618 | 1619 | /// https://docs.nova.app/api-reference/issue-collection/ 1620 | 1621 | /** 1622 | * An `IssueCollection` object coordinates a group of results from a diagnostic pass within a file or workspace, represented using [Issue](https://docs.nova.app/api-reference/issue) objects. 1623 | * 1624 | * The `IssueCollection` class is not subclassable. 1625 | * @implements {Disposable} 1626 | * @example 1627 | * class MyLinterClass() { 1628 | * constructor() { 1629 | * this.issueCollection = new IssueCollection(); 1630 | * } 1631 | * 1632 | * deliverResults(fileURI, issues) { 1633 | * this.issueCollection.set(fileURI, issues); 1634 | * } 1635 | * } 1636 | */ 1637 | declare class IssueCollection extends Disposable { 1638 | /** Creates a new `IssueCollection` object with a provided name. If no name is provided, the name of the extension will be displayed to the user when required. */ 1639 | constructor(name?: string) 1640 | 1641 | /** The name of the collection, potentially shown to the user. Most commonly the name is that of a diagnostic tool, such as `"jslint"`. */ 1642 | readonly name: string 1643 | 1644 | /** 1645 | * Appends an array of issues to the collection for a provided file URI. 1646 | * @throws Attempting to invoke this method after the collection has been disposed will throw an `Error`. 1647 | */ 1648 | append(uri: string, issues: Issue[]): void 1649 | 1650 | /** Removes all issues from the collection, and removes the collection from its owning workspace. The collection will no longer be displayed to the user. Subsequent attempts to set new issues on the collection will do nothing. */ 1651 | dispose(): void 1652 | 1653 | /** Removes all issues from the collection. */ 1654 | clear(): void 1655 | 1656 | /** Returns a boolean value indicating whether the collection contains any issues for the provided file URI. */ 1657 | has(uri: string): boolean 1658 | 1659 | /** Returns all issues within the collection for a provided file URI. */ 1660 | get(uri: string): ReadonlyArray<Issue> 1661 | 1662 | /** 1663 | * Replaces all issues within the collection for a provided file URI. 1664 | * @throws Attempting to invoke this method after the collection has been disposed will throw an `Error`. 1665 | */ 1666 | set(uri: string, issues: Issue[]): void 1667 | 1668 | /** 1669 | * Removes all issues within the collection for a provided file URI. 1670 | * @throws Attempting to invoke this method after the collection has been disposed will throw an `Error`. 1671 | */ 1672 | remove(uri: string): void 1673 | } 1674 | 1675 | /// https://docs.nova.app/api-reference/issue-parser/ 1676 | 1677 | /** 1678 | * An `IssueParser` object is a streaming-style object capable of parsing [Issue](https://docs.nova.app/api-reference/issue) objects from the string output of a task (such as the standard output of a [Process](https://docs.nova.app/api-reference/process)). This is accomplished by “pushing” lines of output into the parser, which processes that output using a series of predefined [Issue Matcher](https://docs.nova.app/extensions/issue-matchers) rules defined in an extensions JSON manifest. 1679 | * 1680 | * The `IssueParser` class is not subclassable. 1681 | * @example 1682 | * let p = new Process(path, { 1683 | * args: args 1684 | * }); 1685 | * 1686 | * let parser = new IssueParser("my-issue-matcher"); 1687 | * 1688 | * p.onStdout((line) => { 1689 | * parser.pushLine(line); 1690 | * }); 1691 | * 1692 | * p.onDidExit((code) => { 1693 | * let issues = parser.issues; 1694 | * }); 1695 | * 1696 | * p.start(); 1697 | */ 1698 | declare class IssueParser { 1699 | /** Creates a new `IssueParser` object with one or more issue matcher names. The `matcherNames` argument may be either a string, in which case a single matcher is used, or an array of strings, in which case multiple matchers are used. */ 1700 | constructor(matcherNames?: string | string[]) 1701 | 1702 | /** The array of [Issue](https://docs.nova.app/api-reference/issue) objects that have been successfully parsed from the provided output. If no issues are parsed, an empty array is returned. */ 1703 | readonly issues: ReadonlyArray<Issue> 1704 | 1705 | /** Pushes a new line of output on to the parser, which causes immediate parsing of that line against the current set of matchers. */ 1706 | pushLine(line: string): void 1707 | 1708 | /** Removes all issues from the parser’s issues array and resets any in-progress matching. This can be used to “batch” issues after a known point within the output is reached. */ 1709 | clear(): void 1710 | } 1711 | 1712 | /// https://docs.nova.app/api-reference/language-client/ 1713 | 1714 | /** 1715 | * A `LanguageClient` is an interface for adding a language server compatible with the Language Server Protocol specification. Creating an instance of a `LanguageClient` object sets up configuration for the server, at which point communication with the server is handed-off to the application. 1716 | * 1717 | * The `LanguageClient` class is not subclassable. 1718 | * @example 1719 | * var serverOptions = { 1720 | * path: path 1721 | * }; 1722 | * var clientOptions = { 1723 | * syntaxes: ['typescript'] 1724 | * }; 1725 | * var client = new LanguageClient('typescript', 'TypeScript Language Server', serverOptions, clientOptions); 1726 | * 1727 | * client.start(); 1728 | */ 1729 | declare class LanguageClient extends Disposable { 1730 | /** 1731 | * Creates a `LanguageClient` object for communication with a language server. 1732 | * 1733 | * The `identifier` parameter should be a simple, unique string that can be used to identify the server (such as `"typescript"`). It will not be displayed to the user. 1734 | * 1735 | * The `name` parameter is the name of the server that can potentially be shown to the user, to indicate that the server has been enabled and is in use. 1736 | * 1737 | * The `serverOptions` object defines configuration settings for launching and communicating with the server executable. 1738 | * 1739 | * The `clientOptions` object defines configuration settings for how the editor invokes the language client. 1740 | */ 1741 | constructor( 1742 | /** The `identifier` parameter should be a simple, unique string that can be used to identify the server (such as `"typescript"`). It will not be displayed to the user. */ 1743 | identifier: string, 1744 | 1745 | /** The `name` parameter is the name of the server that can potentially be shown to the user, to indicate that the server has been enabled and is in use. */ 1746 | name: string, 1747 | 1748 | /** The `serverOptions` object defines configuration settings for launching and communicating with the server executable. */ 1749 | serverOptions: { 1750 | /** Additional arguments to pass. */ 1751 | args?: string[] 1752 | 1753 | /** Additional environment variables to set. */ 1754 | env?: { [key: string]: string } 1755 | 1756 | /** The path to the server executable. Absolute, or relative to the extension’s bundle. */ 1757 | path: string 1758 | 1759 | /** The type of transport to use (“stdio”, “socket”, “pipe”). Defaults to “stdio” if not value is specified. */ 1760 | type?: "stdio" | "socket" | "pipe" 1761 | }, 1762 | 1763 | /** The `clientOptions` object defines configuration settings for how the editor invokes the language client. */ 1764 | clientOptions: { 1765 | /** 1766 | * Enable debug logging to the Extension Console. 1767 | * @since 10.0 1768 | */ 1769 | debug?: boolean 1770 | 1771 | /** 1772 | * Custom options to send with the LSP initialize request. 1773 | * @since 2.0 1774 | */ 1775 | initializationOptions?: Object 1776 | 1777 | /** Syntaxes for which the client is valid. */ 1778 | syntaxes: ( 1779 | string | 1780 | { 1781 | /** The syntax name */ 1782 | syntax: string 1783 | 1784 | /** The Language Server Protocol language ID. If not present, the syntax name is used. */ 1785 | languageId?: string 1786 | } 1787 | )[] 1788 | } 1789 | ) 1790 | 1791 | /** The identifier of the language client specified when it was created. */ 1792 | readonly identifier: string 1793 | 1794 | /** The visible name of the language client specified when it was created. */ 1795 | readonly name: string 1796 | 1797 | /** A boolean indicating whether the client’s language server is currently running. This value will be false before `.start()` is invoked, and after the language server is stopped. */ 1798 | readonly running: boolean 1799 | 1800 | /** 1801 | * Adds an event listener that invokes the provided `callback` when the language server stops. The callback will receive as an argument an Error object if the language server stopped unexpectedly. Otherwise, this argument will be `undefined`. 1802 | * 1803 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 1804 | * @since 2.0 1805 | */ 1806 | onDidStop<T>(callback: (this: T, err?: Error) => void, thisValue?: T): Disposable 1807 | 1808 | /** 1809 | * Registers a notification handler with the language client. If the language service sends a notification with the provided method name to the host it will be forwarded to the provided callback. The callback will receive the parameters objects as an argument. 1810 | * 1811 | * If another handler was previously registered for the provided method name it will be replaced. 1812 | * 1813 | * Note: This should only be used for methods that are not part of the core Language Server Protocol specification. Attempting to register handlers for core methods will not invoke the provided callback. 1814 | */ 1815 | onNotification(method: string, callback: (params: any) => void): void 1816 | 1817 | /** 1818 | * Registers a request handler with the language client. If the language service sends a request with the provided method name to the host it will be forwarded to the provided callback. The callback will receive the parameters objects as an argument, and the return value will be returned to the language service as the response. If the return value is a `Promise`, it will be returned once the promise resolves or rejects. 1819 | * 1820 | * If another handler was previously registered for the provided method name it will be replaced. 1821 | * 1822 | * Note: This should only be used for methods that are not part of the core Language Server Protocol specification. Attempting to register handlers for core methods will not invoke the provided callback. 1823 | */ 1824 | onRequest(method: string, callback: (params: any) => unknown | Promise<unknown>): void 1825 | 1826 | /** Sends a request with the provided method name to the language service, and returns a `Promise` object that resolves when the reply or an error is received by the host. The resolved value will be the parameters returned in the response. */ 1827 | sendRequest(method: string, params?: unknown): Promise<unknown> 1828 | 1829 | /** Sends a notification with the provided method name to the language service. */ 1830 | sendNotification(method: string, params?: unknown): void 1831 | 1832 | /** 1833 | * Attempts to asynchronously start the language server. If the server was already running, or is in the process of stopping, this method does nothing. If the server is unable to start, such as if the executable was not found at the specified path or module, then an error will be sent via the `onDidStop` event listener. 1834 | * 1835 | * Changed in Nova 2: This method may be invoked safely after the language server stops to attempt to restart it. In previous versions, this would raise an `Error`. 1836 | */ 1837 | start(): void 1838 | 1839 | /** Attempts to asynchronously stop the language server. If the server was not running, this method does nothing. */ 1840 | stop(): void 1841 | } 1842 | 1843 | /// https://docs.nova.app/api-reference/notification-center/ 1844 | 1845 | /** The `NotificationCenter` class is used to manage notifications presented to the user by an extension. A shared instance is always available as the `nova.notifications` environment property. */ 1846 | interface NotificationCenter { 1847 | /** Adds a NotificationRequest object to be displayed to the user. */ 1848 | add(request: NotificationRequest): Promise<NotificationResponse> 1849 | 1850 | /** Cancels any pending or displayed notifications with the specified identifier. */ 1851 | cancel(identifier: string): void 1852 | } 1853 | 1854 | /// https://docs.nova.app/api-reference/notification-request/ 1855 | 1856 | /** 1857 | * A `NotificationRequest` object can be used to present a non-interruptive notification to the user. 1858 | * 1859 | * The `NotificationRequest` class is not subclassable. 1860 | */ 1861 | declare class NotificationRequest { 1862 | /** 1863 | * Creates a `NotificationRequest` object with an optional identifier. 1864 | * 1865 | * The identifier argument can be used to assign a specific meaning to the notification, so that it may be cancelled or handled in a specific way when receiving a response. If no identifier is specified, a random string will be used. 1866 | * 1867 | * To request a notification be presented to the user, create a `NotificationRequest` object, set its properties, and add it to the global NotificationCenter object. This will return a `Promise`, which can be used to observe when the notification is dismissed or fails. If the promise succeeds, it will provide a NotificationResponse object as the result. 1868 | * 1869 | * Dispatching multiple notification requests with an identifier will automatically cancel any previous requests with the same identifier. Only one notification for the identifier may be displayed to the user at a time. In addition, multiple notifications sent from the same extension may be coalesced or queued to prevent overwhelming notification display. 1870 | * @example 1871 | * let request = new NotificationRequest("foobar-not-found"); 1872 | * 1873 | * request.title = nova.localize("Foobar Not Found"); 1874 | * request.body = nova.localize("Enter the path to the foobar tool."); 1875 | * 1876 | * request.type = "input"; 1877 | * request.actions = [nova.localize("OK"), nova.localize("Ignore")]; 1878 | * 1879 | * let promise = nova.notifications.add(request); 1880 | * promise.then(reply => { 1881 | * console.log(reply); 1882 | * }, error => { 1883 | * console.error(error); 1884 | * }); 1885 | */ 1886 | constructor(identifier?: string) 1887 | 1888 | /** The identifier for the notification. */ 1889 | identifier: string 1890 | 1891 | /** The title to be displayed to the user. This should be short and concise, and localized if possible. */ 1892 | title: string 1893 | 1894 | /** The body of the notification displayed to the user. This should be localized, if possible. */ 1895 | body: string 1896 | 1897 | /** 1898 | * A string denoting the type of notification to display. By default, this will be a simple informative notification (with no input boxes). 1899 | * 1900 | * The following types are supported: 1901 | * - “input”: displays an input field to the user 1902 | * - “secure-input” displays a secure input field (password field) to the user 1903 | */ 1904 | type: "input" | "secure-input" 1905 | 1906 | /** The default value of the input field, for notifications of the appropriate type. */ 1907 | textInputValue: string 1908 | 1909 | /** The placeholder value of the input field, for notifications of the appropriate type. */ 1910 | textInputPlaceholder: string 1911 | 1912 | /** The set of actions to display to the user, as an array of strings. These should be localized, if possible. */ 1913 | actions: string[] 1914 | } 1915 | 1916 | /// https://docs.nova.app/api-reference/notification-response/ 1917 | 1918 | /** A `NotificationResponse` object represents the result of a notification presented using a [NotificationRequest](https://docs.nova.app/api-reference/notification-request) being dismissed. */ 1919 | interface NotificationResponse { 1920 | /** The identifier for the notification. */ 1921 | readonly identifier: string 1922 | 1923 | /** The index of the action that was chosen to dismiss the notification, in the same order as the `actions` property specified in the original notification request. If the notification was dismissed for another reason, such as the workspace closing, this value will may `null` or `undefined`. */ 1924 | readonly actionIdx?: number | null 1925 | 1926 | /** The value entered by the user into the notification’s input field, for notifications of the appropriate type. */ 1927 | readonly textInputValue?: string 1928 | } 1929 | 1930 | /// https://docs.nova.app/api-reference/path/ 1931 | 1932 | /** The `nova.path` global object is used to manipulate file system paths. */ 1933 | interface Path { 1934 | /** Returns the last component (the filename) of the specified path, including any extension. */ 1935 | basename(path: string): string 1936 | 1937 | /** Returns the directory parent of the path. */ 1938 | dirname(path: string): string 1939 | 1940 | /** Returns the file extension of the path. If the path has no file extension, this method returns an empty string. */ 1941 | extname(path: string): string 1942 | 1943 | /** Splits the path into an array with two components: the path + filename without the extension, and the file extension. */ 1944 | splitext(path: string): [string, string] 1945 | 1946 | /** Expands any reference to the user’s home directory using the `~` component to contain the full home directory path. */ 1947 | expanduser(path: string): string 1948 | 1949 | /** Returns `true` if the path is an absolute path. */ 1950 | isAbsolute(path: string): boolean 1951 | 1952 | /** Combines one or more components into one path using the platform’s proper path components. */ 1953 | join(...paths: string[]): string 1954 | 1955 | /** Attempts to normalize a path by expanding symbolic links and other ambiguous components. */ 1956 | normalize(path: string): string 1957 | 1958 | /** 1959 | * Calculates and returns a relative path between two other paths, inserting `..` components as necessary. 1960 | * @since 8.0 1961 | */ 1962 | relative(from: string, to: string): string 1963 | 1964 | /** Splits the path into an array of path components (split on the ‘/’ separator), but including the leading ‘/’ root for absolute paths. */ 1965 | split(path: string): string[] 1966 | } 1967 | 1968 | /// https://docs.nova.app/api-reference/process/ 1969 | 1970 | type ReadableStream<T = any> = any 1971 | type WritableStream<T = any> = any 1972 | 1973 | /** 1974 | * A `Process` object can be used to launch a subprocess, establish communication channels, and listen for events. 1975 | * 1976 | * The `Process` class is not subclassable. 1977 | */ 1978 | declare class Process { 1979 | /** Creates a `Process` object that will launch the executable represented by `command`. */ 1980 | constructor(command: string, options?: { 1981 | /** Additional arguments to pass. */ 1982 | args?: string[] 1983 | 1984 | /** Additional environment variables to set. */ 1985 | env?: { [key: string]: string } 1986 | 1987 | /** The current working directory path to set for the process. */ 1988 | cwd?: string 1989 | 1990 | /** 1991 | * Options for configuring the stdio channels. 1992 | * 1993 | * To directly configure each of the stdio channels, specify an array of three elements, each representing how to set up standard in, standard out, and standard error, respectively. 1994 | * 1995 | * If an element is `"pipe"`, then a standard pipe will be set up for the channel. The pipe will be exposed through the resulting process’s `stdio` array property at the corresponding index as a WritableStream (stdin) or ReadableStream (stdout and stderr) object. 1996 | * 1997 | * If an element is `"ignore"`, then no channel will be set up. 1998 | * 1999 | * Passing a number for the element will treat the value as a file descriptor, which must already exist, and set up a channel reading or writing to that descriptor. Passing the values 0, 1, and 2 is effectively the same as setting up a pipe to the parent process’s standard in, standard out, and standard error. 2000 | * 2001 | * For convenience, passing the values `"pipe"` or `"ignore"` instead of an array is effectively the same as passing an array of three of that value (such as `["pipe", "pipe", "pipe"]`). 2002 | * 2003 | * Additionally, the value `"jsonrpc"` may be passed instead of an array to set up the entire stdio suite to use JSON-RPC communication. If this is done, then the `.request()`, `.notify()`, `.onRequest()`, and `.onNotify()` methods of the resulting process object become available. 2004 | * 2005 | * The `stdio` property of the resulting process will only contain a stream value for an element if that element was set up using `pipe`. In all other cases, the value of the `stdio` property’s element will be `null` and it is up to the caller to set up any additional communication. 2006 | * 2007 | * By default, if no `stdio` option is passed, it is the same as passing the value `["pipe", "pipe", "pipe"]`. 2008 | */ 2009 | stdio?: ["pipe" | "ignore", "pipe" | "ignore", "pipe" | "ignore"] | "pipe" | "ignore" | "jsonrpc" | number 2010 | 2011 | /** 2012 | * Run the subprocess within a shell. 2013 | * 2014 | * If the value of the shell option is `true`, the subprocess will be invoked using `/bin/sh`. If it’s a string, the shell path specified by the string will be used. 2015 | * 2016 | * Any arguments and environment set up for the subprocess will be passed to the shell, and then forwarded to the subprocess by the shell normally. 2017 | * 2018 | * Warning: Executing arbitrary processes with arguments within a shell environment may be susceptible to shell injection attacks. Care should be taken to sanitize any input that is passed to the shell environment. 2019 | */ 2020 | shell?: true | string 2021 | }) 2022 | 2023 | /** The arguments passed to the process (as an Array), including any specified when the Process was constructed. */ 2024 | readonly args: ReadonlyArray<string> 2025 | 2026 | /** The command used to launch the process. */ 2027 | readonly command: string 2028 | 2029 | /** The current working directory for the process. If not specified, the project directory will be used. */ 2030 | readonly cwd: string 2031 | 2032 | /** The environment variables set for the process, including any specified when the Process was constructed. */ 2033 | readonly env: { [key: string]: string } 2034 | 2035 | /** The process identifier (PID) of the subprocess. If the process has not been started, this property will be zero. */ 2036 | readonly pid: number 2037 | 2038 | /** An array of three elements, representing the standard in, standard out, and standard error communication channels, respectively. If the process was set up using pipes for the stdio elements, this array will contain corresponding [WritableStream](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream) (stdin) or [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) (stdout and stderr) objects at the appropriate index. Otherwise, the value at the given index will be `null`. */ 2039 | readonly stdio: [ 2040 | WritableStream | null, 2041 | ReadableStream | null, 2042 | ReadableStream | null, 2043 | ] 2044 | 2045 | /** Returns the standard in channel from the receiver’s `stdio` array. This is the same as calling `process.stdio[0]`. */ 2046 | readonly stdin: WritableStream | null 2047 | 2048 | /** Returns the standard out channel from the receiver’s `stdio` array. This is the same as calling `process.stdio[1]`. */ 2049 | readonly stdout: ReadableStream | null 2050 | 2051 | /** Returns the standard error channel from the receiver’s `stdio` array. This is the same as calling `process.stdio[2]`. */ 2052 | readonly stderr: ReadableStream | null 2053 | 2054 | /** 2055 | * Adds an event listener that invokes the provided `callback` when a line is read from the subprocess’s `stdout` pipe. The callback will receive the line that was read as a string argument. Data from `stdout` will be read as UTF-8 text. 2056 | * 2057 | * This method is effectively a convenience for getting the process’s `stdout` stream, acquiring a reader on it, and using that reader to read lines as UTF-8 text. While a handler is set, this effectively means the `stdout` reader is always locked. 2058 | * 2059 | * If you need to access standard out data in a different way (such as by bytes), consider accessing the `stdout` property and configuring the stream directly. 2060 | * 2061 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 2062 | * 2063 | * @throws If the process was not configured to use a pipe for standard out, this method will throw an `Error`. 2064 | */ 2065 | onStdout<T>(callback: (this: T, line: string) => void, thisValue?: T): Disposable 2066 | 2067 | /** 2068 | * Adds an event listener that invokes the provided `callback` when a line is read from the subprocess’s `stderr` pipe. The callback will receive the line that was read as a string argument. Data from `stderr` will be read as UTF-8 text. 2069 | * 2070 | * This method is effectively a convenience for getting the process’s `stderr` stream, acquiring a reader on it, and using that reader to read lines as UTF-8 text. While a handler is set, this effectively means the `stderr` reader is always locked. 2071 | * 2072 | * If you need to access standard error data in a different way (such as by bytes), consider accessing the `stderr` property and configuring the stream directly. 2073 | * 2074 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 2075 | * 2076 | * @throws If the process was not configured to use a pipe for standard error, this method will throw an `Error`. 2077 | */ 2078 | onStderr<T>(callback: (this: T, line: string) => void, thisValue?: T): Disposable 2079 | 2080 | /** 2081 | * Adds an event listener that invokes the provided `callback` when the subprocess terminates. The callback will receive as an argument the exit status (as a `Number`) of the subprocess. 2082 | * 2083 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 2084 | */ 2085 | onDidExit<T>(callback: (this: T, status: number) => void, thisValue?: T): Disposable 2086 | 2087 | /** 2088 | * Starts the subprocess. 2089 | * @throws If the process could not be launched because a valid executable was not found, this method will raise an `Error`. 2090 | * @throws If the process has already been launched, this method will also raise an `Error`. 2091 | */ 2092 | start(): void 2093 | 2094 | /** Sends a signal to the subprocess, specified by the `signal` argument. The signal may be a string (such as `"SIGINT"`, `"SIGTERM"`, or `"SIGHUP"`) or a number. */ 2095 | signal(signal: "SIGINT" | "SIGTERM" | "SIGHUP" | number): void 2096 | 2097 | /** Attempts to terminate the subprocess using `SIGKILL`. If the subprocess successfully terminates, then event handlers registered using `onDidExit()` will be invoked just as if the subprocess terminated on its own. */ 2098 | kill(): void 2099 | 2100 | /** Attempts to terminate the subprocess using `SIGTERM`. If the subprocess successfully terminates, then event handlers registered using `onDidExit()` will be invoked just as if the subprocess terminated on its own. */ 2101 | terminate(): void 2102 | 2103 | /** 2104 | * Sends a JSON-RPC notification with a provided method name and parameters to a process. The parameters object must be JSON-encodable. 2105 | * @throws If the process was not configured to use JSON-RPC communication, calling this method will throw an `Error`. 2106 | * @example 2107 | * process.notify('didSave', {'file': 'foo.txt'}); 2108 | */ 2109 | notify(methodName: string, params?: any): void 2110 | 2111 | /** 2112 | * Sends a JSON-RPC request with a provided method name and parameters to a process. The parameters object must be JSON-encodable. 2113 | * 2114 | * This method returns a `Promise` object that will resolve or reject once the request has been handled by the process, or if communication fails or the connection is terminated prematurely. 2115 | * 2116 | * The argument passed to any resolution (`then()`) hander will be a JSON-encodable object representing the `result` of the request. 2117 | * 2118 | * The argument passed to any rejection (`catch()`) handler will be a [ProcessMessage](https://docs.nova.app/api-reference/process-message) object. 2119 | * @throws If the process was not configured to use JSON-RPC communication, calling this method will immediately throw an `Error`. 2120 | * @example 2121 | * process.request('getNames', {'sort': 'alpha'}).then(function(reply) { 2122 | * console.log("Received response: " + reply.result); 2123 | * }); 2124 | */ 2125 | request(methodName: string, params?: any): Promise<any> 2126 | 2127 | /** 2128 | * If the process was configured to use JSON-RPC (see the Standard I/O section, above), then this method will add an event handler for a provided notification method name. 2129 | * 2130 | * The callback will be invoked when the extension receives a notification with a matching name from the process. The callback will be provided the [ProcessMessage](https://docs.nova.app/api-reference/process-message) that was sent. 2131 | * @throws If the process was not configured to use JSON-RPC communication, calling this method will throw an `Error`. 2132 | * @example 2133 | * process.onNotify('didConnect', function(message) { 2134 | * console.log("The server successfully connected."); 2135 | * }); 2136 | */ 2137 | onNotify(methodName: string, callback: (message: ProcessMessage<any, any, any>) => void): Disposable 2138 | 2139 | /** 2140 | * If the process was configured to use JSON-RPC (see the Standard I/O section, above), then this method will add an event handler for a provided request method name. 2141 | * 2142 | * The callback will be invoked when the extension receives a request with a matching name from the process. The callback will be provided the [ProcessMessage](https://docs.nova.app/api-reference/process-message) that was sent. 2143 | * 2144 | * The callback should return a reply to be transmitted back to the process (which may be any object that is JSON-encodable). If the reply is a `Promise` object, then the extension runtime will automatically wait until the promise is resolved before sending the response. 2145 | * 2146 | * Should the promise be rejected, the runtime will attempt to form a reply from the rejection reason, returned as a JSON-RPC error message. 2147 | * @throws If the process was not configured to use JSON-RPC communication, calling this method will throw an `Error`. 2148 | * @example 2149 | * process.onRequest('getCount', function(request) { 2150 | * return Promise(function(resolve, reject) { 2151 | * resolve({'count': 10}); 2152 | * }); 2153 | * }); 2154 | */ 2155 | onRequest(methodName: string, callback: (message: ProcessMessage<any, any, any>) => any): Disposable 2156 | } 2157 | 2158 | /// https://docs.nova.app/api-reference/process-message/ 2159 | 2160 | /** A `ProcessMessage` object is represents a messages sent from a subprocess to the extension via JSON-RPC. `ProcessMessage` objects are only used with a [Process](https://docs.nova.app/api-reference/process) object which has been set up to use JSON-RPC communication. */ 2161 | interface ProcessMessage<P, R, E> { 2162 | /** The method name of the message, as a string. If the message is a response, this will be `null`. */ 2163 | readonly method: string | null 2164 | 2165 | /** An object containing the parameters of the message. All values are JSON-encodable. */ 2166 | readonly parameters?: P 2167 | 2168 | /** If the message is a response whose request succeeded, this will contain the result object of the response, otherwise this will be `null`. */ 2169 | readonly result: R 2170 | 2171 | /** If the message is a response whose request failed, this will contain the error code object of the response, otherwise this will be `null`. */ 2172 | readonly errorCode: number | null 2173 | 2174 | /** If the message is a response whose request failed, this will contain the error reason object of the response, otherwise this will be `null`. */ 2175 | readonly errorReason: string | null 2176 | 2177 | /** If the message is a response whose request failed, this will contain the error data object of the response (if any), otherwise this will be `null`. */ 2178 | readonly errorData: E | null 2179 | } 2180 | 2181 | /// https://docs.nova.app/api-reference/range/ 2182 | 2183 | /** 2184 | * A `Range` represents a contiguous, linear region of an element, specified by a start and end index. Most often it is used to indicate sections of a text stream. 2185 | * 2186 | * The `Range` class is not subclassable. 2187 | */ 2188 | declare class Range { 2189 | /** 2190 | * Creates a new `Range` with a provided `start` and end `index`. 2191 | * @throws Raises an `Error` if the end index precedes the start index. 2192 | */ 2193 | constructor(start: number, end: number) 2194 | 2195 | /** The start index of the range, as a `Number`. */ 2196 | readonly start: number 2197 | 2198 | /** The end index of the range, as a `Number`. */ 2199 | readonly end: number 2200 | 2201 | /** The length of the range, as a `Number`. This is equivalent to subtracting `start` from `end`. */ 2202 | readonly length: number 2203 | 2204 | /** A `Boolean` indicating whether the range is empty (its start and end indices are the same). */ 2205 | readonly empty: boolean 2206 | 2207 | /** Returns `true` if the receiver is equal to another provided range, `false` otherwise. */ 2208 | isEqual(range: Range): boolean 2209 | 2210 | /** Returns a `Number` indicating how a provided range compares to the receiver in sort order. The return value will be `-1` if the receiver’s start index precedes the other’s, or if the same, if its length is shorter. The return value will be `1` if the opposite is true. The return value will be `0` if the ranges are equal. */ 2211 | compare(range: Range): number 2212 | 2213 | /** Returns `true` if the receiver fully contains another provided range, `false` otherwise. */ 2214 | containsRange(range: Range): boolean 2215 | 2216 | /** Returns `true` if the receiver contains a provided index, `false` otherwise. */ 2217 | containsIndex(index: number): boolean 2218 | 2219 | /** Returns a new `Range` representing a union of the receiver and a provided range. */ 2220 | union(range: Range): Range 2221 | 2222 | /** Returns a new `Range` representing an intersection of the receiver and a provided range. If the two ranges to not intersect, the returned range will have zero start and end indices. */ 2223 | intersection(range: Range): Range 2224 | 2225 | /** Returns `true` if the receiver intersects a provided range (shares at least one index), `false` otherwise. */ 2226 | intersectsRange(range: Range): boolean 2227 | } 2228 | 2229 | /// https://docs.nova.app/api-reference/scanner/ 2230 | 2231 | /** 2232 | * A `Scanner` object is a simple string parser that allows for easy scanning for substrings and characters in a character set, and well as numeric values in several representations. 2233 | * 2234 | * To set a scanner object to ignore a set of characters as it scans the string, use the `skipChars` property. Characters in the skip set are skipped over before the target is scanned. The default set of characters to skip is the whitespace and newline character set. 2235 | * 2236 | * The `Scanner` class is not subclassable. 2237 | * @example 2238 | * let string = "Foobar abc 12.0"; 2239 | * 2240 | * let scanner = new Scanner(string); 2241 | * 2242 | * scanner.scanString("Foo"); // => "Foo" 2243 | * scanner.scanString("Foo"); // => null 2244 | * scanner.scanString("bar"); // => "bar" 2245 | * 2246 | * scanner.scanChars(Charset.alphanumeric); // => "abc"; 2247 | * 2248 | * scanner.scanFloat(); // => 12.0 2249 | * scanner.scanFloat(); // => null 2250 | * 2251 | * scanner.atEnd; // => true 2252 | */ 2253 | declare class Scanner { 2254 | /** Creates a new `Scanner` object with a provided string to scan. */ 2255 | constructor(string: string) 2256 | 2257 | /** The string the scanner is parsing. */ 2258 | readonly string: string 2259 | 2260 | /** The current character position of the scanner in its string as an integer. */ 2261 | location: number 2262 | 2263 | /** Whether the scanner’s location is at the end of its string. */ 2264 | readonly atEnd: boolean 2265 | 2266 | /** The set of characters that should be skipped during parsing, as a [Charset](https://docs.nova.app/api-reference/charset). Characters in the skip set are skipped over before the target is scanned. The default set of characters to skip is the whitespace and newline character set. */ 2267 | skipChars: Charset 2268 | 2269 | /** Whether the scanner parses using case-sensitive rules. By default this is `false`. */ 2270 | caseSensitive: boolean 2271 | 2272 | /** Scans the provided string, returning the string if found and `null` if it was not found. */ 2273 | scanString(string: string): string | null 2274 | 2275 | /** Scans the string until a given string is encountered, accumulating characters in a string that is returned. If no characters are scanned (such as if the string to be scanned up to is already at the scan location or the scanner is empty), this method returns `null`. */ 2276 | scanUpToString(string: string): string | null 2277 | 2278 | /** Scans for characters in the provided [Charset](https://docs.nova.app/api-reference/charset), accumulating them into a string that is returned. If no characters are scanned, this method returns `null`. */ 2279 | scanChars(charset: Charset): string | null 2280 | 2281 | /** Scans the string until a character in the provided [Charset](https://docs.nova.app/api-reference/charset) is encountered, accumulating characters in a string that is returned. If no characters are scanned (such as if a characters to be scanned up to is already at the scan location or the scanner is empty), this method returns `null`. */ 2282 | scanUpToChars(charset: Charset): string | null 2283 | 2284 | /** Scans for an integer value in decimal representation, returning it if found, and returning `null` if no value is found. */ 2285 | scanInt(): number | null 2286 | 2287 | /** Scans for a floating-point value in decimal representation, returning it if found, and returning `null` if no value is found. */ 2288 | scanFloat(): number | null 2289 | 2290 | /** Scans for an integer value in hexadecimal representation, returning it if found, and returning `null` if no value is found. */ 2291 | scanHexInt(): number | null 2292 | 2293 | /** Scans for a floating-point value in hexadecimal representation, returning it if found, and returning `null` if no value is found. */ 2294 | scanHexFloat(): number | null 2295 | } 2296 | 2297 | /// https://docs.nova.app/api-reference/scope-selector/ 2298 | 2299 | /** 2300 | * A `ScopeSelector` object represents a single text selector used for the names of scopes in syntax grammars. These objects can be used to determine whether a specific region of text matches a specific subset of selector classes, such as for use in completions. 2301 | * @since 3.0 2302 | */ 2303 | declare class ScopeSelector { 2304 | /** 2305 | * Creates a new scope selector from the provided string. The string must follow the standard format used for [syntax grammar scopes](https://docs.nova.app/syntax-reference/scopes): a set of alphanumeric identifiers that are separated by period (`.`) characters. The universal selector `*` is also allowed. Any other characters (including whitespace) will be ignored and stripped from the string. 2306 | * 2307 | * The special class `*` is reserved to represent the universal selector, which will match any other selector compared to it. If this class is included as a component of any selector it will be assumed to also represent the universal selector. 2308 | */ 2309 | constructor(string: string) 2310 | 2311 | /** An array of strings representing the set of period-separated classes that were specified in the string which created the selector. The classes are not guaranteed to be in any particular order, and may not represent the order that was originally specified. */ 2312 | readonly classes: ReadonlyArray<string> 2313 | 2314 | /** The string which created the selector. */ 2315 | readonly string: string 2316 | 2317 | /** 2318 | * Returns a boolean value as to whether the selector or string provided matches the receiver. 2319 | * @throws The argument must be either another `ScopeSelector` instance or a string that can be resolved as such. Passing any other value will raise an `Error`. 2320 | */ 2321 | matches(selectorOrString: ScopeSelector | string): boolean 2322 | } 2323 | 2324 | /// https://docs.nova.app/api-reference/symbol/ 2325 | 2326 | type SymbolType = 2327 | // Types 2328 | | "type" 2329 | | "class" 2330 | | "category" 2331 | | "interface" 2332 | | "enum" 2333 | | "union" 2334 | | "struct" 2335 | 2336 | // Callables 2337 | | "function" 2338 | | "method" 2339 | | "closure" 2340 | | "constructor" 2341 | | "destructor" 2342 | | "getter" 2343 | | "setter" 2344 | | "static-method" 2345 | 2346 | // Values 2347 | | "constant" 2348 | | "variable" 2349 | | "property" 2350 | | "argument" 2351 | | "color" 2352 | | "enum-member" 2353 | | "static-property" 2354 | 2355 | // Expressions 2356 | | "expression" 2357 | | "statement" 2358 | | "block" 2359 | | "heading" 2360 | | "comment" 2361 | | "package" 2362 | | "file" 2363 | | "reference" 2364 | | "keyword" 2365 | | "bookmark" 2366 | 2367 | // Stylesets 2368 | | "style-ruleset" 2369 | | "style-directive" 2370 | | "style-id" 2371 | | "style-class" 2372 | | "style-pseudoclass" 2373 | | "style-pseudoelement" 2374 | 2375 | // Tags 2376 | | "tag" 2377 | | "tag-head" 2378 | | "tag-title" 2379 | | "tag-meta" 2380 | | "tag-link" 2381 | | "tag-body" 2382 | | "tag-script" 2383 | | "tag-style" 2384 | | "tag-heading" 2385 | | "tag-section" 2386 | | "tag-container" 2387 | | "tag-ul" 2388 | | "tag-ol" 2389 | | "tag-li" 2390 | | "tag-anchor" 2391 | | "tag-image" 2392 | | "tag-media" 2393 | | "tag-form" 2394 | | "tag-form-field" 2395 | | "tag-framework" 2396 | 2397 | /** 2398 | * A `Symbol` represents a symbolic construct within an editor’s text, such as a function, type, or interface. Extensions can request symbols from a [TextEditor](https://docs.nova.app/api-reference/text-editor) instance at specific positions in the text. 2399 | * 2400 | * The `Symbol` class is not subclassable. 2401 | */ 2402 | interface Symbol { 2403 | /** The type of the symbol, as a string. */ 2404 | readonly type: SymbolType 2405 | 2406 | /** The range of the symbol within the text, as a [Range](https://docs.nova.app/api-reference/range) object. */ 2407 | readonly range: Range 2408 | 2409 | /** The name of the symbol as used in quick open and autocomplete. */ 2410 | readonly name: string 2411 | 2412 | /** The range of the symbol’s name within the text, as a [Range](https://docs.nova.app/api-reference/range) object. This does not necessarily match exactly with the `name` property, such as if transformations were made on the name during symbolication. */ 2413 | readonly nameRange: Range 2414 | 2415 | /** The name of the symbol as presented in the Symbols list. This may include additional contextual information not included in the text. */ 2416 | readonly displayName: string 2417 | 2418 | /** The comment text associated with the symbol, if any. */ 2419 | readonly comment: string | null 2420 | 2421 | /** The parent symbol containing the receiver, if any. For example, a method symbol’s parent might be a containing class. */ 2422 | readonly parent: Symbol | null 2423 | } 2424 | 2425 | /// https://docs.nova.app/api-reference/task/ 2426 | 2427 | declare type TaskName = string & { __type: 'TaskName' } 2428 | 2429 | /** 2430 | * A `Task` object is used to represent a dynamically-defined task that the user can choose and invoke in the IDE’s task running interface. It allows customization of one or more standard actions in the tasks interface represented in the toolbar and menus. 2431 | * 2432 | * The `Task` class is not subclassable. 2433 | * @since 2.0 2434 | */ 2435 | declare class Task { 2436 | /** An action name used to denote an action bound to “Build”. */ 2437 | static readonly Build: TaskName 2438 | 2439 | /** An action name used to denote an action bound to “Clean”. */ 2440 | static readonly Clean: TaskName 2441 | 2442 | /** An action name used to denote an action bound to “Run”. */ 2443 | static readonly Run: TaskName 2444 | 2445 | /** 2446 | * Creates a new task object with the provided user-readable name, as a string. 2447 | * @example 2448 | * let task = new Task("Say Example"); 2449 | * 2450 | * task.setAction(Task.Build, new TaskProcessAction('/usr/bin/say', { 2451 | * args: ["I'm Building!"], 2452 | * env: {} 2453 | * })); 2454 | * 2455 | * task.setAction(Task.Run, new TaskProcessAction('/usr/bin/say', { 2456 | * args: ["I'm Running!"], 2457 | * env: {} 2458 | * })); 2459 | * 2460 | * task.setAction(Task.Clean, new TaskProcessAction('/usr/bin/say', { 2461 | * args: ["I'm Cleaning!"], 2462 | * env: {} 2463 | * })); 2464 | */ 2465 | constructor(name: string) 2466 | 2467 | /** The user-readable name of the task as a string. */ 2468 | name: string 2469 | 2470 | /** The name of an image to show for the item (see [Images](https://docs.nova.app/extensions/images) for more information). */ 2471 | image: string 2472 | 2473 | /** 2474 | * If set to `true`, then invoking the “Run” action of the task will first invoke the “Build” task. By default, this is `false`. 2475 | * @since 5.0 2476 | */ 2477 | buildBeforeRunning: boolean 2478 | 2479 | /** Returns the action that is defined for the provided name, or `undefined` if no action is set. */ 2480 | getAction(name: string): TaskProcessAction | undefined 2481 | /** Returns the action that is defined for the provided name, or `undefined` if no action is set. */ 2482 | getAction<T extends Transferrable>(name: string): TaskResolvableAction<T> | undefined 2483 | 2484 | /** Sets an action for a provided name. If `action` is `null` or `undefined` the action will be removed from the task. */ 2485 | setAction(name: string, action?: TaskProcessAction | null): void 2486 | /** Sets an action for a provided name. If `action` is `null` or `undefined` the action will be removed from the task. */ 2487 | setAction<T extends Transferrable>(name: string, action?: TaskResolvableAction<T> | null): void 2488 | } 2489 | 2490 | /// https://docs.nova.app/api-reference/task-action-resolve-context/ 2491 | 2492 | /** 2493 | * A `TaskActionResolveContext` object contains contextual information about a [TaskResolvableAction](https://docs.nova.app/api-reference/task-resolvable-action) instance being resolved in response to the user invoking it. An object of this type will be provided to a task provider’s `resolveTaskAction()` method. 2494 | * 2495 | * The `TaskActionResolveContext` class is not subclassable. 2496 | * @since 4.0 2497 | */ 2498 | interface TaskActionResolveContext<T extends Transferable> { 2499 | /** The action type name of the action being invoked, such as `Task.Build`, `Task.Run`, or `Task.Clean`. This value can be compared to see what type of action to resolve. */ 2500 | readonly action: TaskName 2501 | 2502 | /** 2503 | * If the action being resolved is from a Task Template (defined in an extension’s manifest `taskTemplates` key), the property will be a [Configuration](https://docs.nova.app/api-reference/configuration) object that contains configuration values as set in the Project Settings for the task. 2504 | * 2505 | * If the action being resolved is not from a task template (such as one provided by a task assistant) this property will be `undefined`. 2506 | * 2507 | * The configuration object provided for this property is transient. It will not continue to be referenced by the runtime after this resolution of the action is complete. As such, attempting to set values or observe changes on it won’t be particularly useful. 2508 | * @since 5.0 2509 | */ 2510 | readonly config?: Configuration 2511 | 2512 | /** 2513 | * The arbitrary data argument that was provided for the resolvable action which is being resolved. 2514 | * 2515 | * This object can be of any type that is *transferrable*, or encodable in the same way as arguments to the [CommandsRegistry](https://docs.nova.app/api-reference/commands-registry). If not set when the action was defined, this property will be `undefined`. 2516 | */ 2517 | readonly data?: T 2518 | } 2519 | 2520 | /// https://docs.nova.app/api-reference/task-command-action/ 2521 | 2522 | /** 2523 | * A `TaskCommandAction` object represents an action that can be used as part of a [Task](https://docs.nova.app/api-reference/task) that invokes an extension command registered with the [CommandsRegistry](https://docs.nova.app/api-reference/commands-registry), much in the same way as if the user had chosen a menu item bound to it. 2524 | * 2525 | * The `TaskCommandAction` class is not subclassable. 2526 | * @since 3.0 2527 | */ 2528 | declare class TaskCommandAction { 2529 | /** Creates a `TaskCommandAction` object that will invoke the extension command named `command`. */ 2530 | constructor(command: string, options?: { 2531 | /** Arguments to pass to the command. */ 2532 | args?: string[] 2533 | }) 2534 | 2535 | /** 2536 | * The arguments passed to the command. 2537 | * 2538 | * See documentation for the [CommandsRegistry](https://docs.nova.app/api-reference/commands-registry) for more information about how commands are invoked and how their arguments are handled. 2539 | */ 2540 | readonly args: ReadonlyArray<string> 2541 | 2542 | /** The name used to register the command. */ 2543 | readonly command: string 2544 | } 2545 | 2546 | /// https://docs.nova.app/api-reference/task-debug-adapter-action/ 2547 | 2548 | /** 2549 | * A `TaskDebugAdapterAction` object represents an action that can be used as part of a [Task](https://docs.nova.app/api-reference/task) which invokes a [debug adapter](https://docs.nova.app/extensions/debug-adapters) conforming to the [Debug Adapter Protocol](https://microsoft.github.io/debug-adapter-protocol/). 2550 | * 2551 | * The `TaskDebugAdapterAction` class is not subclassable. 2552 | * @since 9.0 2553 | */ 2554 | declare class TaskDebugAdapterAction { 2555 | /** 2556 | * Creates a `TaskDebugAdapterAction` object that interfaces with a debug adapter. 2557 | * 2558 | * The `adapterType` is a string denoting the adapter’s identifier. This identifier should be unique across the workspace, and is generally recommended to be the identifier of the debugger or adapter itself, such as `debugpy`, `chrome-devtools`, etc. This parameter is used to link the instance with its [adapter description](https://docs.nova.app/extensions/debug-adapters/#manifest-description) in the extension manifest. 2559 | * @example 2560 | * class PythonTaskAssistant { 2561 | * resolveTaskAction(context) { 2562 | * let config = context.config; 2563 | * 2564 | * let action = new TaskDebugAdapterAction('debugpy'); 2565 | * 2566 | * action.command = "/usr/bin/python3"; 2567 | * action.args = ["-m", "debugpy"]; 2568 | * 2569 | * action.debugArgs = { 2570 | * program: config.get("python.debug.script", "string") 2571 | * }; 2572 | * 2573 | * task.setActionAction(Task.Run, action); 2574 | * } 2575 | * } 2576 | */ 2577 | constructor(adapterType: string) 2578 | 2579 | /** 2580 | * Determines how the adapter is started by Nova. Valid values are: 2581 | * - `launch`: The adapter is launched directly by Nova. This is the default if a value is not specified. 2582 | * - `attach`: Nova attempts to attach to an already-running instance of the adapter. A `transport` other than `stdio` must be specified for attaching. 2583 | */ 2584 | adapterStart?: "launch" | "attach" 2585 | 2586 | /** 2587 | * The arguments passed to the debug adapter process. 2588 | * 2589 | * **Note:** these are the arguments passed when launching the `adapter`, not the debuggee. Passing arguments to the debuggee requires support from the adapter via a key in the [debugArgs](https://docs.nova.app/api-reference/task-debug-adapter-action/#debugargs) property. This property is ignored if the adapter is not launched by Nova. 2590 | */ 2591 | args?: string[] 2592 | 2593 | /** The command used to launch the debug adapter. This property is ignored if the adapter is not launched by Nova. */ 2594 | command?: string 2595 | 2596 | /** The current working directory for the debug adapter. If not specified, the project directory will be used. This property is ignored if the adapter is not launched by Nova. */ 2597 | cwd?: string 2598 | 2599 | /** 2600 | * Arguments passed to the debug adapter for use in setting up its options and starting the debuggee. This corresponds to the `arguments` argument of the [Launch](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Launch) or [Attach](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Attach) request of the Debug Adapter Protocol. 2601 | * 2602 | * This object is freeform and the contents of it is not defined by Nova’s extension API (beyond it being an object). Check the documentation for the specific adapter for more information. 2603 | */ 2604 | debugArgs?: object 2605 | 2606 | /** 2607 | * The method by which the adapter should attempt to start debugging the debuggee. Valid values are: 2608 | * - `launch`: The adapter will attempt to launch the debuggee by sending a [Launch](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Launch) request. 2609 | * - `attach`: The adapter will attempt to connect to the debuggee by sending an [Attach](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Attach) request. 2610 | * 2611 | * Not all adapters support both types of debug request. Check the documentation for the specific adapter for more information. 2612 | */ 2613 | debugRequest?: "launch" | "attach" 2614 | 2615 | /** The environment variables (as an Object) set for the debug adapter. This property is ignored if the adapter is not launched by Nova. */ 2616 | env?: { [key: string]: string } 2617 | 2618 | /** The host on which to attempt to connect to a Socket to communicate with the adapter. This property is only referenced when the transport is set to `socket`. By default, if no value is specified, this defaults to `localhost`. */ 2619 | socketHost?: string 2620 | 2621 | /** The path at which to connect to a Unix Domain Socket to communicate with the adapter. This property is only referenced when the `transport` is set to `domainSocket`. This property is required if using Unix Domain Socket communication. */ 2622 | socketPath?: string 2623 | 2624 | /** The port on which to attempt to connect to a Socket to communicate with the adapter. This property is only referenced when the `transport` is set to `socket`. This property is required if using Socket communication. */ 2625 | socketPort?: number 2626 | 2627 | /** 2628 | * The transport mechanism to use to communicate with the adapter. Valid values are: 2629 | * - `stdio`: Communicate using Standard I/O. Only valid when the adapter is launched by Nova. 2630 | * - `socket`: Communicate using a TCP Socket. A `socketPort` *must* be specified and a `socketHost` is optional. 2631 | * - `domainSocket`: Communicate using a Unix Domain Socket. A `socketPath` must be specified. 2632 | */ 2633 | transport?: "stdio" | "socket" | "domainSocket" 2634 | } 2635 | 2636 | /// https://docs.nova.app/api-reference/task-process-action/ 2637 | 2638 | /** 2639 | * A `TaskProcessAction` object represents an action that can be used as part of a Task which invokes a Unix subprocess, much in the same way as the [Process](https://docs.nova.app/api-reference/process) class. 2640 | * 2641 | * The `TaskProcessAction` class is not subclassable. 2642 | * @since 2.0 2643 | */ 2644 | declare class TaskProcessAction { 2645 | /** 2646 | * Creates a `TaskProcessAction` object that will launch the executable represented by `command`. 2647 | * @example 2648 | * let action = new TaskProcessAction('/usr/bin/say', { 2649 | * args: ["I'm Running!"], 2650 | * env: {} 2651 | * }); 2652 | * 2653 | * task.setActionAction(Task.Run, action); 2654 | */ 2655 | constructor(command: string, options?: { 2656 | /** Additional arguments to pass. */ 2657 | args?: string[] 2658 | 2659 | /** Additional environment variables to set. */ 2660 | env?: { [key: string]: string } 2661 | 2662 | /** The current working directory path to set for the process. */ 2663 | cwd?: string 2664 | 2665 | /** Run the subprocess within a shell. */ 2666 | shell?: boolean 2667 | 2668 | /** An array of [Issue Matcher](https://docs.nova.app/extensions/issue-matchers/) names used to process output from the action. */ 2669 | matchers?: string[] 2670 | }) 2671 | 2672 | /** The arguments passed to the process, including any specified when the Process was constructed. */ 2673 | readonly args: ReadonlyArray<string> 2674 | 2675 | /** The command used to launch the process. */ 2676 | readonly command: string 2677 | 2678 | /** The current working directory for the process. If not specified, the project directory will be used. */ 2679 | readonly cwd: string 2680 | 2681 | /** The environment variables set for the process, including any specified when the Process was constructed. */ 2682 | readonly env: { [key: string]: string } 2683 | 2684 | /** An array of [Issue Matcher](https://docs.nova.app/extensions/issue-matchers) names that will be used when processing output from the action. If not specified, the standard set of matchers will be used. */ 2685 | readonly matchers: ReadonlyArray<string> 2686 | } 2687 | 2688 | /// https://docs.nova.app/api-reference/task-resolvable-action/ 2689 | 2690 | /** 2691 | * A `TaskResolvableAction` object represents an action that can be used as part of a [Task](https://docs.nova.app/api-reference/task) whose execution details are not known when the action is created. When the user invokes a task’s resolvable action, the action’s task provider will be queried to resolve the action into a more concrete type (such as a [TaskProcessAction](https://docs.nova.app/api-reference/task-process-action). 2692 | * 2693 | * The `TaskResolvableAction` class is not subclassable. 2694 | * @since 4.0 2695 | */ 2696 | declare class TaskResolvableAction<T extends Transferrable> { 2697 | /** Creates a `TaskResolvableAction` object. */ 2698 | constructor(options?: { 2699 | /** An arbitrary transferrable (encodable) type that will be provided when the action is resolved */ 2700 | data?: T 2701 | }) 2702 | 2703 | /** 2704 | * The arbitrary data argument that will be passed to the action’s task provider when it is resolved. 2705 | * 2706 | * This object can be of any type that is *transferrable*, or encodable in the same way as arguments to the [CommandsRegistry](https://docs.nova.app/api-reference/commands-registry). 2707 | * 2708 | * This value will be provided to the task assistant’s `resolveTaskAction()` method through the `context` parameter of type [TaskActionResolveContext](https://docs.nova.app/api-reference/task-action-resolve-context). 2709 | */ 2710 | readonly data: T 2711 | } 2712 | 2713 | /// https://docs.nova.app/api-reference/text-document/ 2714 | 2715 | /** A `TextDocument` represents an open text document in the application. Text document objects are not directly mutable, requiring a [TextEditor](https://docs.nova.app/api-reference/text-editor) object to make modifications. Text documents are not one-to-one to text editors, since multiple editors may be open for a single document. */ 2716 | interface TextDocument { 2717 | /** Returns the document’s unique URI, as a `String`. The URI is guaranteed to exist for all documents, but may change if the document is moved. Unsaved documents have a URI with an `unsaved://` scheme. */ 2718 | readonly uri: string 2719 | 2720 | /** Returns the document’s path, as a `String`. If the document is remote, this will be the path on the relevant server. If the document is unsaved, this may be `null` or `undefined`. */ 2721 | readonly path?: string | null 2722 | 2723 | /** Returns `true` if the document is a remote document. */ 2724 | readonly isRemote: boolean 2725 | 2726 | /** Returns `true` if the document has modifications that are not yet saved to disk. */ 2727 | readonly isDirty: boolean 2728 | 2729 | /** Returns `true` if the document contains no text. */ 2730 | readonly isEmpty: boolean 2731 | 2732 | /** Returns `true` if the document has not yet been saved to disk, and does not have a path. */ 2733 | readonly isUntitled: boolean 2734 | 2735 | /** Returns `true` if the document has been closed. Closed documents are no longer interact-able. */ 2736 | readonly isClosed: boolean 2737 | 2738 | /** Returns, as a `String`, the default line ending string used by the document. */ 2739 | readonly eol: string 2740 | 2741 | /** Returns the length of the document in characters. */ 2742 | readonly length: number 2743 | 2744 | /** Returns the identifier for the document’s language syntax. If the document is plain text, this may be `null` or `undefined`. */ 2745 | readonly syntax?: string | null 2746 | 2747 | /** 2748 | * Returns a section of the document’s text indicated by a provided [Range](https://docs.nova.app/api-reference/range) as a `String`. 2749 | * @throws If the range exceeds the receiver’s bounds, an `Error` will be thrown. 2750 | */ 2751 | getTextInRange(range: Range): string 2752 | 2753 | /** 2754 | * Given a [Range](https://docs.nova.app/api-reference/range), this method will return the range of all lines encompassing that range. 2755 | * @throws If the range exceeds the receiver’s bounds, an `Error` will be thrown. 2756 | */ 2757 | getLineRangeForRange(range: Range): Range 2758 | 2759 | /** Adds an event listener that invokes the provided `callback` when the document’s path changes. The callback will receive as an argument the document object and the new path (or `null` if the document does not have a path). */ 2760 | onDidChangePath(callback: (document: TextDocument, path: string | null) => void): Disposable 2761 | 2762 | /** Adds an event listener that invokes the provided `callback` when the document’s syntax (language) changes. The callback will receive as an argument the document object and the new syntax name (or `null` if the document does not have a syntax / is plain text). */ 2763 | onDidChangeSyntax(callback: (document: TextDocument, syntax: string | null) => void): Disposable 2764 | } 2765 | 2766 | /// https://docs.nova.app/api-reference/text-edit/ 2767 | 2768 | /** 2769 | * A `TextEdit` describes a single change that may be applied to a [TextEditor](https://docs.nova.app/api-reference/text-editor). An array of `TextEdit` objects represent a set of changes that may be applied together atomically. `TextEdit` objects are most often used with APIs such as [CompletionItem](https://docs.nova.app/api-reference/completion-item) to describe set of edits to apply. 2770 | * @since 2.0 2771 | */ 2772 | declare class TextEdit { 2773 | /** Returns a new text edit that deletes text in the [Range](https://docs.nova.app/api-reference/range) `range`. */ 2774 | static delete(range: Range): TextEdit 2775 | 2776 | /** Returns a new text edit that inserts text at position. */ 2777 | static insert(position: number, newText: string): TextEdit 2778 | 2779 | /** Returns a new text edit that replaces the [Range](https://docs.nova.app/api-reference/range) `range` with `newText`. */ 2780 | static replace(range: Range, newText: string): TextEdit 2781 | 2782 | /** Creates a new text edit that replaces the [Range](https://docs.nova.app/api-reference/range) `range` with `newText`. */ 2783 | constructor(range: Range, newText: string) 2784 | 2785 | /** A `String` that will be inserted when the text edit is applied. */ 2786 | readonly newText: string 2787 | 2788 | /** The [Range](https://docs.nova.app/api-reference/range) that will be replaced when the edit is applied. */ 2789 | readonly range: Range 2790 | } 2791 | 2792 | /// https://docs.nova.app/api-reference/text-editor/ 2793 | 2794 | /** A `TextEditor` represents an open text editor in the application. An editor has a reference to its backing [TextDocument](https://docs.nova.app/api-reference/text-document) object. Text editors are not one-to-one to text documents, since multiple editors may be open for a single document. */ 2795 | interface TextEditor { 2796 | /** Returns `true` if the object provided is a `TextEditor` instance, otherwise returning `false`. This can be most useful for a [Commands](https://docs.nova.app/extensions/commands) handler function, which can receive either a [Workspace](https://docs.nova.app/api-reference/workspace) or `TextEditor` instance as its first argument. */ 2797 | static isTextEditor(object: any): boolean 2798 | 2799 | /** The [TextDocument](https://docs.nova.app/api-reference/text-document) object backing the editor. */ 2800 | readonly document: TextDocument 2801 | 2802 | /** The currently selected range, as a [Range](https://docs.nova.app/api-reference/range). If the receiver has multiple selected ranges, this will return the primary range (generally the first range). */ 2803 | selectedRange: Range 2804 | 2805 | /** An array of all currently selected ranges, as [Range](https://docs.nova.app/api-reference/range) objects. The ranges are guaranteed to be in ascending order, and have no intersections. */ 2806 | selectedRanges: Range[] 2807 | 2808 | /** The currently selected text, as a `String`. If the receiver has multiple selected ranges, this will return the text for the primary range (as returned by `selectedRange`). */ 2809 | readonly selectedText: string 2810 | 2811 | /** Whether the editor is set to use soft tabs (spaces). */ 2812 | softTabs: boolean 2813 | 2814 | /** The number of spaces used as a single tab length. */ 2815 | tabLength: number 2816 | 2817 | /** A `String` representation of a single tab in the editor’s preferred indentation style and tab width. */ 2818 | readonly tabText: string 2819 | 2820 | /** 2821 | * Begins an atomic edit session for the editor. 2822 | * 2823 | * The first argument must be a callable that will be invoked immediately to collect changes. The caller is responsible for doing all work in the callback it intends to represent a “single” operation on the undo stack. 2824 | * 2825 | * The callback will receive as an argument a [TextEditorEdit](https://docs.nova.app/api-reference/text-editor-edit) object that can be used to queue changes for the edit operation. 2826 | * 2827 | * This method returns a `Promise` object that resolves when the edit operation is either accepted or rejected by the editor. The editor may reject an edit operation if, for example, the extension has taken too long to queue changes such that editor responsiveness may be impacted. 2828 | * @throws It is a programming error to invoke this method from within a text change callback (such as one registered using `onDidChange()`). Attempting to do so will throw an `Error`. 2829 | */ 2830 | edit(callback: (edit: TextEditorEdit) => void, options?: unknown): Promise<void> 2831 | // TODO: Options not documented 2832 | 2833 | /** 2834 | * Shorthand for inserting text quickly at the editor’s current insertion point(s). If there is any selection, it will be replaced by the provided text. Multiple calls to `insert()` within the same function will not be coalesced into one undo operation. To coalesce changes into a single undo operation, use the `edit()` API. 2835 | * 2836 | * This method returns a `Promise` object that resolves when the insert operation is either accepted or rejected by the editor. The editor may reject an insert operation if, for example, the extension has taken too long to queue changes such that editor responsiveness may be impacted. 2837 | * 2838 | * **The format argument was added in Nova 1.2.** 2839 | * @throws It is a programming error to invoke this method from within a text change callback (such as one registered using `onDidChange()`). Attempting to do so will throw an `Error`. 2840 | */ 2841 | insert(string: string, format?: InsertTextFormat): Promise<void> 2842 | 2843 | /** 2844 | * Requests that the editor be saved. For unsaved documents, this will present a modal save panel to the user requesting that a path be chosen. 2845 | * 2846 | * This method returns a `Promise` object that resolves when the save operation is finished, or rejects if the save operation failed. 2847 | */ 2848 | save(): Promise<void> 2849 | 2850 | /** 2851 | * Returns a section of the document’s text indicated by a provided [Range](https://docs.nova.app/api-reference/range) as a `String`. 2852 | * 2853 | * This is a convenience method that is effectively the same as invoking `getTextInRange(range)` on the editor’s document. 2854 | * @throws If the range exceeds the receiver’s bounds, an `Error` will be thrown. 2855 | */ 2856 | getTextInRange(range: Range): string 2857 | 2858 | /** 2859 | * Given a [Range](https://docs.nova.app/api-reference/range), this method will return the range of all lines encompassing that range. 2860 | * 2861 | * This is a convenience method that is effectively the same as invoking `getLineRangeForRange(range)` on the editor’s document. 2862 | * @throws If the range exceeds the receiver’s bounds, an `Error` will be thrown. 2863 | */ 2864 | getLineRangeForRange(range: Range): Range 2865 | 2866 | /** 2867 | * Adds an event listener that invokes the provided `callback` when the editor’s text changes. The callback will receive as an argument the `TextEditor` object. 2868 | * 2869 | * **Note:** This callback is potentially invoked very often as text changes. If you would like to perform actions in response to a user pausing after typing, consider the `onDidStopChanging()` event handler instead. 2870 | * 2871 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 2872 | */ 2873 | onDidChange<T>(callback: (this: T, editor: TextEditor) => void, thisValue?: T): Disposable 2874 | 2875 | /** 2876 | * Adds an event listener that invokes the provided `callback` a short time after the editor stops changing. Multiple changes to text in a short time will be coalesced into one event that can be acted upon performantly. The callback will receive as an argument the `TextEditor` object. 2877 | * 2878 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 2879 | */ 2880 | onDidStopChanging<T>(callback: (this: T, editor: TextEditor) => void, thisValue?: T): Disposable 2881 | 2882 | /** 2883 | * Adds an event listener that invokes the provided `callback` just before the editor is saved. The callback will receive as an argument the `TextEditor` object. If the callback performs modifications to the editor within the callback (such as with `edit()`), they will be applied in such a way as to include them in the pending save operation. 2884 | * 2885 | * This method may return a `Promise` object to denote to the runtime that changes need to be performed asynchronously. The IDE will wait for the promise to resolve or reject as part of its wait time. 2886 | * 2887 | * If a callback registered using this method (or a promise returned from it) takes too long to perform operations, any edits enqueued may be deferred until after the save operation, or discarded entirely. In the case they are discarded, an error will be reported from the `Promise` object returned from `edit()`. The exact amount of time may vary, but the runtime guarantees that it will allow at least 5 seconds for all extensions to perform their operations. 2888 | * 2889 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 2890 | */ 2891 | onWillSave<T>(callback: (this: T, editor: TextEditor) => void | Promise<void>, thisValue?: T): Disposable 2892 | 2893 | /** 2894 | * Adds an event listener that invokes the provided `callback` when the editor is saved. The callback will receive as an argument the `TextEditor` object. 2895 | * 2896 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 2897 | */ 2898 | onDidSave<T>(callback: (this: T, editor: TextEditor) => void, thisValue?: T): Disposable 2899 | 2900 | /** 2901 | * Adds an event listener that invokes the provided `callback` when the editor’s selected ranges change. The callback will receive as an argument the `TextEditor` object. 2902 | * 2903 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 2904 | */ 2905 | onDidChangeSelection<T>(callback: (this: T, editor: TextEditor) => void, thisValue?: T): Disposable 2906 | 2907 | /** 2908 | * Adds an event listener that invokes the provided `callback` when the editor is being closed. The callback will receive as an argument the `TextEditor` object. 2909 | * 2910 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 2911 | */ 2912 | onDidDestroy<T>(callback: (this: T, editor: TextEditor) => void, thisValue?: T): Disposable 2913 | 2914 | /** 2915 | * Moves the editor’s selected ranges upward a specific number of rows. If no row count parameter is provided, the selection will be moved one row. 2916 | * @since 5.0 2917 | */ 2918 | moveUp(rowCount?: number): void 2919 | 2920 | /** 2921 | * Moves the editor’s selected ranges downward a specific number of rows. If no row count parameter is provided, the selection will be moved one row. 2922 | * @since 5.0 2923 | */ 2924 | moveDown(rowCount?: number): void 2925 | 2926 | /** 2927 | * Moves the editor’s selected ranges leftward a specific number of columns. If no column count parameter is provided, the selection will be moved one column. 2928 | * @since 5.0 2929 | */ 2930 | moveLeft(columnCount?: number): void 2931 | 2932 | /** 2933 | * Moves the editor’s selected ranges rightward a specific number of columns. If no column count parameter is provided, the selection will be moved one column. 2934 | * @since 5.0 2935 | */ 2936 | moveRight(columnCount?: number): void 2937 | 2938 | /** 2939 | * Moves the editor’s selected range to the top of the document, before the first character. 2940 | * @since 5.0 2941 | */ 2942 | moveToTop(): void 2943 | 2944 | /** 2945 | * Moves the editor’s selected range to the end of the document, after the last character. 2946 | * @since 5.0 2947 | */ 2948 | moveToBottom(): void 2949 | 2950 | /** 2951 | * Moves the editor’s selected ranges to the beginning of each line containing them. 2952 | * @since 5.0 2953 | */ 2954 | moveToBeginningOfLine(): void 2955 | 2956 | /** 2957 | * Moves the editor’s selected ranges to the end of each line containing them. 2958 | * @since 5.0 2959 | */ 2960 | moveToEndOfLine(): void 2961 | 2962 | /** 2963 | * Moves the editor’s selected ranges to the beginning of the word containing or against the start of each range. 2964 | * @since 5.0 2965 | */ 2966 | moveToBeginningOfWord(): void 2967 | 2968 | /** 2969 | * Moves the editor’s selected ranges to the beginning of the word containing or against the end of each range. 2970 | * @since 5.0 2971 | */ 2972 | moveToEndOfWord(): void 2973 | 2974 | /** Adds the provided [Range](https://docs.nova.app/api-reference/range) to the editor’s selected ranges, automatically coalescing any overlapping ranges. If the provided range is zero-length, the range will be added as a cursor. */ 2975 | addSelectionForRange(range: Range): void 2976 | 2977 | /** Extends the editor’s primary selected range to the provided character position. */ 2978 | selectToPosition(position: number): void 2979 | 2980 | /** Extends the editor’s primary selected range upward a specific number of lines. If no row count parameter is provided, the selection will be extended one row. */ 2981 | selectUp(rowCount?: number): void 2982 | 2983 | /** Extends the editor’s primary selected range downward a specific number of lines. If no row count parameter is provided, the selection will be extended one row. */ 2984 | selectDown(rowCount?: number): void 2985 | 2986 | /** Extends the editor’s primary selected range leftward a specific number of characters. If no column count parameter is provided, the selection will be extended one column. */ 2987 | selectLeft(columnCount?: number): void 2988 | 2989 | /** Extends the editor’s primary selected range rightward a specific number of characters. If no column count parameter is provided, the selection will be extended one column. */ 2990 | selectRight(columnCount?: number): void 2991 | 2992 | /** Extends the editor’s primary selected range to the beginning of the text. */ 2993 | selectToTop(): void 2994 | 2995 | /** Extends the editor’s primary selected range to the end of the text. */ 2996 | selectToBottom(): void 2997 | 2998 | /** Selects all text in the editor. */ 2999 | selectAll(): void 3000 | 3001 | /** Extends all selected ranges and cursors to encompass all lines in which they intersect. */ 3002 | selectLinesContainingCursors(): void 3003 | 3004 | /** Extends all selected ranges and cursors backward to the beginning of their first (or only) line. */ 3005 | selectToBeginningOfLine(): void 3006 | 3007 | /** Extends all selected ranges and cursors forward to the end of their last (or only) line. */ 3008 | selectToEndOfLine(): void 3009 | 3010 | /** Extends all selected ranges and cursors to encompass all words in which they intersect. */ 3011 | selectWordsContainingCursors(): void 3012 | 3013 | /** Extends all selected ranges and cursors backward to the beginning of their first (or only) word. */ 3014 | selectToBeginningOfWord(): void 3015 | 3016 | /** Extends all selected ranges and cursors forward to the end of their last (or only) word. */ 3017 | selectToEndOfWord(): void 3018 | 3019 | /** Scrolls the editor to ensure that the primary selected range is visible. */ 3020 | scrollToCursorPosition(): void 3021 | 3022 | /** Scrolls the editor to ensure that the provided character position is visible. */ 3023 | scrollToPosition(position: number): void 3024 | 3025 | /** 3026 | * Begins a shadow typing session for the editor with a set of ranges. The ranges provided will be added as selected text ranges (or cursors, if zero-length) in the editor in a similar way to adding them to the `selectedRanges` property. However, the ranges will only remain valid while typing text in the current undo coalescing state. If the selection or undo state changes by any other means (such as by moving the cursors manually or saving the document), the ranges will be removed and the shadow typing session will end. 3027 | * 3028 | * The optional `charset` argument may be provided with a [Charset](https://docs.nova.app/api-reference/charset) object. As the user types, the characters will be compared with this character set. If a character does not match, the shadow typing session will end automatically. 3029 | */ 3030 | startShadowTyping(ranges: Range[], charset?: Charset): void 3031 | 3032 | /** Explicitly ends the current shadow typing session, if any. It’s generally not required to invoke this manually except in very specific circumstances that the shadow typing session’s attribute (such as its charset) cannot handle. */ 3033 | endShadowTyping(): void 3034 | 3035 | /** Gets the deepest displayable symbol containing the provided text position, as a [Symbol](https://docs.nova.app/api-reference/symbol) object. If no symbol could be found, this method returns `null`. */ 3036 | symbolAtPosition(position: number): Symbol | null 3037 | 3038 | /** Gets the deepest displayable symbol for the start position of each of the selected ranges of the editor, as an array of [Symbol](https://docs.nova.app/api-reference/symbol) objects. If no symbol could be found at a specific position, the array will contain a `null` entry for that range. */ 3039 | symbolsForSelectedRanges() 3040 | } 3041 | 3042 | /// https://docs.nova.app/api-reference/text-editor-edit/ 3043 | 3044 | /** Enumeration defining in what format the text provided should be parsed. */ 3045 | declare enum InsertTextFormat { 3046 | /** The text is plain text and will not be modified (the default value). */ 3047 | PlainText, 3048 | 3049 | /** The text uses the [Snippets](https://docs.nova.app/extensions/snippets/) format and will be parsed for editor placeholders. */ 3050 | Snippet 3051 | } 3052 | 3053 | /** 3054 | * A `TextEditorEdit` object is used to queue changes within a call to a [TextEditor](https://docs.nova.app/api-reference/text-editor)’s `edit()` method. Multiple calls to an edit’s methods will be performed atomically to the editor as one operation on the undo stack. 3055 | * 3056 | * Changes are incurred in the order in which they are invoked on the `TextEditorEdit` object. As such, ranges provided to successive calls must ensure they take into account changes in character positions and ranges due to previous edits in the operation. 3057 | */ 3058 | interface TextEditorEdit { 3059 | /** Deletes text in the the provided [Range](https://docs.nova.app/api-reference/range). */ 3060 | delete(range: Range): void 3061 | 3062 | /** 3063 | * Replaces text in the the provided [Range](https://docs.nova.app/api-reference/range) with a new text string. This method differs from `insert()` in that it will not move the cursor. 3064 | * 3065 | * The third argument provided, format, is an `InsertTextFormat` enumeration value defining in what format the text provided should be parsed. **This argument was added in Nova 5.** 3066 | * Supported values are: 3067 | * - InsertTextFormat.PlainText: The text is plain text and will not be modified (the default value). 3068 | * - InsertTextFormat.Snippet: The text uses the Snippets format and will be parsed for editor placeholders. 3069 | */ 3070 | replace(range: Range, text: string, format?: InsertTextFormat): void 3071 | 3072 | /** 3073 | * Inserts text at the provided character position (`Number`). This method differs from `replace()` in that it will automatically move the cursor. 3074 | * 3075 | * The third argument provided, `format`, is an `InsertTextFormat` enumeration value defining in what format the text provided should be parsed. **This argument was added in Nova 5.** 3076 | * Supported values are: 3077 | * - InsertTextFormat.PlainText: The text is plain text and will not be modified (the default value). 3078 | * - InsertTextFormat.Snippet: The text uses the Snippets format and will be parsed for editor placeholders. 3079 | */ 3080 | insert(position: number, text: string, format?: InsertTextFormat): void 3081 | } 3082 | 3083 | /// https://docs.nova.app/api-reference/tree-data-provider/ 3084 | 3085 | /** 3086 | * A `TreeDataProvider` interface should be implemented by objects that provide data to a [TreeView](https://docs.nova.app/api-reference/tree-view). 3087 | * 3088 | * The elements provided as data objects by a `TreeDataProvider` may be any valid JavaScript object. 3089 | * @example 3090 | * interface TreeDataProvider { 3091 | * getChildren(element); 3092 | * getParent(element); 3093 | * getTreeItem(element); 3094 | * } 3095 | */ 3096 | interface TreeDataProvider<E> { 3097 | /** Returns an array of children for an element (or a `Promise` that resolves to it). The `element` will be `null` for the root of the tree. */ 3098 | getChildren(element: E | null): E[] | Promise<E[]> 3099 | 3100 | /** Returns the parent of an element. This is an optional method used for the `TreeView` `reveal()` API. */ 3101 | getParent(element: E): E | null 3102 | 3103 | /** Returns the [TreeItem](https://docs.nova.app/api-reference/tree-item) representation of an element. */ 3104 | getTreeItem(element: E): TreeItem 3105 | } 3106 | 3107 | /// https://docs.nova.app/api-reference/tree-item/ 3108 | 3109 | declare enum TreeItemCollapsibleState { 3110 | /** The item cannot be expanded (it is a leaf item). */ 3111 | None, 3112 | 3113 | /** The item can be expanded, but is collapsed by default. */ 3114 | Collapsed, 3115 | 3116 | /** The item can be expanded, and is expanded by default. */ 3117 | Expanded 3118 | } 3119 | 3120 | /** 3121 | * A `TreeItem` object is the visual representation of an element represented within the dataset of a [TreeView](https://docs.nova.app/api-reference/tree-view). Tree items define attributes such as the element’s label, description, and icon. 3122 | * 3123 | * The `TreeItem` class is not subclassable. 3124 | * @example 3125 | * let item = new TreeItem("image.png", TreeItemCollapsibleState.None); 3126 | * 3127 | * item.descriptiveText = "PNG file"; 3128 | * item.path = "path/to/image.png"; 3129 | */ 3130 | declare class TreeItem { 3131 | /** Creates a new `TreeItem` object. The collapsibleState argument defaults to `TreeItemCollapsibleState.None`. */ 3132 | constructor(name: string, collapsibleState?: TreeItemCollapsibleState) 3133 | 3134 | /** The display name of the item, as a `string`. */ 3135 | name: string 3136 | 3137 | /** Defines how an item is displayed with regards to being expanded. The default value is `TreeItemCollapsibleState.None`, which indicates the item cannot be expanded. */ 3138 | collapsibleState: TreeItemCollapsibleState 3139 | 3140 | /** An optional [Command](https://docs.nova.app/extensions/commands) to invoke when the item is double-clicked. */ 3141 | command?: string 3142 | 3143 | /** 3144 | * When set to a [Color](https://docs.nova.app/api-reference/color) object, the color will be rendered as a swatch in the item’s row in place of its image. 3145 | * 3146 | * If both `image` and `color` are set on a tree item, the image will take priority. 3147 | */ 3148 | color?: Color 3149 | 3150 | /** A value used when validating the `when` clause of commands for the tree view. This value may be used for when clauses of the form `viewItem == '<contextValue>'`. */ 3151 | contextValue?: string 3152 | 3153 | /** A short description of the item, as a `string`. This will be displayed alongside the item’s label, if space allows. */ 3154 | descriptiveText?: string 3155 | 3156 | /** An optional unique identifier for the item, as a `string`. This identifier must be unique across the entire tree. This will be used to preserve selection and expansion state. */ 3157 | identifier?: string 3158 | 3159 | /** 3160 | * The name of an image to show for the item (see [Images](https://docs.nova.app/extensions/images) for more information). 3161 | * 3162 | * If both `image` and `color` are set on a tree item, the image will take priority. 3163 | */ 3164 | image?: string 3165 | 3166 | /** The file-system path to the item as a `string`, if appropriate. If this is specified, and `image` is not defined, the image will by default use the appropriate file-type image for this path. */ 3167 | path?: string 3168 | 3169 | /** A tooltip to display when hovering over the item, as a `string`. */ 3170 | tooltip?: string 3171 | } 3172 | 3173 | /// https://docs.nova.app/api-reference/tree-view/ 3174 | 3175 | /** 3176 | * A `TreeView` object acts as the interface to working with a custom extension sidebar using a tree style (an outline of objects with disclosure buttons). When you define a tree sidebar, you also create a `TreeView` object to provide data and respond to events for that sidebar. 3177 | * 3178 | * The `TreeView` class is not subclassable. 3179 | * @implements {Disposable} 3180 | * @example 3181 | * // Create the TreeView 3182 | * let treeView = new TreeView("my-identifier", { 3183 | * dataProvider: new MyDataProvider() 3184 | * }); 3185 | * 3186 | * treeView.onDidChangeSelection((selection) => { 3187 | * console.log("New selection: " + selection.map((e) => e.name)); 3188 | * }); 3189 | * 3190 | * treeView.onDidExpandElement((element) => { 3191 | * console.log("Expanded: " + element.name); 3192 | * }); 3193 | * 3194 | * treeView.onDidCollapseElement((element) => { 3195 | * console.log("Collapsed: " + element.name); 3196 | * }); 3197 | * 3198 | * treeView.onDidChangeVisibility(() => { 3199 | * console.log("Visibility Changed"); 3200 | * }); 3201 | */ 3202 | declare class TreeView<E> extends Disposable { 3203 | /** Creates a new `TreeView` object. The `identifier` argument should match the identifier specified for a sidebar section in your extension’s `extension.json` file. */ 3204 | constructor(identifier: string, options?: { 3205 | /** Object that provides data to the tree (see [TreeDataProvider](https://docs.nova.app/api-reference/tree-data-provider)). */ 3206 | dataProvider?: TreeDataProvider<E> 3207 | }) 3208 | 3209 | /** Whether the tree view is currently visible. */ 3210 | readonly visible: boolean 3211 | 3212 | /** An array of elements that are currently selected within the tree view. */ 3213 | readonly selection: ReadonlyArray<E> 3214 | 3215 | /** 3216 | * Adds an event listener that invokes the provided `callback` when the tree view’s selection change. The callback will receive as an argument the array of selected elements. 3217 | * 3218 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 3219 | */ 3220 | onDidChangeSelection<T>(callback: (this: T, selectedElements: E[]) => void, thisValue?: T): Disposable 3221 | 3222 | /** 3223 | * Adds an event listener that invokes the provided `callback` when the tree view’s visibility change. 3224 | * 3225 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 3226 | */ 3227 | onDidChangeVisibility<T>(callback: (this: T) => void, thisValue?: T): Disposable 3228 | 3229 | /** 3230 | * Adds an event listener that invokes the provided `callback` when the an element is expanded. The callback will receive as an argument the element that was expanded. 3231 | * 3232 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 3233 | */ 3234 | onDidExpandElement<T>(callback: (this: T, element: E) => void, thisValue?: T): Disposable 3235 | 3236 | /** 3237 | * Adds an event listener that invokes the provided `callback` when the an element is collapsed. The callback will receive as an argument the element that was collapsed. 3238 | * 3239 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 3240 | */ 3241 | onDidCollapseElement<T>(callback: (this: T, element: E) => void, thisValue?: T): Disposable 3242 | 3243 | /** 3244 | * Causes the tree view to reload the specified element (if it is visible) and any descendants. Invoke this method with no argument (or with a `null` or `undefined` argument) to reload the entire tree view. Returns a `Promise` object that resolves when the reload has finished. 3245 | */ 3246 | reload(element?: E | null): Promise<void> 3247 | 3248 | /** Attempts to reveal the element in the tree. */ 3249 | reveal(element: E, options?: { 3250 | /** Whether the element should be selected (default is `true`). */ 3251 | select?: boolean 3252 | 3253 | /** Whether the scroll view of the tree should be scrolled to make the element visible (default is `false`). */ 3254 | focus?: boolean 3255 | 3256 | /** The number of ancestors to attempt to expand to reveal the element (up to a maximum of 3). */ 3257 | reveal?: number 3258 | }): void 3259 | } 3260 | 3261 | /// https://docs.nova.app/api-reference/web-apis/ 3262 | 3263 | // TODO: Finish WEB APIs 3264 | 3265 | declare function atob(data: string): string 3266 | declare function btoa(data: string): string 3267 | 3268 | type TimerHandler = string | Function 3269 | 3270 | declare function setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number 3271 | declare function clearTimeout(handle?: number): void 3272 | 3273 | declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number 3274 | declare function clearInterval(handle?: number): void 3275 | 3276 | /// https://docs.nova.app/api-reference/workspace/ 3277 | 3278 | /** 3279 | * A `Workspace` contains properties and methods related to an open workspace window. Extensions are loaded on a per-workspace basis, so there is generally only one workspace object available from the perspective of executing extension code. 3280 | * 3281 | * An instance representing the current workspace is always available via the `workspace` property of the global `nova` [Environment](https://docs.nova.app/api-reference/environment) object. 3282 | */ 3283 | interface Workspace { 3284 | /** The `TextEditor` instance that is currently focused in the workspace. This may be `null` if no text editor is focused. */ 3285 | readonly activeTextEditor: TextEditor | null 3286 | 3287 | /** 3288 | * The [Configuration](https://docs.nova.app/api-reference/configuration) object for the workspace, written into the workspace’s internal metadata folder. 3289 | * 3290 | * Extensions may store values in this configuration that should be written into a per-workspace storage, and potentially stored in source control by the user. 3291 | */ 3292 | readonly config: Configuration 3293 | 3294 | /** 3295 | * An array of [DebugSession](https://docs.nova.app/api-reference/debug-session) objects which are running for the workspace. 3296 | * @since 9.0 3297 | */ 3298 | readonly debugSessions: ReadonlyArray<DebugSession> 3299 | 3300 | /** Returns the workspace’s path on disk, as a `String`. If the workspace is not bound to a folder this may be `null` or `undefined`. */ 3301 | readonly path?: string | null 3302 | 3303 | /** 3304 | * The root path of the workspace’s preview. This path represents the directory being served at the root of previews. This property will return `null` or `undefined` in cases where previewing is not available for the workspace. 3305 | * @since 9.0 3306 | */ 3307 | readonly previewRootPath?: string | null 3308 | 3309 | /** 3310 | * The computed URL for the workspace’s preview as a `String`. If the workspace is using Nova’s built-in web server this property will represent that server’s root. If the workspace has a custom preview URL set by the user this property will represent that URL. This method will return `null` or `undefined` in cases where previewing is not available for the workspace. 3311 | * @since 9.0 3312 | */ 3313 | readonly previewURL?: string | null 3314 | 3315 | /** An array of [TextDocument](https://docs.nova.app/api-reference/text-document) objects representing each document open in the workspace. Text Documents are not necessarily one-to-one with the `textEditors` properties, as multiple editors can be opened for a single text document. */ 3316 | readonly textDocuments: ReadonlyArray<TextDocument> 3317 | 3318 | /** An array of [TextEditor](https://docs.nova.app/api-reference/text-editor) objects representing each text editor open in the workspace. Text Editors are not necessarily one-to-one with the `textDocuments` properties, as multiple editors can be opened for a single document. */ 3319 | readonly textEditors: ReadonlyArray<TextEditor> 3320 | 3321 | /** Returns `true` if the workspace contains the file at a specified path. If the workspace is not bound to a folder, this method always returns `false`. */ 3322 | contains(path: string): boolean 3323 | 3324 | /** 3325 | * Adds an event listener that invokes the provided `callback` when the workspace opens a text editor. The callback will receive as an argument the [TextEditor](https://docs.nova.app/api-reference/text-editor) object. 3326 | * 3327 | * As a convenience, when this method is invoked the callback will also immediately be called with all open text editors. 3328 | * 3329 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 3330 | */ 3331 | onDidAddTextEditor<T>(callback: (this: T, editor: TextEditor) => void, thisValue?: T): Disposable 3332 | 3333 | /** 3334 | * Adds an event listener that invokes the provided `callback` when the workspace’s path changes. The callback will receive as an argument the new path as a string. 3335 | * 3336 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 3337 | */ 3338 | onDidChangePath<T>(callback: (this: T, newPath: string) => void, thisValue?: T): Disposable 3339 | 3340 | /** 3341 | * Adds an event listener that invokes the provided `callback` when the workspace ends a debug session. The callback will receive as an argument the [DebugSession](https://docs.nova.app/api-reference/debug-session) object. 3342 | * 3343 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 3344 | * @since 9.0 3345 | */ 3346 | onDidEndDebugSession<T>(callback: (this: T, debugSession: DebugSession) => void, thisValue?: T): Disposable 3347 | 3348 | /** 3349 | * Adds an event listener that invokes the provided `callback` when the workspace opens a text document. The callback will receive as an argument the [TextDocument](https://docs.nova.app/api-reference/text-document) object. 3350 | * 3351 | * As a convenience, when this method is invoked the callback will also immediately be called with all open text documents. 3352 | * 3353 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 3354 | */ 3355 | onDidOpenTextDocument<T>(callback: (this: T, document: TextDocument) => void, thisValue?: T): Disposable 3356 | 3357 | /** 3358 | * Adds an event listener that invokes the provided `callback` when the workspace starts a debug session. The callback will receive as an argument the [DebugSession](https://docs.nova.app/api-reference/debug-session) object. 3359 | * 3360 | * The optional `thisValue` argument may be used to set what `this` is bound to when the callable is invoked. If omitted, `this` will be `undefined`. 3361 | * @since 9.0 3362 | */ 3363 | onDidStartDebugSession<T>(callback: (this: T, debugSession: DebugSession) => void, thisValue?: T): Disposable 3364 | 3365 | /** Requests the workspace open the project settings view for a specified extension, by identifier. If no identifier is specified, the current extension’s project settings will be opened. */ 3366 | openConfig(identifier?: string): void 3367 | 3368 | /** Requests the workspace open a file by URI. For local files, this can be either a file:// URI or a path on disk. Returns a `Promise` object that, on success, resolves to the new editor’s object (usually a [TextEditor](https://docs.nova.app/api-reference/text-editor) object), or `null` if the editor does not expose extension API. */ 3369 | openFile(uri: string, options?: { 3370 | /** Line number to jump to after opening. */ 3371 | line?: number, 3372 | 3373 | /** Column number to jump to after opening (requires `line`). */ 3374 | column?: number 3375 | }): Promise<TextEditor> | null 3376 | 3377 | /** Requests the workspace open a new, untitled document tab. */ 3378 | openNewTextDocument(options?: { 3379 | /** The content of the new document, if any. */ 3380 | content?: string 3381 | 3382 | /** Line number to jump to after opening. */ 3383 | line?: number 3384 | 3385 | /** Column number to jump to after opening (requires `line`). */ 3386 | column?: number 3387 | 3388 | /** The identifier for a syntax to set for the document. If not specified, the user’s default syntax will be used. */ 3389 | syntax: string 3390 | }) 3391 | 3392 | /** 3393 | * Returns a `String` representing the URL for previewing the file at the specified path. This method will return `null` or `undefined` in cases where previewing is not available for the workspace or if the specified file is not within the directory tree being served by the workspace’s preview. 3394 | * @since 9.0 3395 | */ 3396 | previewURLForPath(path: string): string | null | undefined 3397 | 3398 | /** Converts an absolute path into a path relative to the workspace root. If the provided path is not a descendant of the workspace root then relative prefix components (`../`) will be applied as necessary to create a relative path. If the workspace is not bound to a folder this method returns the path unchanged. */ 3399 | relativizePath(path): string 3400 | 3401 | /** 3402 | * Requests that the IDE reload tasks from the [task assistant](https://docs.nova.app/api-reference/assistants-registry) with the provided identifier. This will cause the IDE to invoke the `provideTasks()` method on the assistant asynchronously. 3403 | * 3404 | * If an assistant with the provided identifier is not registered this method has no effect. 3405 | */ 3406 | reloadTasks(identifier: string): void 3407 | 3408 | /** 3409 | * Displays an action panel to the user. The panel will be titled with the calling extension’s name, and the provided `message` will be displayed as the panel body. 3410 | * 3411 | * The optional `callback` argument should be a callable, which will be invoked when the user chooses a button in the alert. The callback will be passed the button index chosen (as a `Number`), or `null` if the alert was dismissed by other means (such as the application cancelling the alert without user intervention). 3412 | */ 3413 | showActionPanel(message: string, options?: { 3414 | /** 3415 | * An array of strings, used as button names in the alert. 3416 | * 3417 | * If not specified, a single “OK” button will be included. 3418 | */ 3419 | buttons?: string[] 3420 | }, callback?: (buttonIndex: number | null) => void): void 3421 | 3422 | /** 3423 | * Displays a choice palette to the user (in the style of the command palette). The provided array of strings, `choices`, will be displayed as the initial results of the palette, and can be filtered by the user by typing. 3424 | * 3425 | * The optional `callback` argument should be a callable, which will be invoked when the user confirms with the Return key. The callback will be passed the choice (from the `choices` array) selected by the user or `null` if the palette was cancelled, as well as optionally the index of the choice within the provided array as the second argument. 3426 | */ 3427 | showChoicePalette(choices: string[], options?: { 3428 | /** Text to display if no value is present. */ 3429 | placeholder?: string 3430 | }, callback?: (choice: string | null, choiceIndex: number | null) => void): void 3431 | 3432 | /** Displays an error message to the user as an alert. The alert will be titled with the calling extension’s name, and the provided `message` will be displayed as the alert body. This method is similar to `showInformativeMessage` except it includes additional UI indications that the message indicates an error, and may bring the workspace’s window to the foreground. */ 3433 | showErrorMessage(message: string): void 3434 | 3435 | /** 3436 | * Displays a file chooser panel to the user. The panel will be titled with the calling extension’s name, and the provided `message` will be displayed as the panel body. 3437 | * 3438 | * File chooser panels show a standard macOS open panel to request file(s) and folder(s) be selected by the user. 3439 | * 3440 | * The optional `callback` argument should be a callable, which will be invoked when the user dismisses the panel. The callback will be passed an array of paths chosen, or `null` if the alert was cancelled. 3441 | */ 3442 | showFileChooser(message: string, options?: { 3443 | /** Text to display instead for the “OK” button. */ 3444 | prompt?: string 3445 | 3446 | /** Whether the user may choose files. */ 3447 | allowFiles?: boolean 3448 | 3449 | /** Whether the user may choose folders. */ 3450 | allowFolders?: boolean 3451 | 3452 | /** Whether the user may choose multiple files. */ 3453 | allowMultiple?: boolean 3454 | 3455 | /** The file types allowed, as an array of strings. Types may be file extensions or uniform type identifiers. */ 3456 | filetype?: string[] 3457 | 3458 | /** Whether to return paths to the caller which are relative to the workspace. */ 3459 | relative?: boolean 3460 | }, callback?: (paths: string[] | null) => void): void 3461 | 3462 | /** Displays an informative message to the user as an alert. The alert will be titled with the calling extension’s name, and the provided `message` will be displayed as the alert body. */ 3463 | showInformativeMessage(message: string): void 3464 | 3465 | /** 3466 | * Displays an input palette to the user (in the style of the command palette). The provided `message` will be displayed as the palette’s descriptive text. 3467 | * 3468 | * Input palettes include a single text field to ask user for a value. 3469 | * 3470 | * The optional `callback` argument should be a callable, which will be invoked when the user confirms with the Return key. The callback will be passed the value provided by the user (as a `String`), or `null` if the palette was cancelled. 3471 | */ 3472 | showInputPalette(message: string, options?: { 3473 | /** Text to display if no value is present. */ 3474 | placeholder?: string 3475 | 3476 | /** 3477 | * Text with which to pre-fill the palette. 3478 | * @since 4.0 3479 | */ 3480 | value?: string 3481 | }, callback?: (value: string | null) => void): void 3482 | 3483 | /** 3484 | * Displays an input panel to the user (in the style of a modal sheet). The panel will be titled with the calling extension’s name, and the provided `message` will be displayed as the panel body. 3485 | * 3486 | * Input panels include a single text field to ask user for a value, as well as two buttons (“Cancel” and “OK”). 3487 | * 3488 | * The optional `callback` argument should be a callable, which will be invoked when the user chooses a button in the alert. The callback will be passed the value provided by the user (as a `String`), or `null` if the alert was cancelled. 3489 | */ 3490 | showInputPanel(message: string, options?: { 3491 | /** Label to display before the input field. */ 3492 | label?: string 3493 | 3494 | /** Text to display if no value is present. */ 3495 | placeholder?: string 3496 | 3497 | /** Default value to display. */ 3498 | value?: string 3499 | 3500 | /** Text to display instead for the “OK” button. */ 3501 | prompt?: string 3502 | 3503 | /** Whether the field should be “secure” (display its value using dots). */ 3504 | secure?: boolean 3505 | }, callback?: (value: string | null) => void): void 3506 | 3507 | /** Displays a warning message to the user as an alert. The alert will be titled with the calling extension’s name, and the provided `message` will be displayed as the alert body. This method is similar to `showInformativeMessage` except it includes additional UI indications that the message indicates a warning, and may bring the workspace’s window to the foreground. */ 3508 | showWarningMessage(message: string): void 3509 | } 3510 | --------------------------------------------------------------------------------