Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Add suggestion type icons and left label - #334

Merged
benogle merged 20 commits into
masterfrom
bo-left-label
Apr 2, 2015
Merged

benogle merged 20 commits into
masterfrom
bo-left-label

Conversation

@benogle

@benogle benogle commented Mar 24, 2015

Copy link
Copy Markdown
Contributor

This add support for three properties on a suggestion: leftLabel, type, and iconHTML. Your provider might return something like this:

provider =
  getSuggestions: ({prefix}) ->
    [{
      type: 'property'
      text: 'becomeFirstResponder'
      leftLabel: 'BOOL'
    }, ...]

The type is turned into an icon in the left-most column. The leftLabel is rendered right aligned between the icon and suggestion replacement. The user would see:

screen shot 2015-03-23 at 5 30 36 pm

In dark:

screen shot 2015-03-23 at 5 31 27 pm

Alternatively you can use your own icon with the iconHTML property:

provider =
  getSuggestions: ({prefix}) ->
    [{
      iconHTML: '<i class="icon-move-right"></i>'
      type: 'snippet'
      text: 'cla'
      rightLabel: 'Class'
    }, ...]

(note the first suggestion)

screen shot 2015-03-23 at 3 01 17 pm

Optional

Al three of these properties are optional. When not specified, the suggestion list looks much like it's looked since the beginning:

screen shot 2015-03-23 at 5 56 56 pm

Types, Icons and Colors

Default icons are just the first letter of the type. Over time, they may be replaced by purpose-built icons.

Icon colors are determined by syntax variables. The idea is to match the icon color with the color of the symbol type. i.e. when variables are colored red, the variable icon is red.

Currently supported types with predefined colors are variable, constant, property, value, method, function, class, keyword, tag, snippet. This list represents nearly everything being colorized.

Each syntax theme can set these variables to set the icon colors:

@syntax-color-variable: #DF6A73;
@syntax-color-constant: #DF6A73;
@syntax-color-property: #DF6A73;
@syntax-color-value: #D29B67;
@syntax-color-method: #61AEEF;
@syntax-color-function: #61AEEF;
@syntax-color-class: #E5C17C;
@syntax-color-keyword: #555;
@syntax-color-tag: #555;
@syntax-color-snippet: #97C378;

A list of fallback colors are defined for syntax themes that do not define these variables.

Types not defined here can be used in the type field, but will have a fallback color. A theme can style the icons with the following less:

@color: #369;
autocomplete-suggestion-list .icon.newtype {
  color: @color;
  background: fadeout(@color, 80%)
}

@joefitzgerald

Copy link
Copy Markdown
Contributor

LGTM. A few thoughts:

  • If my language calls a function a func, how do I map back to the function syntax variable
  • What happens when different providers mix use of leftLabel, rightLabel, iconHTML, or none of them? Do we have a test that covers that?
  • Should we be more prescriptive in provider docs about what belongs in leftLabel and rightLabel? While they are optional, it would suck if there was variable "types" of information in each, as it could cause dissonance when scanning a suggestion list containing suggestions from multiple providers

@benogle

benogle commented Mar 24, 2015

Copy link
Copy Markdown
Contributor Author

If my language calls a function a func, how do I map back to the function syntax variable

The provider should use one of the supported types if it can, in this case: function. If it wants to define its own, the type will be added to the icon span as a class. So you can do this in your theme/styles/package:

@color: #369;
autocomplete-suggestion-list .icon.func {
  color: @color;
  background: fadeout(@color, 80%)
}

What happens when different providers mix use of leftLabel, rightLabel, iconHTML, or none of them? Do we have a test that covers that?

Each is displayed as a table column. There are 3 columns:

| iconHTML | leftLabel | text & rightLabel |

For the icon and left label, when nothing defines them, then those columns will take up no space. If one suggestion defines either the icon or left label, there will be space for the whole column. For the rightLabel, it's just floated right in the right most column; it doesnt get its own column. See the image linked to int he OP:

  • cla is the only one with a rightLabel
  • clang and code-completion-at do not have icons.

63578990-d182-11e4-988f-2fc4ed3cbccb

Should we be more prescriptive in provider docs about what belongs in leftLabel and rightLabel? While they are optional, it would suck if there was variable "types" of information in each, as it could cause dissonance when scanning a suggestion list containing suggestions from multiple providers

I'm not totally following. Yes, we should explain in the docs what we think should be in those fields.

@benogle

benogle commented Mar 24, 2015

Copy link
Copy Markdown
Contributor Author

cc @bolinfest as you guys need something like this. If you have a list of all suggestion types you guys use, that would be helpful. Does the list above cover your needs?

@joefitzgerald

Copy link
Copy Markdown
Contributor

For go, the values I have been using in type are: [func, package, var, type, const, PANIC].

  • func maps to function
  • package maps to nothing (it's like a require in js/coffee)
  • var maps to variable
  • type maps to class (kiiiiind of, but not really)
  • const maps to `constant
  • PANIC maps to nothing (but if you had an exception or an error type it would match one of those

My concern here is that each grammar has a different definition of syntax types, and consequently you're going to get into a mapping quandary for most grammars.

Perhaps a more flexible approach would be to somehow tie this to [a variable number of] things defined in the grammar, and use those to drive the icon and styling.

@benogle

benogle commented Mar 24, 2015

Copy link
Copy Markdown
Contributor Author

The symbol types chosen are based on the scopes / classes used in the syntax themes. How are those things listed scoped / styled for go? This problem exists already in the syntax themes, no? How was it worked around?

We could generify some of them. class becomes type, and we could add one for require et al like import.

Just having a list of colors and randomly assigning them is an option, but it would be nice to tie them back to the colors the users sees in the syntax.

@joefitzgerald

Copy link
Copy Markdown
Contributor

@benogle type is identified by the go grammar here: https://github.com/atom/language-go/blob/5fa8d11f75014818ff192d88b52d473f2b6e041a/grammars/go.cson#L62-L69; func is identified here: https://github.com/atom/language-go/blob/5fa8d11f75014818ff192d88b52d473f2b6e041a/grammars/go.cson#L47-L54

These don't seem to map to any syntax theme, and yet the scopes they define do seem to affect colorization of the source. So I wonder if it's the scope (or parts thereof) that we should be narrowing in on, as it seems like it may be a common denominator across language?

@benogle

benogle commented Mar 24, 2015

Copy link
Copy Markdown
Contributor Author

func is using the function scope which makes sense.

type defines two that are colorized: keyword and storage.

storage is a totally horrible name, though. Another common thing highlighted that languages often use with a horrible name is entity.

Here is a list of types this could support by default

  • variable
  • constant
  • property
  • value
  • function
  • method (alias for function)
  • type (new!)
  • class (alias for type)
  • keyword
  • builtin (alias for keyword)
  • tag
  • snippet
  • import (new!)
  • require (alias for import)

What else would we need? Could some crazy language map onto these?

@joefitzgerald

Copy link
Copy Markdown
Contributor

Given:

  • grammars define scopes
  • scopes are themed via syntax themes
  • there is no clear definition of a common set of scopes that should be themed in syntax themes

Do we really want to be defining another set of 'types' that can be themed, or should we really just accept any scope (just like a grammar) and let things wash out in the syntax themes? That is; if a grammar is themed correctly, the suggestion list for that grammar should also. It forces the themes to agree upon a set of common things, as well as specific language concessions. It forces the grammars to use scopes that are commonly accepted, or work to have the syntax theme specification extended for their use case.

So rather than having an accepted whitelist of types, we should move https://github.com/atom-community/autocomplete-plus/blob/075ad4348bf5b969b38fbc5527e44fb91a179433/styles/autocomplete.less#L1-L10 into the syntax themes themselves, and then do what you've done above and make sure the syntax themes include additional things.

@benogle

benogle commented Mar 24, 2015

Copy link
Copy Markdown
Contributor Author

So rather than having an accepted whitelist of types, we should move https://github.com/atom-community/autocomplete-plus/blob/075ad4348bf5b969b38fbc5527e44fb91a179433/styles/autocomplete.less#L1-L10 into the syntax themes themselves

Yes, this is the intent. Those variables linked are defaults, and the syntax themes should override them. I think this will move toward a more consistent ecosystem of themes, and allow easier extension of themes -- new users can just fork a theme change some variables to get 95% of the way to what they want. The themes we control should have these defined shortly after merging this.

then do what you've done above and make sure the syntax themes include additional things.

I dont understand this. Which part above?

there is no clear definition of a common set of scopes that should be themed in syntax themes

This has always frustrated me. I would love love to have some conventions on defining scopes. I did a bunch of work on a grammar a while back, and it required looking at ~5 other grammars to understand the common scopes for something I wanted to define.

Do we really want to be defining another set of 'types' that can be themed,

I'm not fully understanding your position here. Looks like the first paragraph disagrees with the list of types, but the second agrees. What is your read on the list I've defined above? Are you saying we should change the names to match scopes? Or not define them at all?

@joefitzgerald

Copy link
Copy Markdown
Contributor

What is your read on the list I've defined above? Are you saying we should change the names to match scopes? Or not define them at all?

I'm saying we should define the styles for them in some core stylesheet, not in the autocomplete-plus stylesheet.

...it required looking at ~5 other grammars to understand the common scopes for something I wanted to define.

Does this belong at https://atom.io/docs / https://atom.io/docs/latest/using-atom-grammar?

Sounds like we're saying the same things in all the other areas. This PR is good forward movement.

@benogle

benogle commented Mar 24, 2015

Copy link
Copy Markdown
Contributor Author

I'm saying we should define the styles for them in some core stylesheet, not in the autocomplete-plus stylesheet.

The variable defaults or the color styles for these icons?

@joefitzgerald

Copy link
Copy Markdown
Contributor

The variable defaults.

@joefitzgerald

Copy link
Copy Markdown
Contributor

:shipit:

@benogle

benogle commented Mar 30, 2015

Copy link
Copy Markdown
Contributor Author

This is ready to go, but I'm going to sit on it until we release 189 tomorrow.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants