Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.

Conversation

akinsho
Copy link
Member

@akinsho akinsho commented Feb 6, 2018

This PR adds syntax highlighting to the hover tool tip other changes include:

  • Adding deep merges to the config so it supports sub object fields
  • Adding an adhoc highlighter to generate tokens for given lines as well as fn to generate vim highlights for a line
  • Added a function to get vim highlights actual color values
  • Added functionality to pull token colors from the json theme, user config and set defaults based on available vim highlights.
  • I've removed splitting up the hover info on every new line and now only render the docs and the titles differently.

Todo

  • Set highlight colors for various tokens or so tokens such as variable.other.object render with a color

  • Fix failing test due to config changes

  • Fix Regex quirks re .| characters

  • Add unit tests

  • resize hover container

Screenshots

screen shot 2018-02-07 at 22 05 33

screen shot 2018-02-04 at 16 06 44

Discussed below:
Fix formatting for code block and add highlighting to code blocks in tooltip

split out quickInfo container and pass it its own version of the theme
}> = this._configuration.getValue("editor.tokenColors")

// FIXME: Specify Highlights to check by differentiating vim highlights as no having "."
const tokens = Object.keys(configurationColors).filter(c => !c.includes("."))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this logic to NeovimInstance as getHighlights? This way, we don't need a public getVimHighlights method, as I'm hoping to keep the Editor interface as agnostic of Vim as possible.

Once we have that, we could change below to:

const vimHighlights = await this._neovimInstance.getHighlights()

}> = this._configuration.getValue("editor.tokenColors")

// FIXME: Specify Highlights to check by differentiating vim highlights as no having "."
const tokens = Object.keys(configurationColors).filter(c => !c.includes("."))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we need to look up editor.tokenColors here? Could we use a fixed array of `["Function", "Identifier", "String", "Character", etc], and then convert them to scopes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might've had the reverse in mind - we get all the Vim highlights, convert them to scopes + colors, and then use those for setting syntax highlights.

@@ -319,6 +484,19 @@ export class ThemeManager {
return this._themeLoader.getAllThemes()
}

public async getVimHighlightColors(tokenColors: IVimHighlight[]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we're actually setting the token colors here, so we might want to rename this to setTokenColors instead.

},
}

export interface IVimHighlight {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we could make the ThemeManager agnostic of Vim. The highlight group is really an implementation detail - it'd be great if we could make this care about color/bold/italic/background-color, and then leave it up to the setHighlights in Buffer to rationalize highlight groups from that. It sounded like there might be challenges here though - let me know what sort of hurdles you ran into.

@@ -3,6 +3,79 @@ import * as os from "os"
import * as React from "react"
import styled, { boxShadowInset, css, fontSizeSmall, withProps } from "./common"

const markedCss = css`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes for the rendering look great to me! Thanks for all your work here. I wonder if we could split this up into two changes? It seems like the synchronizing highlight groups has some challenges, but we could at least bring in the rendering with the editor.tokenColors we have today

"editor.tokenColors": {
"meta.import": {
scope: "meta-import",
settings: "Define",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ya, this is where I was hoping we could specify color/background color/bold/italic etc (and in the user's config / theme as well) instead of the vim highlight group. The vim highlight group was really just a crutch to implement.

"highlight.mode.visual.foreground": "#282c34",
"editor.tokenColors": {
"variable.parameter": {
"color": "#d19a66"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 😄

@@ -295,6 +295,9 @@ export class Buffer implements IBuffer {
}

const getToken = (lineContents: string, character: number): Oni.IToken => {
if (!lineContents || !character) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I wonder if this is related to an issue in my PR #1298... perhaps I'm hitting this too!

it requires setting up moving json files around
as grammar loader is a dependecy and cant be
used without a valid textmate json file
can look into adding this functionality separately
to test grammar loader
@codecov
Copy link

codecov bot commented Feb 13, 2018

Codecov Report

Merging #1443 into master will decrease coverage by <.01%.
The diff coverage is 45.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1443      +/-   ##
==========================================
- Coverage   45.63%   45.62%   -0.01%     
==========================================
  Files         112      112              
  Lines        4111     4114       +3     
  Branches      589      590       +1     
==========================================
+ Hits         1876     1877       +1     
- Misses       2105     2107       +2     
  Partials      130      130
Impacted Files Coverage Δ
browser/src/UI/components/common.ts 92.59% <100%> (+0.28%) ⬆️
browser/src/Services/Themes/ThemeManager.ts 60.52% <100%> (ø) ⬆️
...rowser/src/Services/Configuration/Configuration.ts 73.91% <100%> (+0.28%) ⬆️
...lugins/Api/LanguageClient/LanguageClientHelpers.ts 50% <16.66%> (-2.78%) ⬇️
browser/src/UI/components/QuickInfo.tsx 30.76% <33.33%> (+0.21%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44e162d...60e6ee9. Read the comment docs.

@akinsho akinsho changed the title [WIP] Feature/syntax highlight hover Feature/syntax highlight hover Feb 13, 2018
@akinsho
Copy link
Member Author

akinsho commented Feb 17, 2018

Further update managed to fix the outstanding bug (that I'm aware of tm) which was that code blocks weren't highlighting which was actually not a commonly encountered issue as most of the markup is being rendered in p tags by marked but it was an issue with marked trimming whitespace from the text passed to the custom renderer which I've resolved. So believe this is good to go.

also remove styling as this is actually unnecessary
lack of rule causes weird at a glance issue with larger
code blocks
this is not ideal as hover then has missing keys
plus some functionality can be achieved without sets
marked dumps html into the out put which is less
preferable and its sanitizer option breaks highlighting

describe("Markdown Conversion Functions", () => {
it("Scopes to string fn should correctly convert scopes to classnames", () => {
const className = markdown.scopesToString(["token.scope.extension"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests here! 👍

)

return (
<TokenThemeProvider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool idea to separate the logic of getting the token colors from the logic of rendering

Copy link
Member

@bryphe bryphe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the work with this, @akin909 ! I just pulled the latest and it looks awesome 💯

@akinsho akinsho merged commit b3b5b80 into onivim:master Feb 22, 2018
@akinsho akinsho mentioned this pull request Mar 3, 2018
2 tasks
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.

3 participants