From bcf658f678100dfcba119500520ff1abd8ec4ad4 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 23 Feb 2023 11:05:51 +0100 Subject: [PATCH] mv monaco --- .../parser/services/code-parser-compiler.ts | 10 ++--- apps/remix-ide/webpack.config.js | 2 + libs/remix-ui/editor/src/index.ts | 1 + .../remix-ui/editor/src/lib/actions/editor.ts | 4 +- .../providers/completion/completionGlobals.ts | 39 +++++++++---------- .../src/lib/providers/completionProvider.ts | 8 ++-- .../editor/src/lib/providers/hoverProvider.ts | 6 +-- .../editor/src/lib/remix-ui-editor.tsx | 21 +++++----- package.json | 5 ++- yarn.lock | 25 ------------ 10 files changed, 49 insertions(+), 72 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts b/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts index 8ea51b2ce1..5fd65d2b68 100644 --- a/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts +++ b/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts @@ -7,13 +7,13 @@ import { CodeParser } from "../code-parser"; import { fileDecoration, fileDecorationType } from '@remix-ui/file-decorators' import { sourceMappingDecoder } from '@remix-project/remix-debug' import { CompilerRetriggerMode, CompilationSourceCode } from '@remix-project/remix-solidity'; -import { MarkerSeverity } from 'monaco-editor'; import { findLinesInStringWithMatch, SearchResultLine } from '@remix-ui/search' import { lastCompilationResult } from '@remixproject/plugin-api'; +import { monaco } from '@remix-ui/editor'; type errorMarker = { message: string - severity: MarkerSeverity + severity: monaco.MarkerSeverity position: { start: { line: number @@ -196,8 +196,8 @@ export default class CodeParserCompiler { const decorator: fileDecoration = { path: fileTarget.file, isDirectory: false, - fileStateType: errors[0].severity == MarkerSeverity.Error ? fileDecorationType.Error : fileDecorationType.Warning, - fileStateLabelClass: errors[0].severity == MarkerSeverity.Error ? 'text-danger' : 'text-warning', + fileStateType: errors[0].severity == monaco.MarkerSeverity.Error ? fileDecorationType.Error : fileDecorationType.Warning, + fileStateLabelClass: errors[0].severity == monaco.MarkerSeverity.Error ? 'text-danger' : 'text-warning', fileStateIconClass: '', fileStateIcon: '', text: errors.length.toString(), @@ -230,7 +230,7 @@ export default class CodeParserCompiler { async createErrorMarker(error: any, filePath: string, lineColumn): Promise { return { message: error.formattedMessage, - severity: error.severity === 'error' ? MarkerSeverity.Error : MarkerSeverity.Warning, + severity: error.severity === 'error' ? monaco.MarkerSeverity.Error : monaco.MarkerSeverity.Warning, position: { start: { line: ((lineColumn.start && lineColumn.start.line) || 0) + 1, diff --git a/apps/remix-ide/webpack.config.js b/apps/remix-ide/webpack.config.js index 93aecd6aef..1e60610759 100644 --- a/apps/remix-ide/webpack.config.js +++ b/apps/remix-ide/webpack.config.js @@ -60,11 +60,13 @@ module.exports = composePlugins(withNx(), withReact(), (config) => { // add copy & provide plugin config.plugins.push( + /* new CopyPlugin({ patterns: [ { from: '../../node_modules/monaco-editor/dev/vs', to: 'assets/js/monaco-editor/dev/vs' } ].filter(Boolean) }), + */ new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'], url: ['url', 'URL'], diff --git a/libs/remix-ui/editor/src/index.ts b/libs/remix-ui/editor/src/index.ts index 7e3dcbc386..af5d53cdff 100644 --- a/libs/remix-ui/editor/src/index.ts +++ b/libs/remix-ui/editor/src/index.ts @@ -1 +1,2 @@ export * from './lib/remix-ui-editor' +export { default as monaco } from './types/monaco' \ No newline at end of file diff --git a/libs/remix-ui/editor/src/lib/actions/editor.ts b/libs/remix-ui/editor/src/lib/actions/editor.ts index 231aa09a82..261c97d929 100644 --- a/libs/remix-ui/editor/src/lib/actions/editor.ts +++ b/libs/remix-ui/editor/src/lib/actions/editor.ts @@ -1,5 +1,5 @@ -import { IRange } from "monaco-editor"; +import { monaco } from '@remix-ui/editor'; export interface Action { type: string; payload: Record @@ -58,7 +58,7 @@ export const reducerActions = (models = initialState, action: Action) => { } case 'REVEAL_RANGE': { if (!editor) return models - const range: IRange = { + const range: monaco.IRange = { startLineNumber: action.payload.startLineNumber + 1, startColumn: action.payload.startColumn, endLineNumber: action.payload.endLineNumber + 1, diff --git a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts index 4d69093b1c..94cb3249dc 100644 --- a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts +++ b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts @@ -1,6 +1,5 @@ -import { IRange } from "monaco-editor"; -import monaco from "../../../types/monaco"; import path from "path"; +import { monaco } from '@remix-ui/editor'; type CodeParserImportsData = { files?: string[], @@ -8,7 +7,7 @@ type CodeParserImportsData = { packages?: string[], } -export function getStringCompletionItems(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function getStringCompletionItems(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { return [ { detail: 'concatenate an arbitrary number of string values', @@ -21,7 +20,7 @@ export function getStringCompletionItems(range: IRange, monaco): monaco.language ] } -export function getBytesCompletionItems(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function getBytesCompletionItems(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { return [ { detail: 'concatenate an arbitrary number of values', @@ -35,7 +34,7 @@ export function getBytesCompletionItems(range: IRange, monaco): monaco.languages } -export function getBlockCompletionItems(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function getBlockCompletionItems(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { return [ { detail: '(address): Current block miner’s address', @@ -97,7 +96,7 @@ export function getBlockCompletionItems(range: IRange, monaco): monaco.languages ]; } -export function getCompletionSnippets(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function getCompletionSnippets(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { return [ { label: 'contract', @@ -193,7 +192,7 @@ export function getCompletionSnippets(range: IRange, monaco): monaco.languages.C ] } -export function getTxCompletionItems(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function getTxCompletionItems(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { return [ { detail: '(uint): gas price of the transaction', @@ -212,7 +211,7 @@ export function getTxCompletionItems(range: IRange, monaco): monaco.languages.Co ]; } -export function getMsgCompletionItems(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function getMsgCompletionItems(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { return [ { detail: '(bytes): complete calldata', @@ -252,7 +251,7 @@ export function getMsgCompletionItems(range: IRange, monaco): monaco.languages.C ]; } -export function getAbiCompletionItems(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function getAbiCompletionItems(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { return [ { detail: 'encode(..) returs (bytes): ABI-encodes the given arguments', @@ -298,7 +297,7 @@ export function getAbiCompletionItems(range: IRange, monaco): monaco.languages.C } -export function GetCompletionTypes(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function GetCompletionTypes(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { const completionItems = []; const types = ['address', 'string', 'bytes', 'byte', 'int', 'uint', 'bool', 'hash']; for (let index = 8; index <= 256; index += 8) { @@ -314,7 +313,7 @@ export function GetCompletionTypes(range: IRange, monaco): monaco.languages.Comp return completionItems; } -function CreateCompletionItem(label: string, kind: monaco.languages.CompletionItemKind, detail: string, range: IRange) { +function CreateCompletionItem(label: string, kind: monaco.languages.CompletionItemKind, detail: string, range: monaco.IRange) { const completionItem: monaco.languages.CompletionItem = { label, kind, @@ -327,7 +326,7 @@ function CreateCompletionItem(label: string, kind: monaco.languages.CompletionIt return completionItem; } -export function GetCompletionKeywords(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function GetCompletionKeywords(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { const completionItems = []; const keywords = ['modifier', 'mapping', 'break', 'continue', 'delete', 'else', 'for', 'after', 'promise', 'alias', 'apply', 'auto', 'copyof', 'default', 'define', 'final', 'implements', @@ -366,7 +365,7 @@ export function GetCompletionKeywords(range: IRange, monaco): monaco.languages.C } -export function GeCompletionUnits(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function GeCompletionUnits(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { const completionItems = []; const etherUnits = ['wei', 'gwei', 'finney', 'szabo', 'ether']; etherUnits.forEach(unit => { @@ -390,7 +389,7 @@ export function GeCompletionUnits(range: IRange, monaco): monaco.languages.Compl return completionItems; } -export function GetImports(range: IRange +export function GetImports(range: monaco.IRange , monaco, data: CodeParserImportsData , word: string ): monaco.languages.CompletionItem[] { @@ -473,7 +472,7 @@ export function GetImports(range: IRange return list; }; -export function GetGlobalVariable(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function GetGlobalVariable(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { return [ { detail: 'Current block', @@ -520,7 +519,7 @@ export function GetGlobalVariable(range: IRange, monaco): monaco.languages.Compl ]; } -export function GetGlobalFunctions(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function GetGlobalFunctions(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { return [ { detail: 'assert(bool condition): throws if the condition is not met - to be used for internal errors.', @@ -644,7 +643,7 @@ export function GetGlobalFunctions(range: IRange, monaco): monaco.languages.Comp ]; } -export function getContextualAutoCompleteByGlobalVariable(word: string, range: IRange, monaco): monaco.languages.CompletionItem[] { +export function getContextualAutoCompleteByGlobalVariable(word: string, range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { if (word === 'block') { return getBlockCompletionItems(range, monaco); } @@ -669,7 +668,7 @@ export function getContextualAutoCompleteByGlobalVariable(word: string, range: I return null; } -export function getArrayCompletionItems(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function getArrayCompletionItems(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { return [ { detail: '', @@ -706,7 +705,7 @@ export function getArrayCompletionItems(range: IRange, monaco): monaco.languages ] } -export function getAddressCompletionItems(range: IRange, monaco): monaco.languages.CompletionItem[] { +export function getAddressCompletionItems(range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { return [ { detail: '(uint256): balance of the Address in Wei', @@ -752,7 +751,7 @@ export function getAddressCompletionItems(range: IRange, monaco): monaco.languag } -export function getContextualAutoCompleteBTypeName(word: string, range: IRange, monaco): monaco.languages.CompletionItem[] { +export function getContextualAutoCompleteBTypeName(word: string, range: monaco.IRange, monaco): monaco.languages.CompletionItem[] { if (word === 'ArrayTypeName') { return getArrayCompletionItems(range, monaco); } diff --git a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts index 93d259b236..7f2ea6ba84 100644 --- a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts @@ -1,11 +1,9 @@ import { AstNode } from "@remix-project/remix-solidity" import { isArray } from "lodash" -import { editor, languages, Position } from "monaco-editor" -import monaco from "../../types/monaco" import { EditorUIProps } from "../remix-ui-editor" import { GeCompletionUnits, GetCompletionKeywords, getCompletionSnippets, GetCompletionTypes, getContextualAutoCompleteBTypeName, getContextualAutoCompleteByGlobalVariable, GetGlobalFunctions, GetGlobalVariable, GetImports } from "./completion/completionGlobals" - -export class RemixCompletionProvider implements languages.CompletionItemProvider { +import { monaco } from '@remix-ui/editor'; +export class RemixCompletionProvider implements monaco.languages.CompletionItemProvider { props: EditorUIProps monaco: any @@ -17,7 +15,7 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider } triggerCharacters = ['.', '', '"', '@', '/'] - async provideCompletionItems(model: editor.ITextModel, position: Position, context: monaco.languages.CompletionContext): Promise { + async provideCompletionItems(model: monaco.editor.ITextModel, position: monaco.Position, context: monaco.languages.CompletionContext): Promise { const completionSettings = await this.props.plugin.call('config', 'getAppParameter', 'settings/auto-completion') if (!completionSettings) return diff --git a/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts b/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts index ab2074b9a6..2f18c7d0f6 100644 --- a/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts @@ -1,8 +1,8 @@ import { Monaco } from '@monaco-editor/react' -import { editor, languages, Position } from 'monaco-editor' import { EditorUIProps } from '../remix-ui-editor' -export class RemixHoverProvider implements languages.HoverProvider { +import { monaco } from '@remix-ui/editor'; +export class RemixHoverProvider implements monaco.languages.HoverProvider { props: EditorUIProps monaco: Monaco @@ -11,7 +11,7 @@ export class RemixHoverProvider implements languages.HoverProvider { this.monaco = monaco } - provideHover = async function (model: editor.ITextModel, position: Position): Promise { + provideHover = async function (model: monaco.editor.ITextModel, position: monaco.Position): Promise { const cursorPosition = this.props.editorAPI.getHoverPosition(position) const nodeAtPosition = await this.props.plugin.call('codeParser', 'definitionAtPosition', cursorPosition) const contents = [] diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index c2ece6a9bb..ced152fdc0 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -7,11 +7,12 @@ import { solidityTokensProvider, solidityLanguageConfig } from './syntaxes/solid import { cairoTokensProvider, cairoLanguageConfig } from './syntaxes/cairo' import { zokratesTokensProvider, zokratesLanguageConfig } from './syntaxes/zokrates' import { moveTokenProvider, moveLanguageConfig } from './syntaxes/move' +import { monaco } from '@remix-ui/editor'; import './remix-ui-editor.css' import { loadTypes } from './web-types' -import monaco from '../types/monaco' -import { IMarkdownString, IPosition, MarkerSeverity } from 'monaco-editor' + + import { RemixHoverProvider } from './providers/hoverProvider' import { RemixReferenceProvider } from './providers/referenceProvider' @@ -59,12 +60,12 @@ export type lineText = { className: string afterContentClassName: string hide: boolean, - hoverMessage: IMarkdownString | IMarkdownString[] + hoverMessage: monaco.IMarkdownString | monaco.IMarkdownString[] } type errorMarker = { message: string - severity: MarkerSeverity | 'warning' | 'info' | 'error' | 'hint' + severity: monaco.MarkerSeverity | 'warning' | 'info' | 'error' | 'hint' position: { start: { line: number @@ -78,7 +79,7 @@ type errorMarker = { file: string } -loader.config({ paths: { vs: 'assets/js/monaco-editor/dev/vs' } }) +//loader.config({ paths: { vs: 'assets/js/monaco-editor/dev/vs' } }) export type DecorationsReturn = { currentDecorations: Array @@ -105,8 +106,8 @@ export interface EditorUIProps { findMatches: (uri: string, value: string) => any getFontSize: () => number, getValue: (uri: string) => string - getCursorPosition: (offset?: boolean) => number | IPosition - getHoverPosition: (position: IPosition) => number + getCursorPosition: (offset?: boolean) => number | monaco.IPosition + getHoverPosition: (position: monaco.IPosition) => number addDecoration: (marker: sourceMarker, filePath: string, typeOfDecoration: string) => DecorationsReturn clearDecorationsByPlugin: (filePath: string, plugin: string, typeOfDecoration: string, registeredDecorations: any, currentDecorations: any) => DecorationsReturn keepDecorationsFor: (filePath: string, plugin: string, typeOfDecoration: string, registeredDecorations: any, currentDecorations: any) => DecorationsReturn @@ -435,9 +436,9 @@ export const EditorUI = (props: EditorUIProps) => { filePath = fileFromUrl.file const model = editorModelsState[filePath]?.model const errorServerityMap = { - 'error': MarkerSeverity.Error, - 'warning': MarkerSeverity.Warning, - 'info': MarkerSeverity.Info + 'error': monaco.MarkerSeverity.Error, + 'warning': monaco.MarkerSeverity.Warning, + 'info': monaco.MarkerSeverity.Info } if (model) { const markerData: monaco.editor.IMarkerData = { diff --git a/package.json b/package.json index 074e898c7e..43e5144e4f 100644 --- a/package.json +++ b/package.json @@ -126,7 +126,7 @@ "@ethereumjs/vm": "^6.3.0", "@ethersphere/bee-js": "^3.2.0", "@isomorphic-git/lightning-fs": "^4.4.1", - "@monaco-editor/react": "4.4.5", + "@remixproject/engine": "^0.3.31", "@remixproject/engine-web": "^0.3.31", "@remixproject/plugin": "^0.3.31", @@ -168,7 +168,7 @@ "jszip": "^3.6.0", "latest-version": "^5.1.0", "merge": "^2.1.1", - "monaco-editor": "^0.30.1", + "npm-install-version": "^6.0.2", "path-browserify": "^1.0.1", "prettier": "^2.7.1", @@ -217,6 +217,7 @@ "@babel/preset-typescript": "^7.18.6", "@babel/register": "^7.4.4", "@fortawesome/fontawesome-free": "^5.8.1", + "@monaco-editor/react": "4.4.5", "@nrwl/cli": "^15.7.1", "@nrwl/eslint-plugin-nx": "^15.7.1", "@nrwl/jest": "15.7.1", diff --git a/yarn.lock b/yarn.lock index 2d40823ea0..51fa83284b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6981,26 +6981,6 @@ accepts@~1.3.8: mime-types "~2.1.34" negotiator "0.6.3" -ace-mode-lexon@^1.*.*: - version "1.0.5" - resolved "https://registry.yarnpkg.com/ace-mode-lexon/-/ace-mode-lexon-1.0.5.tgz#20d18ef25e59f60002c85ae2bbcfa306f1d48b34" - integrity sha512-kn42vP48Cl+qrhAcjld1l4OjH4kdqQRL37XVI3kS+eluNZcB/0wGcIQ/44+F7Hv2tMPmsqMOnlaCCGIlBkb0Zw== - -ace-mode-move@0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/ace-mode-move/-/ace-mode-move-0.0.1.tgz#8778ec8844dc67f7a54c8aae10653ac271a2dd7a" - integrity sha512-RRckwbouhlCg1n8LQrZ87ojVdJg8FZYxa6d4ot8PNNBRKHLvJagPu/poW9mmRCW4YAGvOfrGpJpZH1kOjitj/Q== - -ace-mode-solidity@^0.1.0: - version "0.1.1" - resolved "https://registry.yarnpkg.com/ace-mode-solidity/-/ace-mode-solidity-0.1.1.tgz#a1b49c732f2bf1bfacd3b181ba0c21575a36b918" - integrity sha512-OFDYb2DpSUdY/st3o+efbBof4e3M5zFXE8p1DwXNSoeGVT5+8/3KKwX6uhkuKipZ9VgqtPDSJLNcIY1+KSsrIw== - -ace-mode-zokrates@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/ace-mode-zokrates/-/ace-mode-zokrates-1.0.4.tgz#6696a9ed8352da23eabd5904d411e50dcd278107" - integrity sha512-jLpIg+PhJTlCWKu52U/EdJPQPJez9mMB0uzvCiyHgCJsX6+FY+s7jmBDrpxGdgNdNWJPQ20/MKzOx3oUnSF27A== - acorn-es7-plugin@^1.1.7: version "1.1.7" resolved "https://registry.yarnpkg.com/acorn-es7-plugin/-/acorn-es7-plugin-1.1.7.tgz#f2ee1f3228a90eead1245f9ab1922eb2e71d336b" @@ -19563,11 +19543,6 @@ mold-source-map@~0.4.0: convert-source-map "^1.1.0" through "~2.2.7" -monaco-editor@^0.30.1: - version "0.30.1" - resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.30.1.tgz#47f8d18a0aa2264fc5654581741ab8d7bec01689" - integrity sha512-B/y4+b2O5G2gjuxIFtCE2EkM17R2NM7/3F8x0qcPsqy4V83bitJTIO4TIeZpYlzu/xy6INiY/+84BEm6+7Cmzg== - move-concurrently@^1.0.1, move-concurrently@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"