Code Monkey home page Code Monkey logo

language-haskell's Introduction

Haskell Syntax Highlighting Support

Syntax highlighting support for Haskell and associated languages (e.g. Cabal, Happy and Alex) in Visual Studio Code.

Syntax highlighting

Adds syntax highlighting support for Haskell (.hs and .lhs). This is a (now heavily) modified version of the syntax file from the Haskell TextMate bundle. Additionally there is support for Cabal files (.cabal) via a concoction of my own.

Also adds automatic indentation after where, do, -> etc. and surrounding brackets ([], {} etc)

Screenshot Haskell

Screenshot Cabal

Bugs

If you happen to notice bugs or have suggestions for improvements visit the issue section of the repository.

Themes

This extension provides TextMate scopes for use in syntax highlighting, but the colours displayed depend on the theme being used. Unfortunately many themes have incomplete support for the different TextMate scopes, and as a result different tokens can end up with identical colours.

For a theme that supports all the scopes provided by this extension, see the Groovy Lambda theme.

Theme authors

I recently realized that I am woefully unaware of whether there are any themes with Haskell-specific rules and how changes to this extension affect such themes. If you are a theme author that wishes to use Haskell specific rules, or are aware of a theme with Haskell specific rules, feel free to get in touch.

With version 3.0.0 some new tm scopes were added, such that now record and GADT definitions can be distinguished. Let me know if there are any questions about the scope assignment in this extension or if there are further scope assigments you'd like to see added.

We now publish an automatically generated, complete list of the textmate scopes used in our grammars. You can find the lists of scopes in the scope-lists directory.

Contributing

This project currently uses the YAML-tmLanguage format for language grammars (Haskell, Cabal, alex, happy, ...). The grammars can be found in the syntaxes directory. To generate JSON grammars (which is the format VS Code expects), we use the Node package js-yaml (requires npx in PATH):

npx js-yaml haskell.YAML-tmLanguage > haskell.json

For testing, we use the Node package vscode-tmgrammar-test. For instance, to generate/check the scopes of a Haskell source file, run:

npx vscode-tmgrammar-test "-s" "source.haskell" "-g" "syntaxes/haskell.json" "-t" "myTestFile.hs"

To run the test-suite, simply call make test. This will build the grammar files and run vscode-tmgrammar-test on all the files in the testsuite.

language-haskell's People

Contributors

alanz avatar arkrost avatar boringcactus avatar dsifford avatar edmundnoble avatar georgefst avatar glebec avatar hajinko avatar jbugman avatar justusadam avatar lemourin avatar maqqr avatar martoon-00 avatar masonicboom avatar matthewess avatar miguel-fontes avatar mixphix avatar mpilgrem avatar noughtmare avatar nsmaciej avatar porges avatar ranjitjhala avatar robrix avatar scott-fleischman avatar sheaf avatar sjorn3 avatar takenobu-hs avatar tchajed avatar vigilans avatar zjhmale avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

language-haskell's Issues

Qualified infix functions incorrectly highlighted

screen shot 2017-06-26 at 11 00 53

Sorry for making so many issues, I just started using vscode and I'm just reporting things as I come across them. I can collect them into a single issue in future if you would prefer, since they are all very minor issues.

Incorrect Highlighting For Multiple Line Type Signatures

Thanks for awesome plugin!

I wrote haskell codes such as:

dbPageWrapper :: (DashBoardPage p, Monad m) =>
  T.Text -> p -> HtmlT m a -> HtmlT m b -> HtmlT m b -- disable type highlighting
dbPageWrapper pref page headerC mainC = do
  ...

Then, I noticed missing syntax.

I use GHC 7.10.3. Probably, because building is passed, this is legal syntax.

module' ("module" then a "prime" symbol) is incorrectly highlight as a keyword

The identifier module' triggers the syntax highlighting associated with the normal module keyword, even though the inclusion of the prime/single-quote symbol should turn it into an ordinary, non-reserved identifier. Importantly, all text after the identifier module' is highlighted as though it were part of a module declaration, which can seriously break syntax highlighting on large parts of valid source files.

Here's an example of the incorrect syntax highlighting for the identifier module':

screenshot from 2017-06-26 15-54-41

And an example of correct syntax highlighting for the identifier module_:

screenshot from 2017-06-26 15-56-28

Missing keywords: data and type families, pattern synonyms, deriving via

Here are some examples of missing keywords:

the keywords "family", "instance" and "where" in type/data families, e.g.:
type family
open_type_family

"via" from the deriving via extension:
deriving_via_keyword
(Note also that the type variable in the standalone deriving declaration is not highlighted correctly.)

"pattern" for a pattern synonym declaration
pattern_synonyms

Incorrect substitutions

Having tough time using it under visual studio code. It randomly inserts this string at places:

<no location info>: Expected a span: "<module-name/filepath>" <start line> <start column> <end line> <end column> "<sample string>"

Removing it and correcting the code slows me down heavily. Wondering if I am not setup right?

Getting rid of the snippets

Users can define their own snippets of code easily in VSCode, so I think the provided snippets are not needed. I personally don't use all of them and so they are mostly just annoyingly appearing, because there is no way to turn them off.

Incorrect markup in class definition head

Signatures in the class definition head are highlighted differently than in the instance declaration head and other general type signatures.

I believe this should be changed and unified.

Stop indentation after two newlines (or don't indent after `module ... where`)

Not entirely sure indentation rules are specified in the syntax packages, so just ignore this if that's not the case.

I find that I often wrestle with the automatic indentation, especially after where blocks. For example, pasting in Haskell code, will automatically indent everything after the module ... where in the top, which is not really intended. Take e.g.

module Main where

import Primes

main = putStrLn $ "The 101st prime is " ++ show (primes !! 100)

which becomes (when pasted),

module Main where

  import Primes

  main = putStrLn $ "The 101st prime is " ++ show (primes !! 100)

It would be great if one could either disable the indentation for module ... where specifically, or better yet have the behaviour of resetting indentation after two blank lines in a row.

Is this even possible in VS Code?

Incorrect comments in literate Haskell files

When making automatic line comments inside of a literate file, the Haskell comments are used, but should be the latex style comments (in my case).

> main = do

becomes

-- > main = do

rather than

% > main = do

Am I just doing something wrong? Let me know.

Literate Haskell

Hi JustusAdam!

Do you have any useful background about what's happening with Literate Haskell syntax?

I've just cloned your repo and looking forward to take a shot at this issue. I'm still getting my head into vscode extension development and it will be my first contact with textmate syntax definitions so, no warrants included.

Thank you!

autoClosing for single quotes

I'm not sure this should be in haskell-configuration.json as although single quotes are used for literals, they're more often used as primes and data kind ticks.

Having to constantly delete the second prime is annoying.

Add support for *.tidal files

.tidal is the standard extension for TidalCycles files. These are basically just a scratchpad containing Haskell expressions. You can then use the vscode-tidalcycles extension to feed these expressions into GHCi.

To get syntax highlighting at the moment, one has to associate *.tidal files with the Haskell filetype, but this causes other extensions like haskell-lsp to go a bit nuts because they expect the files to be valid Haskell modules.

P.S. If you think it is better to put this in its own extension I'll do that.

Proposal:

"languages": [
            ...
            {
                "id": "tidal",
                "aliases": [
                    "Tidal",
                    "tidal"
                ],
                "extensions": [
                    ".tidal"
                ],
                "configuration": "./haskell-configuration.json"
            }
],

Incorrect Highlighting For Comments In Module Declaration

module Main
  (
    -- * main func  <- disable highlighting
    main
    {- | disable, too
    -}
  ) where

-- enable comment highlighting

I think this is a miss. However, there are not supported services such as GitHub.
So, possibly, this issue is not needed.

This issue seems to be caused by textmate bundle, too.
Should I open an issue there?

Incorrect highlighting for multi-line signatures.

Hello,

First of all, thanks a lot for all your work on the plugin.
I have an issue with multi-line signatures (as formatted by Brittany).
The rendering of types in lines 2..n of the signature is not consistent with line 1 (it looks like constructors rather than types).

See, eg,

capture d ecran 2018-06-30 a 22 39 39

vs (expected)

capture d ecran 2018-06-30 a 22 50 16

This could possibly be linked to #1.
Nb: I have seen also #27.

I am using:

  • VSC 1.24.1
  • Haskell Syntax 2.5.0 (but in the Changelog in VSC I see 3.0.0)
  • Haskell Language Server 0.0.19
  • HIE 0.2.0.0

Confusing syntax highlighting

The purpose of syntax highlighting is in my opinion to tell different type of constructs apart. It would be great to tell these apart by color:

  • Types .... e.g. Int, Text, IO a
  • Keywords .... e.g let, otherwise, ::, ->
  • Primitives .... e.g. 5, "String"
  • Data constructors .... e.g. Right, Just
  • Function declaration, arguments
  • Control characters .... e.g. (,), `

But right now, there are:

  • Distinctions between Prelude/Non-Prelude which are useless in my opinion (they also don't hold if there is a custom prelude)
  • Prelude functions have the same color as function declarations
  • 3 different color for types (Bold, Thin Green, Thin Red).

screen

I find the highlighting confusing at the moment. What do you think?

btw. this is not just the theme I'm using, most other themes behave like that

Parsing confused by type-level string (Symbol)

The following code snippet is parsed incorrectly. The last two lines for main are completely unhighlighted in the vscode editor. The problem goes away if "of" is changed to "f". I'm running language-haskell 2.4.0 on vscode 1.19.0 with ghc 8.2.2.

{-# LANGUAGE DataKinds, FlexibleInstances, KindSignatures, MultiParamTypeClasses, FunctionalDependencies #-}

import GHC.TypeLits

data Label (l :: Symbol) = Get

class Has a l b | a l -> b where
  from :: a -> Label l -> b

data Point = Point Int Int deriving Show

instance Has Point "of" Int where from (Point x _) _ = x

example = from (Point 1 2) (Get :: Label "of")

main :: IO ()
main = undefined

QuasiQuotes

They can mean just about anything so their contents should be treated either as plain text or a string literal.

There is a list of reserved names for quotes that should remain as Haskell code.

Variable names ending with apostrophe (') are not highlighted correctly when variable name is also a keyword

Some code I am working in is using a function called module', but this severely messes up the syntax highlighting.

image

The reason is that all keywords in the grammar file is using \b to detect whole words. As I gather it, the \b will match any \w up until \W, where \w is a shorthand for [a-zA-Z0-9_] and \W is anything but \w. This is in conflict with Haskell's syntax, which actually allows any variable definition to end with '. I did a quick hack where I replaced the ending \b for the module-keyword with the following non-capturing group and it fixed the issue: (?:[^a-zA-Z0-9_'])

image

This problem is certainly affecting all keywords, and I was considering doing a pull request but my textmate grammar skills aren't that great so it is hard for me to know what the impact would be.

Option to disable auto-indent.

I am finding I am undoing the indent a lot of the time. It would be nice to have an option to disable it from happening.

Disabling editor.autoIndent for haskell in the user settings seems to avoid some of the instances (such as auto-indenting when pasting) but some basic ones still occur (such as hitting Enter and having it indent too far).

  "[haskell]": {
    "editor.autoIndent": false
  },

Please highlight equal signs and other important characters

Thank you for making and maintaining this plugin! If you look at how GitHub displays blocks like this:

foobar = let
    foo = bar
    fuzz = buzz
    test = tested
    in (finalResponse)

you can see that the equal sign is highlighted. Without at least the equal sign being highlighted I have big blocks of entirely plain text code with no syntax highlighting at all.

I also recommend highlighting the $ operator.

foo = bar $ some thing

And ++ as well.

foo = "concated a " ++ "string"

It just seems like a lot of basic things aren't highlighted.

image

Highlight overloaded labels

There should be a rule for overloaded labels. Currently they are sometimes identifier as C preprocessor instructions, and otherwise parsed as an operator applied to an identifier.

overloaded_labels

Incorrect highlighting of empty typeclass

A class without any associated functions, e.g. just class A a, is valid Haskell, but gets highlighted incorrectly, as does everything following it.

Correct highlighting of non-empty class:
correct

Incorrect highlighting of empty class:
incorrect

Do not increase indent after one-line-if

Currently the increase indent regex increases the indent after any if, even if the if expression terminates on the same line.

Essentially it should not increase indent if a then follows the if.

The current regex is \bif\b(?!').*.

I tried \bif\b(?!').*(?!then.*) and \bif\b(?!').*?(?!then.*). Neither works.

I am not sure the regex is strong enough to even express what we need but I have not confirmed that yet.

Type variables not highlighted in visible type application

Type variables within a visible type application are not highlighted.

type_variable_in_visible_type_application

This requires disambiguating between visible type application and as-patterns. Quoting Richard Eisenberg:

With -XTypeApplications on, the character immediately before an @ determines how it is lexed.

  1. If the character is a legal end-of-identifier character (respecting the state of the -XMagicHash flag), then the @ is an as-pattern.
  2. Otherwise, then the @ is the beginning of a type application.

Scoping Syntax Suggestions

When I type module MyModule where and then tab or enter, it attempts the name = value completion which has to be deleted before moving on. Adding a space after where keeps this from happening but then I have an extra space character in my source file.

Is there a way to make this completion context aware and not try this completion when on the same line as module?

If possible, I'd be happy to make the change and submit a pull.

Maybe consider switching to json?

It seems VS code recommend .json for tmLanguage grammars. I used this extension to convert and it seems to work, if you decide in future to switch. Just friendly sharing knowledge - not suggesting you must! :)

Keyword detected for tagged-union `data`s only absent any record-syntax

Minor quirk really, but for the sake of completeness of open (non)"issues" ๐Ÿ˜ In the screenshot below, observe:

  • at the bottom --- correct detection of deriving in keyword scope in the tagged-union data QueryData that has no record-syntax, vs.

  • at the top (and also in the data Query near the bottom) --- incorrect mis-detection of deriving in variable scope when record-syntax is present in the data

screenshot from 2017-03-12 13-21-34

My RegEx is super-rusty, maybe I'll try my hand here later today, but wanted to report for now ;)

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.