monaco-editor#语法格式校验#lua

// Set up the Lua language
  monaco.languages.register({ id: 'lua' });
  monaco.languages.setLanguageConfiguration('lua', {
    comments: {
      lineComment: '--',
      blockComment: ['--[[', ']]']
    }
  });

  // Define the error checking function
  const checkLuaSyntax = (code) => {
    try {
      luaparse.parse(code);
      return [];
    } catch (error) {
      return [{
        severity: monaco.MarkerSeverity.Error,
        message: error.message,
        startLineNumber: error.line,
        startColumn: error.column + 1,
        endLineNumber: error.line,
        endColumn: error.column + 2
      }];
    }
  };
  // 监听值的变化
  editor.onDidChangeModelContent(() => {
    const model = editor.getModel();
    if (model) {
      const markers = checkLuaSyntax(model.getValue());
      monaco.editor.setModelMarkers(model, 'lua', markers);
    }
  });

你可能感兴趣的:(lua,开发语言,monaco-editor)