How to use the monaco-languageclient/lib/monaco-converter.ProtocolToMonacoConverter function in monaco-languageclient

To help you get started, we’ve selected a few monaco-languageclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github influxdata / influxdb / ui / src / shared / components / FluxMonacoEditor.tsx View on Github external
import FLUXLANGID from 'src/external/monaco.flux.syntax'
import THEME_NAME from 'src/external/monaco.flux.theme'
import loadServer, {LSPServer} from 'src/external/monaco.flux.server'
import {comments, submit} from 'src/external/monaco.flux.hotkeys'
import {registerAutogrow} from 'src/external/monaco.autogrow'
import {isFlagEnabled} from 'src/shared/utils/featureFlag'

// Types
import {OnChangeScript} from 'src/types/flux'
import {EditorType} from 'src/types'

import './FluxMonacoEditor.scss'
import {editor as monacoEditor} from 'monaco-editor'
import {Diagnostic} from 'monaco-languageclient/lib/services'

const p2m = new ProtocolToMonacoConverter()

export interface EditorProps {
  script: string
  onChangeScript: OnChangeScript
  onSubmitScript?: () => void
  autogrow?: boolean
}

interface Props extends EditorProps {
  setEditorInstance?: (editor: EditorType) => void
}

const FluxEditorMonaco: FC = ({
  script,
  onChangeScript,
  onSubmitScript,
github influxdata / influxdb / ui / src / external / monaco.flux.lsp.ts View on Github external
// Libraries
import {LSPServer} from 'src/external/monaco.flux.server'
import FLUXLANGID from 'src/external/monaco.flux.syntax'
import {
  MonacoToProtocolConverter,
  ProtocolToMonacoConverter,
} from 'monaco-languageclient/lib/monaco-converter'
import {CompletionTriggerKind} from 'monaco-languageclient/lib/services'
// Types
import {MonacoType} from 'src/types'

const m2p = new MonacoToProtocolConverter(),
  p2m = new ProtocolToMonacoConverter()

export function registerCompletion(monaco: MonacoType, server: LSPServer) {
  monaco.languages.registerDocumentSymbolProvider(FLUXLANGID, {
    provideDocumentSymbols: async (model, _token) => {
      try {
        const uri = model.uri.toString()
        const symbols = await server.symbols(uri)

        return p2m.asSymbolInformations(symbols)
      } catch (e) {
        return []
      }
    },
  })

  monaco.languages.registerDocumentFormattingEditProvider(FLUXLANGID, {
github TypeFox / monaco-languageclient / examples / browser / src / client.ts View on Github external
return TextDocument.create(MODEL_URI, model.getModeId(), model.getVersionId(), model.getValue());
}

function resolveSchema(url: string): Promise {
    const promise = new Promise((resolve, reject) => {
        const xhr = new XMLHttpRequest();
        xhr.onload = () => resolve(xhr.responseText);
        xhr.onerror = () => reject(xhr.statusText);
        xhr.open("GET", url, true);
        xhr.send();
    });
    return promise;
}

const m2p = new MonacoToProtocolConverter();
const p2m = new ProtocolToMonacoConverter();
const jsonService = getLanguageService({
    schemaRequestService: resolveSchema
});
const pendingValidationRequests = new Map();

monaco.languages.registerCompletionItemProvider(LANGUAGE_ID, {
    provideCompletionItems(model, position, context, token): monaco.Thenable {
        const document = createDocument(model);
        const wordUntil = model.getWordUntilPosition(position);
        const defaultRange = new monaco.Range(position.lineNumber, wordUntil.startColumn, position.lineNumber, wordUntil.endColumn);
        const jsonDocument = jsonService.parseJSONDocument(document);
        return jsonService.doComplete(document, m2p.asPosition(position.lineNumber, position.column), jsonDocument).then((list) => {
            return p2m.asCompletionResult(list, defaultRange);
        });
    },