Giter Site home page Giter Site logo

xlboy / nvim-chainsaw Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chrisgrieser/nvim-chainsaw

0.0 0.0 0.0 28 KB

Speed up log creation. Creates various kinds of language-specific log statements, like logs of variables, assertions, or time-measuring.

License: MIT License

JavaScript 3.14% Lua 96.86%

nvim-chainsaw's Introduction

nvim-chainsaw ๐Ÿชš

badge

Speed up log creation. Creates various kinds of language-specific log statements, like logs of variables, assertions, or time-measuring.

demo.mp4

Installation

-- lazy.nvim
{ "chrisgrieser/nvim-chainsaw" },

-- packer
use { "chrisgrieser/nvim-chainsaw" }

Built-in language support

  • JavaScript / TypeScript / TypeScriptReact
  • Lua
  • Python
  • Shell
  • AppleScript
  • CSS / SCSS

Not every language supports every type of log statement. For details on what is supported, see log-statements-data.lua.

Note

In languages like CSS with no log statements, nvim-chainsaw simply uses similar statements with debugging purposes, such as outline: 2px solid red !important; to quickly assess whether a selector is correct or not.

Usage

The plugin offers various types of log statements. Bind keymaps for the ones you want to use.

-- create log statement, and position the cursor to enter a message
require("chainsaw").messageLog()

-- log the name and value of the a variable
-- normal mode: treesitter node or word under cursor, visual mode: selection
require("chainsaw").variableLog()

-- like variableLog, but with syntax specific to inspect an object, such as
-- `console.log(JSON.stringify(foobar))` in javascript
require("chainsaw").objectLog()

-- assertion statement
require("chainsaw").assertLog()

-- Minimal log statement, with a random emoji for differentiation. Indented for
-- use in structures like if/else, to quickly glance whether a condition was
-- triggered or not. (Inspired by AppleScript's `beep` command.)
require("chainsaw").beepLog()

-- 1. call adds a statement that measures the time
-- 2. call adds a statement that logs the time since
require("chainsaw").timeLog()

-- debug statements like `debugger` in javascript or `breakpoint()` in python
require("chainsaw").debugLog()

-- remove all log statements created by chainsaw
require("chainsaw").removeLogs()

Configuration

-- default settings
require("chainsaw").setup ({
	-- The marker should be a unique string, since `.removeLogs()` will remove
	-- any line with it. Emojis or strings like "[Chainsaw]" are recommended.
	marker = "๐Ÿชš",
	-- emojis used for `.beepLog()`
	beepEmojis = { "๐Ÿค–", "๐Ÿ‘ฝ", "๐Ÿ‘พ", "๐Ÿ’ฃ" },
})

Add your own log statements

Custom log statements are added in the setup() call. The values are formatter lua strings, meaning %s is a placeholder that is dynamically replaced with the actual value. See log-statements-data.lua for examples.

PRs adding log statements for more languages are welcome.

require("chainsaw").setup ({
	logStatements = {
		messageLog = {
			javascript = 'console.log("%s ");',
			otherFiletype = โ€ฆ -- <-- add the statement for your filetype here
		},
		variableLog = {
			javascript = 'console.log("%s %s:", %s);',
			otherFiletype = โ€ฆ -- <-- add the statement for your filetype here
		},
		-- the same way for the other statement types
	},
})

Credits

About Me
In my day job, I am a sociologist studying the social mechanisms underlying the digital economy. For my PhD project, I investigate the governance of the app economy and how software ecosystems manage the tension between innovation and compatibility. If you are interested in this subject, feel free to get in touch.

Blog
I also occasionally blog about vim: Nano Tips for Vim

Profiles

Buy Me a Coffee at ko-fi.com

nvim-chainsaw's People

Contributors

chrisgrieser avatar vbenny42 avatar xlboy 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.