Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.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 },
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'] },
_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`
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}"
},
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
};
} 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,
};
}
});
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);
}
.map(k => (
{
label: k,
kind: monaco.languages.CompletionItemKind.Function,
documentation: "",
insertText: k,
}
))
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);
}
].map(itemProps => ({
kind: Snippet,
insertTextRules:
monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
...itemProps
}));