OneDark-Pro icon indicating copy to clipboard operation
OneDark-Pro copied to clipboard

improve Dart/Flutter highlighting

Open subzero911 opened this issue 5 years ago • 24 comments

I want local variables (like authResult) to be amber and class members (like _auth) to be deep orange, as in Android Studio: image Current VS Code highlighting. All variables are boring white: image

Also, grey background is too bright. I found dark navy background is more pleasant to eye. Maybe something like these:

    "workbench.colorCustomizations": {
        "[One Dark Pro]": {
            "editor.background": "#191a20",    
            "editor.lineHighlightBackground": "#22232b",
            "editor.selectionBackground": "#363844",                                         
        }
    },

subzero911 avatar May 19 '20 15:05 subzero911

could you provide the code in your screenshot

Binaryify avatar May 20 '20 02:05 Binaryify

Of course

import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:chatapp/widgets/auth/auth_form.dart';
import 'package:flutter/services.dart';

class AuthScreen extends StatefulWidget {
  @override
  _AuthScreenState createState() => _AuthScreenState();
}

class _AuthScreenState extends State<AuthScreen> {
  final _auth = FirebaseAuth.instance;
  var _isLoading = false;

  void _submitAuthForm(String email, String username, String password, bool isLogin, BuildContext ctx) async {
    AuthResult authResult;
    try {
      setState(() {
        _isLoading = true;
      });
      if (isLogin) {
        authResult = await _auth.signInWithEmailAndPassword(email: email, password: password);
      } else {
        authResult = await _auth.createUserWithEmailAndPassword(email: email, password: password);
        await Firestore.instance
            .collection('users')
            .document(authResult.user.uid)
            .setData({
          'username': username,
          'email': email,
        });
      }
    } on PlatformException catch (err) {
      var message = 'Error occurred, please check your credentials.';
      if (err.message != null) {
        message = err.message;
      }
      Scaffold.of(ctx).showSnackBar(
        SnackBar(content: Text(message), backgroundColor: Theme.of(context).errorColor),
      );
    } catch (err) {
      print(err);
    } finally {
      setState(() {
        _isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Theme.of(context).primaryColor,
      appBar: AppBar(title: Text('Auth')),
      body: AuthForm(_submitAuthForm, _isLoading),
    );
  }
}

subzero911 avatar May 20 '20 06:05 subzero911

Maybe some color for named parameters also, because white (email: email, password: password) are not very nice too. Named parameters is a frequently used feature in Dart.

subzero911 avatar May 20 '20 06:05 subzero911

there have some bad news, I just check the code's token, and found them are same(source.dart), this mean dart extension is defective image image image if I highlight that, there have many highlight error image I think you could create a issue to dart repo or follow this PR https://github.com/Dart-Code/Dart-Code/pull/2203

Binaryify avatar May 20 '20 08:05 Binaryify

Hi @Binaryify There are LSP Semantic Tokens introduced in the latest Dart Code update. https://dartcode.org/releases/v3-19/ I believe now you could do it.

subzero911 avatar Feb 01 '21 09:02 subzero911

image @subzero911 finally I know how to config the semanticHighlighting how about this

Binaryify avatar Apr 05 '21 05:04 Binaryify

but I don't know should I make parameter be light white image

image image

Binaryify avatar Apr 05 '21 07:04 Binaryify

but I don't know should I make parameter be light white

Red parameter is definitely not what I wanted On the previous picture everything is perfect - white parameter name and red value

subzero911 avatar Apr 05 '21 07:04 subzero911

@subzero911 image Is that what you want?

Binaryify avatar Apr 05 '21 07:04 Binaryify

No I wanted it to be like image

if it's possible

subzero911 avatar Apr 05 '21 07:04 subzero911

both these are parameter image

Binaryify avatar Apr 05 '21 07:04 Binaryify

:( Then I don't know

subzero911 avatar Apr 05 '21 07:04 subzero911

you can set these in your setting.json to check the effect(need reload when first set)

"editor.semanticTokenColorCustomizations": {
    "rules": {
      "variable:dart":{
        "foreground": "#D19A66"
      },
      "property:dart":{
        "foreground": "#D19A66"
      },
      "annotation:dart":{
        "foreground": "#D19A66"
      },
      "parameter:dart":{
        // "foreground": "#abb2bf"
      },
    }
  },
  "editor.semanticHighlighting.enabled": true,
  "dart.previewLsp": true,

and use this the check the code's scope image

Binaryify avatar Apr 05 '21 08:04 Binaryify

Then it's better to left the parameter white

subzero911 avatar Apr 05 '21 08:04 subzero911

I just update to use new dart sdk, and it look normal now, this might be what you want image image

Binaryify avatar Apr 05 '21 08:04 Binaryify

please check v3.10.10 and confirm if it work fine~ make sure you had this in your setting.json

"editor.semanticHighlighting.enabled": true,
"dart.previewLsp": true,

Binaryify avatar Apr 06 '21 02:04 Binaryify

I tried it. Nothing changed for Flutter 1.22.6 (no null-safety version I use): image

I upgraded to Flutter 2.0.4. Now it looks like: image

subzero911 avatar Apr 06 '21 13:04 subzero911

I don't know why after I switch the dart sdk version some time, the highlight will change image image or I need make the parameter become white again image you can add this in your setting.json before I release new version

"editor.semanticTokenColorCustomizations": {
    "rules": {
      "parameter:dart":{
        "foreground": "#abb2bf"
      },
    }
  },

Binaryify avatar Apr 06 '21 14:04 Binaryify

v3.10.11 should already fix this, you can check it now

Binaryify avatar Apr 07 '21 04:04 Binaryify

Hello @Binaryify, after updating OneDarkPro suddenly all of my variables became amber/orange. I had to downgrade to make them become red again in Dart Code. The way I have VS Code setup with dart code is that parameters are white and bold then variables are red. After this update all of the variables became amber (apart from parameters). I tried to manually set variables to become red to override this change but it didn't work.

I made the parameters bold using the textMateRules customisation option.

Thanks for the help!

HadyMash avatar Apr 11 '21 16:04 HadyMash

@HadyMash
you can add this in your setting.json and change the color

"editor.semanticTokenColorCustomizations": {
    "rules": {
      "variable:dart": {
        "foreground": "#E06C75"
      },
      "property:dart": {
        "foreground": "#E06C75"
      },
      "annotation:dart": {
        "foreground": "#E06C75"
      },
      "parameter.label:dart": {
        "foreground": "#E06C75"
      },
    }
  },

and here are the colors you can choose

#e5c07b
#e06c75
#5c6370
#f44747
#56b6c2
#98c379
#ffffff
#7f848e
#abb2bf
#61afef
#c678dd
#d19a66
#BE5046

image

Binaryify avatar Apr 12 '21 01:04 Binaryify

@Binaryify Thanks, it worked!

HadyMash avatar Apr 12 '21 05:04 HadyMash

For people trying to find the vivid red colour, it's #EF596F.

tusharsadhwani avatar Apr 15 '21 18:04 tusharsadhwani

also @Binaryify i'd suggest going back to red for dart instead of amber, half the file looks yellow/orange now

image

tusharsadhwani avatar Apr 15 '21 19:04 tusharsadhwani