From 820d73f3452e59ad732224273f8c016f869c6d03 Mon Sep 17 00:00:00 2001 From: Anton Myasnikov Date: Tue, 11 Aug 2020 13:31:22 +0300 Subject: [PATCH] [LIGO-25] Chores (add Makefile, scripts, vendor, stylish) Problem: We need to add stylish config to settle code style for our project. Makefile to simplify its building. Also we need to check our project for trailing whitespaces so we need to add the corresponding script to be used later in CI. Solution: Add - stylish-haskell config - Makefile - `check_trailing_whitespace` script --- tools/lsp/README.md | 4 +- tools/lsp/squirrel/.stylish-haskell.yaml | 66 +++++++++++++++++++ tools/lsp/squirrel/Makefile | 30 +++++++++ tools/lsp/squirrel/package.yaml | 10 ++- .../scripts/check-trailing-whitespace.sh | 14 ++++ 5 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 tools/lsp/squirrel/.stylish-haskell.yaml create mode 100644 tools/lsp/squirrel/Makefile create mode 100755 tools/lsp/squirrel/scripts/check-trailing-whitespace.sh diff --git a/tools/lsp/README.md b/tools/lsp/README.md index add4e53d3..afecb5ac8 100644 --- a/tools/lsp/README.md +++ b/tools/lsp/README.md @@ -20,8 +20,8 @@ Right now only one parser is linked there; the name of symlink should be changed in future. Server part invokes the TS-parser and then constructs a tree of haskell datatypes -from the TS-tree. Then it is fed into `AST.Parser` (name will be changed), which -constructs an universal AST from the tree of the respective language. +from the TS-tree. Then it is fed into `LIGO.Parser` (name will be changed), which +constructs an universal LIGO from the tree of the respective language. Parser uses the root `Parser` module which provides the combinators and monad to deal with `ParseTree`, produced from TS output. diff --git a/tools/lsp/squirrel/.stylish-haskell.yaml b/tools/lsp/squirrel/.stylish-haskell.yaml new file mode 100644 index 000000000..4ed34c4d9 --- /dev/null +++ b/tools/lsp/squirrel/.stylish-haskell.yaml @@ -0,0 +1,66 @@ +# SPDX-FileCopyrightText: 2019 Serokell +# +# SPDX-License-Identifier: Unlicense + +# Default stylish-haskell config used in Serokell. + +steps: + - simple_align: + cases: false + top_level_patterns: false + records: false + - imports: + align: none + list_align: after_alias + pad_module_names: false + long_list_align: new_line + empty_list_align: inherit + list_padding: 2 + separate_lists: true + space_surround: false + - language_pragmas: + style: compact + remove_redundant: true + - trailing_whitespace: {} +columns: 100 +newline: native +language_extensions: + - BangPatterns + - BlockArguments + - ConstraintKinds + - DataKinds + - DefaultSignatures + - DeriveAnyClass + - DeriveDataTypeable + - DeriveGeneric + - DerivingStrategies + - DerivingVia + - EmptyCase + - ExistentialQuantification + - ExplicitNamespaces + - FlexibleContexts + - FlexibleInstances + - FunctionalDependencies + - GADTs + - GeneralizedNewtypeDeriving + - LambdaCase + - MultiParamTypeClasses + - MultiWayIf + - NamedFieldPuns + - NoImplicitPrelude + - OverloadedLabels + - OverloadedStrings + - PatternSynonyms + - RebindableSyntax + - RecordWildCards + - RecursiveDo + - ScopedTypeVariables + - StandaloneDeriving + - TemplateHaskell + - TemplateHaskellQuotes + - TupleSections + - TypeApplications + - TypeFamilies + - TypeOperators + - ViewPatterns + - QuasiQuotes diff --git a/tools/lsp/squirrel/Makefile b/tools/lsp/squirrel/Makefile new file mode 100644 index 000000000..2c9703b6c --- /dev/null +++ b/tools/lsp/squirrel/Makefile @@ -0,0 +1,30 @@ +SITTER ?= tree-sitter + +DIRS := grammar/pascaligo grammar/reasonligo grammar/camligo + +PACKAGE := squirrel + +STACK_DEV_OPTIONS = --fast --ghc-options -Wwarn --file-watch + +.DEFAULT_GOAL := all + +all: build + +FORCE: + +generate: $(DIRS) + +$(DIRS): FORCE + # $(SITTER) generate # Generation is manual for now + mkdir -p $(PACKAGE)/vendor/$@ + cp $@/src/parser.c vendor/$@/parser.c + cp -r $@/src/tree_sitter vendor/$@/tree_sitter + +clean: + $(RM) vendor/* + stack clean + +build: + stack build $(STACK_DEV_OPTIONS) + +.PHONY: all clean generate build FORCE diff --git a/tools/lsp/squirrel/package.yaml b/tools/lsp/squirrel/package.yaml index 6ff6e9187..62f14f251 100644 --- a/tools/lsp/squirrel/package.yaml +++ b/tools/lsp/squirrel/package.yaml @@ -57,10 +57,12 @@ library: - src/ include-dirs: - - vendor + - vendor/pascaligo + - vendor/reasonligo c-sources: - - vendor/parser.c + - vendor/pascaligo/parser.c + - vendor/reasonligo/parser.c executables: squirrel: @@ -77,4 +79,6 @@ executables: source-dirs: - app/ - ghc-options: -threaded + ghc-options: + - -threaded + - -Wall diff --git a/tools/lsp/squirrel/scripts/check-trailing-whitespace.sh b/tools/lsp/squirrel/scripts/check-trailing-whitespace.sh new file mode 100755 index 000000000..f62112ccd --- /dev/null +++ b/tools/lsp/squirrel/scripts/check-trailing-whitespace.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# SPDX-FileCopyrightText: 2020 Tocqueville Group +# +# SPDX-License-Identifier: LicenseRef-MIT-TQ + +files=$(git ls-files | xargs grep --files-with-matches --binary-files=without-match '[[:blank:]]$') +if [[ -n $files ]];then + echo ' Files with trailing whitespace found:' + for f in "${files[@]}"; do + echo " * $f" + done + exit 1 +fi