Skip to content

Commit

Permalink
Feature/v2.0 (#8)
Browse files Browse the repository at this point in the history
* Add tree-sitter support

* Add additional test cases

* Eldev for github actions

* More tests

* Java/c#/lua/elisp/ruby/rust support

* Teleport to new locations from tree-sitter node

* More flexible format of configurations

* Templates for log message formatters 

* Defcustom instead of defvar
  • Loading branch information
Artawower authored Jan 8, 2022
1 parent e98f12b commit 76c105c
Show file tree
Hide file tree
Showing 12 changed files with 902 additions and 607 deletions.
61 changes: 33 additions & 28 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
name: check
name: CI

on:
pull_request:
push:
branches:
- master
- "feature/*"
paths-ignore: ['**.md', '**.adoc']
pull_request:
paths-ignore: ['**.md', '**.adoc']

jobs:
check:
test:
runs-on: ubuntu-latest
continue-on-error: ${{matrix.emacs_version == 'snapshot'}}

strategy:
fail-fast: false
matrix:
emacs_version:
- 26.1
- 26.2
- 26.3
ignore_warnings:
- true
include:
- emacs_version: snapshot
ignore_warnings: false
emacs_version: ['25.1', '25.2', '25.3',
'26.1', '26.2', '26.3',
'27.1', '27.2',
'snapshot']

steps:
- uses: actions/checkout@v2
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.emacs_version }}
- uses: leotaku/elisp-check@master
with:
file: turbo-log.el
ignore_warnings: ${{ matrix.ignore_warnings }}
- uses: leotaku/elisp-check@master
with:
check: ert
file: test.el
- name: Set up Emacs
uses: purcell/setup-emacs@master
with:
version: ${{matrix.emacs_version}}

- name: Install Eldev
run: curl -fsSL https://raw.github.com/doublep/eldev/master/webinstall/github-eldev | sh

- name: Check out the source code
uses: actions/checkout@v2

- name: Install node js for tree-sitter
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install tree-sitter
run: npm install -g [email protected]
- name: Test the project
run: |
eldev prepare && eldev -p -dtT -C test
eldev prepare && eldev -p -dtT -C compile --warnings-as-errors turbo-log.el
6 changes: 6 additions & 0 deletions Eldev
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; -*- mode: emacs-lisp; lexical-binding: t -*-

;; Autodetermined by `eldev init'.
(eldev-use-package-archive 'melpa)
(eldev-add-extra-dependencies 'test 'typescript-mode)
(eldev-add-extra-dependencies 'test 'tree-sitter-langs)
98 changes: 62 additions & 36 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
[[https://github.com/Artawower/turbo-log/actions][https://github.com/artawower/turbo-log/actions/workflows/lint.yml/badge.svg]] [[https://wakatime.com/badge/github/Artawower/turbo-log.svg]]

* Turbo log - fast logging selected line or region
This project inspired by similar package for [[https://marketplace.visualstudio.com/items?itemName=ChakrounAnas.turbo-console-log][vs-code - turbo-console-log]], and provided functionality for fast log message inserting under current line.
This project inspired by a similar package for [[https://marketplace.visualstudio.com/items?itemName=ChakrounAnas.turbo-console-log][vs-code - turbo-console-log]], and provides functionality for fast log message inserting under current line.
It works for *js-mode, typescript-mode, go-mode and python*.
** How it works?
[[./images/sample.gif]]
** Requirements
[[https://github.com/emacs-tree-sitter/elisp-tree-sitter][tree-sitter]] is required for correct work.

#+BEGIN_SRC emacs-lisp
(use-package tree-sitter-langs
:ensure t
:defer t)

(use-package tree-sitter
:ensure t
:after tree-sitter-langs)
#+END_SRC

** Installation
*** quelpa
#+BEGIN_SRC emacs-lisp
(use-packa)
(use-package turbo-log
:quelpa (turbo-log :fetcher github :repo "artawower/turbo-log.el")
:bind (("C-s-l" . turbo-log-print)
Expand All @@ -18,7 +32,8 @@ It works for *js-mode, typescript-mode, go-mode and python*.
("C-s-]" . turbo-log-paste-as-logger-immediately)
("C-s-d" . turbo-log-delete-all-logs))
:config
(setq turbo-console--prefix "✰"))
(setq turbo-log-msg-format-template "\"🚀: %s\"")
(setq turbo-log-allow-insert-without-tree-sitter-p t))
#+END_SRC
*** doom
#+BEGIN_SRC emacs-lisp
Expand All @@ -34,48 +49,59 @@ It works for *js-mode, typescript-mode, go-mode and python*.
("C-s-]" . turbo-log-paste-as-logger-immediately)
("C-s-x" . turbo-log-delete-all-logs))
:config
(setq turbo-console--prefix "✰"))
(setq turbo-log-msg-format-template "\"🚀: %s\"")
(setq turbo-log-allow-insert-without-tree-sitter-p t))
#+END_SRC

** Customization
*** Common configs
- =turbo-log-prefix= Special prefix, will put [line number][buffer-name?] <here>
- =turbo-log--include-buffer-name= If true will put buffer name to log message
- You can use multiple logger with choice.
=turbo-log-msg-format-template= - template for entire part inside logger

#+BEGIN_SRC emacs-lisp
(setq turbo-log--ecmascript-loggers '("console.log" "console.debug" "console.error"))
#+END_SRC
There are available to customization loggers lists:
=turbo-log-payload-format-template= - template for payload part (selected region or implicite extracted identifier)

=turbo-log-line-number-format-template= - optional template for formatting line number, when not provided, the line number will not be inserted

=turbo-log-buffer-name-format-template= - template for file name inserting

=turbo-log--python-loggers=
=turbo-log--ecmascript-loggers=
=turbo-log--golang-loggers=
=turbo-log-argument-divider= - divider for arguments (in most case it's a comma)

=turbo-log-allow-insert-without-tree-sitter-p= - allow to insert logs without tree-sitter (in such case logger will be inserted next line only, also its a necessary for modes without tree-sitter support)
#+END_SRC
*** Language specific configs
=turbo-log-loggers= - its a most interesting part of your config. You can use every settings as plist for specific logger (without =turbo-log= prefix), for example:

*** Language specific configs:
Disable semicolon for ecmascript
#+BEGIN_SRC emacs-lisp
(plist-put turbo-log--ecmascript-configs :include-semicolon nil)
(setcdr (assq 'typescript-mode turbo-log-loggers)
'(:loggers ("console.log(%s)" "console.debug(%s)" "console.warn(%s)")
:jump-list ((class_declaration (method_definition "constructor")))
:msg-format-template "'TCL: %s'"
:identifier-node-types (identifier member_expression))
:post-insert-hook (prettier-prettify))
#+END_SRC

Where:

=loggers= - list of available loggers, when there are more then 1 =turbo-log-print= will ask to choose logger.

=jump-list= - internal command for insert current logger to specific line number by determined node type. Its a alist that consist of cons where car is node type and cdr is a alist of inserting position and optional name of foud node type, after which logger will be inserted.

=identifier-node-types= - optional alist of node types for extracting identifiers

=post-insert-hook= - list of hooks that will be triggered after logger inserted. Its a good place to call =format-all-buffer= or =prettier-prettify= methods.


** Tested languages
+ [X] Python
+ [X] Golang
+ [X] Javascript
+ [X] Typescript
+ [X] Java
+ [X] C#
+ [X] Rust
+ [-] Lua (Without tree-sitter)
+ [-] Elisp (Without tree-sitter)
+ [ ] C++

** Plans [15/19]
+ [X] Typescript support
+ [X] Javascript support
+ [X] Python support
+ [X] Golang support
+ [X] Add support for multiple logger
+ [X] Add additional function for print only first logger from list.
+ [X] Add support for ecmascript functions without body like =function func() { }=
+ [X] Improve insert position finding for ecmascript
+ [X] Improve insert position finding for golang
+ [X] Improve space/tab count calculation before inserted line. Use ==newline-and-indent==
+ [X] Change custom comment setter to built in "comment region" func.
+ [X] Comment/uncomment all log messages that were made by package.
+ [X] Remove all log messages that were made by package.
+ [X] Add line break for long lines (ecmascript)
+ [ ] Add loggers as template
+ [ ] Universal logger for other languages without additional logic
+ [ ] Add log moving before if statement
+ [ ] Refactor code.
+ [X] Paste variable inside logger!
** Contributing
Any contribution is greatly appreciated!
Run =eldev test=, =checkdoc= and =package-lint-current-buffer= (from [[https://github.com/purcell/package-lint][package-lint]] ) before creating the pull request
34 changes: 34 additions & 0 deletions miscellaneous/test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
public class IteratorWithoutLocalExample
{
public static void Main()
{
IEnumerable<int> xs = OddSequence(50, 110);

foreach (var x in xs) // line 11
{
Console.Write($"{x} ");
}
}

public static IEnumerable<int> OddSequence(int start, int end)
{


string[] cars = {"Volvo",
"BMW",
"Ford", "Mazda"};

if (start < 0 || start > 99)
throw new ArgumentOutOfRangeException(nameof(start), "start must be between 0 and 99.");
if (end > 100)
throw new ArgumentOutOfRangeException(nameof(end), "end must be less than or equal to 100.");
if (start >= end)
throw new ArgumentException("start must be less than end.");

for (int i = start; i <= end; i++)
{
if (i % 2 == 1)
yield return i;
}
}
}
39 changes: 39 additions & 0 deletions miscellaneous/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"fmt"
)

const myConst = "Whatever your want"

func main() {
myVar := "variable"

b := 12
fmt.Println("This print will not be comment")
}

func test(bath int) {
if bath == 0 {}
return 2
}

func realyBingFunctionWithAlotArgs(
ke int,
be string,
anotherBigArguments *[]int,
another string,
) {
a := 12
b := "qwe"
bigArray := []int{
1, 2, 3,
4, 5, 6,
7, 9, 10,
}
fmt.Println("TCL: [line 34][test.go] bigArray: ", bigArray)

const { b, c } = {c: 2, b: 1}
}

func findUserById(func(string) *User) {}
8 changes: 8 additions & 0 deletions miscellaneous/test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Simple{
public static void main(String args[]){

int[] intArray = new int[]{ 1,2,3,
4,5,6,
7,8,9,10 };
}
}
7 changes: 7 additions & 0 deletions miscellaneous/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function fact (n)
if n == 0 then
return 1
else
return n * fact(n-1)
end
end
19 changes: 19 additions & 0 deletions miscellaneous/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class TestClass:
def test(self):
hello_world = "Hello world"
another_var = 12
result = f"{hello_world} {another_var}"
return hello_world

def test2(
self,
a,
b,
):
hello_world = "Hello world"
another_var = 12
b = [1, 2, 3, 4, 5, 6, 7, 8, 9]
result = f"{hello_world} {another_var}"

# print("[line 7][test.py] TCL: hello_world: ", hello_world)
return hello_world
9 changes: 9 additions & 0 deletions miscellaneous/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def AddNum(num1,
num2)
add = num1 + num2;
print "Addition is: ",add;
if add > 2
print "more then 2!";
end
return add;
end
53 changes: 53 additions & 0 deletions miscellaneous/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class TestClass {
private t: any;
private b: string;
private myAnotherVariable: any;

constructor(t: any, b: string, myAnotherVariable: number) {
this.t = t;
this.b = b;
this.myAnowtherVariable = myAnotherVariable;
console.log(
"This message will not be comment, cause it made by programmers."
);
}
}

function myFuncWithEmptyBody(qwwe) {}

function test(): string {
const hello = "Hello";
return hello;
}

function testFuncWithBigSignature(
name: string,
age: number,
patronymic?: string
): string {
return `${name} is ${age} years old. ${patronymic}`;
}

function test() {
const foo = 1;
const bar = 2;
const b = [1, 2, 3, 10, 12, 22, 33, 44, 15];

const a = 4;
if ((a = 1)) {
}

for (let b = 0; b < 4; b++) {}
}

const a = () => ({});

function test() {
const foo = 1;

const bar = 2;
}

const a = (k) => {
const b = k;
};
Loading

0 comments on commit 76c105c

Please sign in to comment.