Git Product home page Git Product logo

wtf.nvim's Introduction

๐Ÿคฏ wtf.nvim

A Neovim plugin to help you work out what the fudge that diagnostic means and how to fix it!

wtf.nvim provides faster and more efficient ways of working with the buffer line's diagnostic messages by redirecting them to your favourite resources straight from Neovim.

Works with any language that has LSP support in Neovim.

โœจ Features

AI powered diagnostic debugging

Use the power of ChatGPT to provide you with explanations and solutions for how to fix diagnostics, custom tailored to the code responsible for them.

Wtf.mp4

Search the web for answers

Why spend time copying and pasting, or worse yet, typing out diagnostic messages, when you can open a search for them in Google, Stack Overflow and more, directly from Neovim?

wtf-search.mp4

๐Ÿ”ฉ Installation

In order to use the AI functionality, set the environment variable OPENAI_API_KEY to your openai api key (the search functionality will still work without it).

Install the plugin with your preferred package manager:

-- Packer
use({
  "piersolenski/wtf.nvim",
    config = function()
      require("wtf").setup()
    end,
    requires = {
      "MunifTanjim/nui.nvim",
    }
})

-- Lazy
{
	"piersolenski/wtf.nvim",
	dependencies = {
		"MunifTanjim/nui.nvim",
	},
  	opts = {},
	keys = {
		{
			"gw",
			mode = { "n", "x" },
			function()
				require("wtf").ai()
			end,
			desc = "Debug diagnostic with AI",
		},
		{
			mode = { "n" },
			"gW",
			function()
				require("wtf").search()
			end,
			desc = "Search diagnostic with Google",
		},
	},
}

โš™๏ธ Configuration

{
    -- Default AI popup type
    popup_type = "popup" | "horizontal" | "vertical",
    -- An alternative way to set your API key
    openai_api_key = "sk-xxxxxxxxxxxxxx",
    -- ChatGPT Model
    openai_model_id = "gpt-3.5-turbo",
    -- Send code as well as diagnostics
    context = true,
    -- Set your preferred language for the response
    language = "english",
    -- Any additional instructions
    additional_instructions = "Start the reply with 'OH HAI THERE'",
    -- Default search engine, can be overridden by passing an option to WtfSeatch
    search_engine = "google" | "duck_duck_go" | "stack_overflow" | "github",
    -- Callbacks
    hooks = {
        request_started = nil,
        request_finished = nil,
    },
    -- Add custom colours
    winhighlight = "Normal:Normal,FloatBorder:FloatBorder",
}

๐Ÿš€ Usage

wtf.nvim works by sending the line's diagnostic messages along with contextual information (such as the offending code, file type and severity level) to various sources you can configure.

To use it, whenever you have an hint, warning or error in an LSP enabled environment, invoke one of the commands:

Command Modes Description
:Wtf [additional_instructions] Normal, Visual Sends the diagnostic messages for a line or visual range to ChatGPT, along with the code if the context has been set to true. Additional instructions can also be specified, which might be useful if you want to refine the response further.
:WtfSearch [search_engine] Normal Uses a search engine (defaults to the one in the setup or Google if not provided) to search for the first diagnostic. It will attempt to filter out unrelated strings specific to your local environment, such as file paths, for broader results.

Custom status hooks

You can add custom hooks to update your status line or other UI elements, for example, this code updates the status line colour to yellow whilst the request is in progress.

hooks = {
    request_started = function()
        vim.cmd("hi StatusLine ctermbg=NONE ctermfg=yellow")
    end,
    request_finished = vim.schedule_wrap(function()
        vim.cmd("hi StatusLine ctermbg=NONE ctermfg=NONE")
    end),
},

Lualine Status Component

There is a helper function get_status so that you can add a status component to lualine.

local wtf = require("wtf")

require('lualine').setup({
    sections = {
        lualine_x = { wtf.get_status },
    }
})

๐Ÿ’ก Inspiration

wtf.nvim's People

Contributors

piersolenski avatar razak17 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.