This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an API for Markdown-based datatips
Summary: The LSP's `hover` API (equivalent of datatip) works with Markdown strings and code snippets. https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#textDocument_hover This is actually quite convenient for external providers as this alleviates the React requirement. Adopt this API (`MarkedString`) and use it for typehints. I actually just moved the type hint UI into datatips in order to easily implement the code snippet part. Here's a screenshot of the sample: https://pxl.cl/73Wm Reviewed By: jgebhardt Differential Revision: D4812360 fbshipit-source-id: d191aeac5f0c92e5c056a3e191c73a4cd2d6f199
- Loading branch information
1 parent
f45f3d4
commit 2014073
Showing
8 changed files
with
171 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the LICENSE file in | ||
* the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {MarkedString} from './types'; | ||
|
||
import marked from 'marked'; | ||
import React from 'react'; | ||
|
||
import MarkedStringSnippet from './MarkedStringSnippet'; | ||
|
||
type Props = { | ||
markedStrings: Array<MarkedString>, | ||
}; | ||
|
||
export default class MarkedStringDatatip extends React.PureComponent { | ||
props: Props; | ||
|
||
render(): React.Element<any> { | ||
const elements = this.props.markedStrings.map((chunk, i) => { | ||
if (chunk.type === 'markdown') { | ||
return ( | ||
<div | ||
className="nuclide-datatip-marked-container" | ||
dangerouslySetInnerHTML={{ | ||
__html: marked(chunk.value, {sanitize: true}), | ||
}} | ||
key={i} | ||
/> | ||
); | ||
} else { | ||
return <MarkedStringSnippet key={i} {...chunk} />; | ||
} | ||
}); | ||
|
||
return ( | ||
<div className="nuclide-datatip-marked"> | ||
{elements} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
@import "ui-variables"; | ||
@import "syntax-variables"; | ||
|
||
.nuclide-datatip-marked > div:not(:last-child) { | ||
border-bottom: 1px solid fade(@text-color-highlight, 10%); | ||
} | ||
|
||
.nuclide-datatip-marked-container { | ||
color: @text-color; | ||
font-family: @font-family; | ||
padding: 8px; | ||
|
||
// Avoid excess internal padding from markdown blocks. | ||
:first-child { | ||
margin-top: 0; | ||
} | ||
|
||
:last-child { | ||
margin-bottom: 0; | ||
} | ||
} | ||
|
||
.nuclide-datatip-marked-text-editor { | ||
max-height: 300px; | ||
overflow-y: auto; | ||
} | ||
|
||
.nuclide-datatip-marked-text-editor atom-text-editor { | ||
background-color: transparent; | ||
min-width: 1em; // Hack to force the AtomTextEditor to properly size itself | ||
padding: 2px 0 2px 4px; | ||
|
||
.editor-contents--private { | ||
cursor: inherit!important; // Let the enclosing datatip override the cursor. | ||
} | ||
|
||
// Prevent forced scroll bar in Atom 1.9.x | ||
.scroll-view .horizontal-scrollbar { | ||
display: none; | ||
} | ||
.scrollbar-corner { | ||
display: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters