How to use the botbuilder-lg.StaticChecker function in botbuilder-lg

To help you get started, we’ve selected a few botbuilder-lg 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 microsoft / botbuilder-tools / packages / LGvscodeExt / src / providers / diagnostics.ts View on Github external
function updateDiagnostics(document: vscode.TextDocument, collection: vscode.DiagnosticCollection): void {
    // special case
    if(document.fileName.endsWith('.git')) {
        return;
    }
    
	if (util.isLgFile(document.fileName)) {
        var diagnostics = new StaticChecker().checkFile(document.uri.fsPath);
        var vscodeDiagnostics: vscode.Diagnostic[] = [];
        const confDiagLevel = vscode.workspace.getConfiguration().get('LG.Expression.ignoreUnknownFunction');
        const confCustomFuncListSetting: string = vscode.workspace.getConfiguration().get('LG.Expression.customFunctionList');
        var customFunctionList: string[] = [];
        if (confCustomFuncListSetting.length >= 1) {
            customFunctionList = confCustomFuncListSetting.split(",").map(u => u.trim());
        }
        diagnostics.forEach(u => {
            const isUnkownFuncDiag: boolean = u.message.includes("it's not a built-in function or a customized function in expression");
            if (isUnkownFuncDiag === true){
                let ignored = false;
                const funcName = extractFuncName(u.message);
                console.log(funcName);
                if (customFunctionList.includes(funcName)) {
                    ignored = true;
                } else {
github microsoft / BotFramework-Composer / Composer / packages / lib / indexers / src / lgIndexer.ts View on Github external
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { LGParser, StaticChecker, DiagnosticSeverity, Diagnostic } from 'botbuilder-lg';
import get from 'lodash/get';

import { FileInfo, LgFile, LgTemplate } from './type';
import { getBaseName } from './utils/help';

const lgStaticChecker = new StaticChecker();

function index(files: FileInfo[]): LgFile[] {
  if (files.length === 0) return [];
  const lgFiles: LgFile[] = [];
  for (const file of files) {
    if (file.name.endsWith('.lg')) {
      const diagnostics = lgStaticChecker.checkText(file.content, file.path);
      let templates: LgTemplate[] = [];
      try {
        templates = parse(file.content, '');
      } catch (err) {
        console.error(err);
      }
      lgFiles.push({
        id: getBaseName(file.name, '.lg'),
        relativePath: file.relativePath,
github microsoft / BotFramework-Composer / Composer / packages / tools / language-servers / lg / server / src / lg-server.ts View on Github external
protected doValidate(document: TextDocument): void {
    if (document.getText().length === 0) {
      this.cleanDiagnostics(document);
      return;
    }
    //const jsonDocument = this.getJSONDocument(document);
    // this.jsonService.doValidation(document, jsonDocument).then(diagnostics =>
    //     this.sendDiagnostics(document, diagnostics)
    // );
    let text = document.getText();
    const staticChercher = new lg.StaticChecker();
    const lgDiags = staticChercher.checkText(text, '', lg.ImportResolver.fileResolver);
    let diagnostics: Diagnostic[] = [];
    lgDiags.forEach(diag => {
      let diagnostic: Diagnostic = {
        severity: this.convertSeverity(diag.Severity),
        range: {
          start: Position.create(diag.Range.Start.Line, diag.Range.Start.Character),
          end: Position.create(diag.Range.End.Line, diag.Range.End.Character),
        },
        message: diag.Message,
        source: document.uri,
      };
      diagnostics.push(diagnostic);
    });

    this.sendDiagnostics(document, diagnostics);
github microsoft / BotFramework-Composer / Composer / packages / tools / language-servers / lg-language-server / lib / server.js View on Github external
doValidate(document) {
    if (document.getText().length === 0) {
      this.cleanDiagnostics(document);
      return;
    }
    //const jsonDocument = this.getJSONDocument(document);
    // this.jsonService.doValidation(document, jsonDocument).then(diagnostics =>
    //     this.sendDiagnostics(document, diagnostics)
    // );
    let text = document.getText();
    const staticChercher = new lg.StaticChecker();
    const lgDiags = staticChercher.checkText(text, '', lg.ImportResolver.fileResolver);
    let diagnostics = [];
    lgDiags.forEach(diag => {
      let diagnostic = {
        severity: utils_1.convertSeverity(diag.Severity),
        range: {
          start: vscode_languageserver_types_1.Position.create(diag.Range.Start.Line - 1, diag.Range.Start.Character),
          end: vscode_languageserver_types_1.Position.create(diag.Range.End.Line - 1, diag.Range.End.Character),
        },
        message: diag.Message,
        source: document.uri,
      };
      diagnostics.push(diagnostic);
    });
    this.sendDiagnostics(document, diagnostics);
  }
github microsoft / BotFramework-Composer / Composer / packages / client / src / utils / lgUtil.ts View on Github external
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/**
 * lgUtil.ts is a single place use lg-parser handle lg file operation.
 * it's designed have no state, input text file, output text file.
 *
 */

import { LGParser, StaticChecker, DiagnosticSeverity, ImportResolver, Diagnostic, LGTemplate } from 'botbuilder-lg';
import get from 'lodash/get';

const lgStaticChecker = new StaticChecker();

const lgImportResolver = ImportResolver.fileResolver;

export interface Template {
  name: string;
  parameters?: string[];
  body: string;
}

export function isValid(diagnostics: Diagnostic[]): boolean {
  return diagnostics.every(d => d.severity !== DiagnosticSeverity.Error);
}

export function check(content: string, id = ''): Diagnostic[] {
  return lgStaticChecker.checkText(content, id, lgImportResolver);
}
github microsoft / BotFramework-Composer / Composer / packages / tools / language-servers / language-generation / src / utils.ts View on Github external
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { TextDocument, Range, Position, DiagnosticSeverity, Diagnostic } from 'vscode-languageserver-types';
import {
  LGResource,
  LGParser,
  DiagnosticSeverity as LGDiagnosticSeverity,
  ImportResolver,
  Diagnostic as LGDiagnostic,
  StaticChecker,
} from 'botbuilder-lg';
import get from 'lodash/get';

const staticChecker = new StaticChecker();

export interface Template {
  Name: string;
  Parameters?: string[];
  Body: string;
}

export interface LGDocument {
  uri: string;
  inline: boolean;
  content?: string;
  template?: Template;
}

export function getRangeAtPosition(document: TextDocument, position: Position): Range | undefined {
  const text = document.getText();
github microsoft / BotFramework-Composer / Composer / packages / tools / language-servers / language-generation / src / server.ts View on Github external
protected doValidate(document: TextDocument): void {
    if (document.getText().length === 0) {
      this.cleanDiagnostics(document);
      return;
    }

    let text = document.getText();
    const staticChercher = new lg.StaticChecker();
    const lgDiags = staticChercher.checkText(text, '', lg.ImportResolver.fileResolver);
    let diagnostics: Diagnostic[] = [];
    lgDiags.forEach(diag => {
      let diagnostic: Diagnostic = {
        severity: convertSeverity(diag.Severity),
        range: {
          start: Position.create(diag.Range.Start.Line - 1, diag.Range.Start.Character),
          end: Position.create(diag.Range.End.Line - 1, diag.Range.End.Character),
        },
        message: diag.Message,
        source: document.uri,
      };
      diagnostics.push(diagnostic);
    });

    this.sendDiagnostics(document, diagnostics);