@lvce-editor/hover-worker 2.19.0 → 2.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,12 @@
1
- # hover-worker
1
+ # Hover Worker
2
2
 
3
- Hover Worker
3
+ > A Web Worker for the hover functionality in Lvce Editor.
4
+
5
+ ## Contributing
6
+
7
+ ```sh
8
+ git clone git@github.com:lvce-editor/hover-worker.git &&
9
+ cd hover-worker &&
10
+ npm ci &&
11
+ npm test
12
+ ```
@@ -1714,9 +1714,20 @@ const initialize = async () => {
1714
1714
  set(rpc);
1715
1715
  };
1716
1716
 
1717
+ const invoke = (...args) => invoke$2(...args);
1718
+
1717
1719
  const measureTextBlockHeight = async (text, fontFamily, fontSize, lineHeight, width) => {
1718
- // TODO ask editor worker or renderer process
1719
- return 100;
1720
+ return invoke('MeasureTextHeight.measureTextBlockHeight', text, fontFamily, fontSize, lineHeight, width);
1721
+ };
1722
+
1723
+ const getDiagnosticHeight = async (diagnostics, fontFamily, fontSize, lineHeight, width) => {
1724
+ const text = diagnostics.map(value => {
1725
+ const diagnostic = value;
1726
+ return `${diagnostic.message} ${diagnostic.source} (${diagnostic.code})`;
1727
+ }).join('\n');
1728
+ const textHeight = await measureTextBlockHeight(text, fontFamily, fontSize, lineHeight, width);
1729
+ // Include the hover's two-pixel border; keep the widget's CSS minimum height.
1730
+ return Math.max(20, textHeight + 2);
1720
1731
  };
1721
1732
 
1722
1733
  const tokenizeCodeBlock = async (codeBlock, languageId, tokenizerPath) => {
@@ -1734,8 +1745,9 @@ const getHoverDetails = async (hover, error, hoverFullWidth, hoverPaddingLeft, h
1734
1745
  }
1735
1746
  const hoverText = typeof hover.text === 'string' && hover.text.trim() ? hover.text : '';
1736
1747
  const documentation = typeof hover.documentation === 'string' && hover.documentation.trim() ? hover.documentation : hoverText;
1748
+ const hoverDocumentationWidth = hoverFullWidth - hoverPaddingLeft - hoverPaddingRight - hoverBorderLeft - hoverBorderRight;
1737
1749
  const lineInfos = await tokenizeCodeBlock();
1738
- const documentationHeight = await measureTextBlockHeight();
1750
+ const documentationHeight = await measureTextBlockHeight(documentation, hoverDocumentationFontFamily, hoverDocumentationFontSize, hoverDocumentationLineHeight, hoverDocumentationWidth);
1739
1751
  return {
1740
1752
  documentation,
1741
1753
  documentationHeight,
@@ -1868,7 +1880,7 @@ const getEditorHoverInfo = async (editorUid, editorLanguageId, hoverFullWidth, h
1868
1880
  const {
1869
1881
  documentation,
1870
1882
  lineInfos
1871
- } = await getHoverDetails(hover, error);
1883
+ } = await getHoverDetails(hover, error, hoverFullWidth, hoverPaddingLeft, hoverPaddingRight, hoverBorderLeft, hoverBorderRight, hoverDocumentationFontFamily, hoverDocumentationFontSize, hoverDocumentationLineHeight);
1872
1884
  if (!documentation && lineInfos.length === 0 && matchingDiagnostics.length === 0) {
1873
1885
  return undefined;
1874
1886
  }
@@ -1883,18 +1895,26 @@ const getEditorHoverInfo = async (editorUid, editorLanguageId, hoverFullWidth, h
1883
1895
 
1884
1896
  const getWordAtOffset = getWordAtOffset2;
1885
1897
 
1886
- const invoke = (...args) => invoke$2(...args);
1887
-
1888
1898
  const loadContent = async state => {
1889
1899
  const {
1890
1900
  editorLanguageId,
1891
- editorUid} = state;
1901
+ editorUid,
1902
+ height: currentHeight,
1903
+ hoverBorderLeft,
1904
+ hoverBorderRight,
1905
+ hoverDocumentationFontFamily,
1906
+ hoverDocumentationFontSize,
1907
+ hoverDocumentationLineHeight,
1908
+ hoverFullWidth,
1909
+ hoverPaddingLeft,
1910
+ hoverPaddingRight
1911
+ } = state;
1892
1912
  const wordAtOffset = await getWordAtOffset(editorUid);
1893
1913
  const {
1894
1914
  x,
1895
1915
  y
1896
1916
  } = await getPositionAtCursor(editorUid);
1897
- const info = await getEditorHoverInfo(editorUid, editorLanguageId);
1917
+ const info = await getEditorHoverInfo(editorUid, editorLanguageId, hoverFullWidth, hoverPaddingLeft, hoverPaddingRight, hoverBorderLeft, hoverBorderRight, hoverDocumentationFontFamily, hoverDocumentationFontSize, hoverDocumentationLineHeight);
1898
1918
  if (!info) {
1899
1919
  return close(state);
1900
1920
  }
@@ -1906,15 +1926,18 @@ const loadContent = async state => {
1906
1926
  if (!documentation && lineInfos.length === 0 && matchingDiagnostics.length === 0) {
1907
1927
  return close(state);
1908
1928
  }
1929
+ const width = 300;
1930
+ const height = matchingDiagnostics.length > 0 ? Math.min(300, await getDiagnosticHeight(matchingDiagnostics, hoverDocumentationFontFamily, hoverDocumentationFontSize, hoverDocumentationLineHeight, width - hoverBorderLeft - hoverBorderRight)) : currentHeight;
1909
1931
  const documentationVirtualDom = documentation ? await invoke('Markdown.getVirtualDomFromMarkdown', documentation) : [];
1910
1932
  return {
1911
1933
  ...state,
1912
1934
  documentation,
1913
1935
  documentationVirtualDom,
1936
+ height,
1914
1937
  leadingWord: wordAtOffset,
1915
1938
  lineInfos,
1916
1939
  matchingDiagnostics,
1917
- width: 300,
1940
+ width,
1918
1941
  x,
1919
1942
  y
1920
1943
  };
@@ -2188,4 +2211,4 @@ const main = async () => {
2188
2211
  await listen();
2189
2212
  };
2190
2213
 
2191
- main();
2214
+ await main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/hover-worker",
3
- "version": "2.19.0",
3
+ "version": "2.19.2",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",