How to use the monaco-editor/esm/vs/editor/editor.api.languages function in monaco-editor

To help you get started, we’ve selected a few monaco-editor 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 sourcegraph / sourcegraph / cmd / management-console / web / src / MonacoEditor.tsx View on Github external
.pipe(
                    map(props => [props.content, props.language]),
                    distinctUntilChanged()
                )
                .subscribe(([content, language]) => {
                    if (this.model) {
                        this.model.setValue(content)
                        monaco.editor.setModelLanguage(this.model, language)
                    }
                })
        )

        const modelUri = monaco.Uri.parse('a://b/foo.json') // a made up unique URI for our model
        const model = monaco.editor.createModel('', 'json', modelUri)

        monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
            allowComments: true,
            validate: true,
            schemas: [
                {
                    uri: 'https://fake-schema.org/critical-schema.json',
                    fileMatch: [modelUri.toString()], // associate with our model
                    schema: criticalSchema,
                },
            ],
        })

        // Create the actual Monaco editor.
        const editor = monaco.editor.create(this.ref!, {
            lineNumbers: 'on',
            automaticLayout: true,
            minimap: { enabled: false },
github DonJayamanne / pythonVSCode / src / datascience-ui / interactive-common / tokenizer.ts View on Github external
export function registerMonacoLanguage() {
    // Tell monaco about our language
    monacoEditor.languages.register({
        id: PYTHON_LANGUAGE,
        extensions: ['.py']
    });

    // Setup the configuration so that auto indent and other things work. Onigasm is just going to setup the tokenizer
    monacoEditor.languages.setLanguageConfiguration(
        PYTHON_LANGUAGE,
        {
            comments: {
                lineComment: '#',
                blockComment: ['\"\"\"', '\"\"\"']
            },
            brackets: [
                ['{', '}'],
                ['[', ']'],
                ['(', ')']
            ],
            autoClosingPairs: [
                { open: '{', close: '}' },
                { open: '[', close: ']' },
                { open: '(', close: ')' },
                { open: '"', close: '"', notIn: ['string'] },
github Inventsable / ovid-editor / src / components / monaco-adobe / monaco.js View on Github external
_getAltTypes() {
      let appName = JSON.parse(window.__adobe_cep__.getHostEnvironment())
        .appName;
      let root = decodeURI(
        window.__adobe_cep__.getSystemPath("extension")
      ).replace(/file\:\/{1,}/, "");

      monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
        // target: 1,
        allowNonTsExtensions: true,
        target: monaco.languages.typescript.ScriptTarget.CommonJS,
        noLib: true,
        allowJs: true,
        noEmit: true
      });

      monaco.languages.typescript.javascriptDefaults.addExtraLib(
        fs.readFileSync(
          `${root}/src/components/monaco-adobe/types-for-adobe/${appName}.d.ts`,
          {
            encoding: "utf-8"
          }
        ),
        `${root}/src/components/monaco-adobe/types-for-adobe/${appName}.d.ts`
github iodide-project / iodide / src / editor / components / iomd-editor / fetch-line-suggestion.js View on Github external
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";

import { FETCH_CHUNK_TYPES } from "../../state-schemas/state-schema";
import { makeSuggestionList } from "./make-suggestion-list";

const { Keyword, Snippet, File } = monaco.languages.CompletionItemKind;

export const fetchLineSuggestion = (lineSoFar, fileNames) => {
  let suggestions;
  if (lineSoFar.match(/\w+: +\w+ *= */)) {
    // if the line matches the pattern of an assignment fetch
    // then offer filename completions
    suggestions = makeSuggestionList(fileNames, File);
  } else {
    // default: offer fetch type templates
    suggestions = [
      /* eslint-disable no-template-curly-in-string */
      {
        label: "css",
        detail: "css fetch statement",
        insertText: "css: https://${1:styleSheetUrl}"
      },
github iodide-project / iodide / src / editor / components / iomd-editor / monaco-iomd-completion-provider.js View on Github external
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";

import { store } from "../../store";
import { getChunkContainingLine } from "../../iomd-tools/iomd-selection";

import {
  NONCODE_EVAL_TYPES,
  RUNNABLE_CHUNK_TYPES
} from "../../state-schemas/state-schema";
import { fetchLineSuggestion } from "./fetch-line-suggestion";
import { delimLineSuggestion } from "./delim-line-suggestion";
import { codeChunkIdentifiers } from "./code-chunk-identifiers";
import { makeSuggestionList } from "./make-suggestion-list";
import messagePasserEditor from "../../../shared/utils/redux-to-port-message-passer";

const { Field } = monaco.languages.CompletionItemKind;

export function makeIomdCompletionProvider(getState) {
  return {
    triggerCharacters: ["%"],
    provideCompletionItems: async (model, position) => {
      const { iomdChunks, languageDefinitions, notebookInfo } = getState();
      const currentChunk = getChunkContainingLine(
        iomdChunks,
        position.lineNumber
      );

      const lineSoFar = model.getValueInRange({
        startLineNumber: position.lineNumber,
        startColumn: 1,
        endLineNumber: position.lineNumber,
        endColumn: position.column
github elastic / kibana / x-pack / legacy / plugins / canvas / public / components / expression_input / expression_input.tsx View on Github external
};
      } else if (s.type === 'value') {
        return {
          label: s.text,
          kind: monacoEditor.languages.CompletionItemKind.Value,
          insertText: s.text,
          command: {
            title: 'Trigger Suggestion Dialog',
            id: 'editor.action.triggerSuggest',
          },
          range: wordRange,
        };
      } else {
        return {
          label: s.fnDef.name,
          kind: monacoEditor.languages.CompletionItemKind.Function,
          documentation: {
            value: getFunctionReferenceStr(s.fnDef),
            isTrusted: true,
          },
          insertText: s.text,
          command: {
            title: 'Trigger Suggestion Dialog',
            id: 'editor.action.triggerSuggest',
          },
          range: wordRange,
        };
      }
    });
github elastic / kibana / x-pack / legacy / plugins / canvas / public / lib / monaco_language_def.ts View on Github external
export function registerLanguage() {
  const functions = registries.browserFunctions.toArray();
  language.keywords = functions.map((fn: CanvasFunction) => fn.name);

  monaco.languages.register({ id: LANGUAGE_ID });
  monaco.languages.setMonarchTokensProvider(LANGUAGE_ID, language);
}
github taurusai / kungfu / app / src / renderer / components / Code / hint / monaco.python.hint.js View on Github external
.map(k => (
        {
            label: k,
            kind: monaco.languages.CompletionItemKind.Function,
            documentation: "",
            insertText: k,
        }
    ))
github elastic / kibana / x-pack / legacy / plugins / canvas / public / lib / monaco_language_def.ts View on Github external
export function registerLanguage() {
  const functions = registries.browserFunctions.toArray();
  language.keywords = functions.map((fn: CanvasFunction) => fn.name);

  monaco.languages.register({ id: LANGUAGE_ID });
  monaco.languages.setMonarchTokensProvider(LANGUAGE_ID, language);
}
github iodide-project / iodide / src / editor / components / iomd-editor / fetch-line-suggestion.js View on Github external
].map(itemProps => ({
      kind: Snippet,
      insertTextRules:
        monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
      ...itemProps
    }));