Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Rewrite suggestions and diagnostics in LG LSP with latest LG APIs #2208

Merged
merged 25 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e281f85
init
cosmicshuai Mar 9, 2020
97c0d8a
fix importResolver
cosmicshuai Mar 9, 2020
4304dae
fix templates suggestions
cosmicshuai Mar 10, 2020
f7d5196
fix return
cosmicshuai Mar 10, 2020
869a626
Merge branch 'master' into shuwan/refactor-lg-lsp
cosmicshuai Mar 10, 2020
b65ad51
fix get all templates method
cosmicshuai Mar 10, 2020
32f849a
fix comments
cosmicshuai Mar 10, 2020
dd37778
fix test cases
cosmicshuai Mar 10, 2020
8534636
Merge branch 'master' into shuwan/refactor-lg-lsp
cosmicshuai Mar 11, 2020
dc438d3
upgrade lgParser related api
zhixzhan Mar 11, 2020
e4a62a5
Merge branch 'master' into shuwan/refactor-lg-lsp
cosmicshuai Mar 11, 2020
cf807ff
Merge branch 'master' into shuwan/refactor-lg-lsp
cosmicshuai Mar 12, 2020
6cf3ce7
fix
cosmicshuai Mar 12, 2020
c6a1993
Merge branch 'shuwan/refactor-lg-lsp' of github.com:microsoft/BotFram…
cosmicshuai Mar 12, 2020
f7b8e1f
Merge branch 'master' into shuwan/refactor-lg-lsp
cwhitten Mar 12, 2020
e535250
Merge branch 'master' into shuwan/refactor-lg-lsp
cosmicshuai Mar 13, 2020
59eb2be
Merge branch 'master' into shuwan/refactor-lg-lsp
cosmicshuai Mar 16, 2020
58688db
Merge branch 'master' into shuwan/refactor-lg-lsp
cosmicshuai Mar 17, 2020
9ac8b57
Merge branch 'master' into shuwan/refactor-lg-lsp
cosmicshuai Mar 19, 2020
ed0c4de
revert designIds
cosmicshuai Mar 19, 2020
6c1ae38
revert designIds
cosmicshuai Mar 19, 2020
f4ebb38
Merge branch 'master' into shuwan/refactor-lg-lsp
zhixzhan Mar 23, 2020
c79ef44
Merge branch 'master' into shuwan/refactor-lg-lsp
zhixzhan Mar 24, 2020
b6052fe
Merge branch 'master' into shuwan/refactor-lg-lsp
cwhitten Mar 24, 2020
d181ba8
upgrade lg api change
zhixzhan Mar 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
},
"dependencies": {
"@bfc/indexers": "*",
"botbuilder-lg": "^4.8.0-preview.106823",
"botframework-expressions": "^4.8.0-preview.106476",
"botbuilder-lg": "^4.8.0-preview-109324",
"adaptive-expressions": "^4.8.0-preview-110700",
"request-light": "^0.2.2",
"vscode-languageserver": "^5.3.0-next"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export class LGServer {
content: editorContent,
};
};

const { fileId, templateId } = this.getLGDocument(document) || {};

if (this.importResolver && fileId) {
Expand Down Expand Up @@ -214,12 +215,12 @@ export class LGServer {
let templates: LgTemplate[] = [];
try {
templates = parse(content, id);
const { imports } = LGParser.parse(content, id);
imports.forEach(({ id }) => {
const importedContent = importResolver('.', id).content;
const importedTemplates = parse(importedContent, '');
templates.push(...importedTemplates);
const lgImports = LGParser.parseText(content, id, importResolver).references;
lgImports.forEach(u => {
templates.push(...u.templates);
});

console.log(templates);
} catch (_error) {
// ignore
}
Expand Down Expand Up @@ -443,13 +444,12 @@ export class LGServer {
const range = getRangeAtPosition(document, position);
const wordAtCurRange = document.getText(range);
const endWithDot = wordAtCurRange.endsWith('.');
const lgFile = this.getLGDocument(document)?.index();
const lgFile = LGParser.parseText(document.getText(), '', this.getImportResolver(document));
if (!lgFile) {
return Promise.resolve(null);
}
const { templates } = lgFile;

const completionTemplateList: CompletionItem[] = templates.map(template => {
const completionTemplateList: CompletionItem[] = lgFile.allTemplates.map(template => {
return {
label: template.name,
kind: CompletionItemKind.Reference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@
// Licensed under the MIT License.

import { TextDocument, Range, Position, DiagnosticSeverity, Diagnostic } from 'vscode-languageserver-types';
import {
DiagnosticSeverity as LGDiagnosticSeverity,
ImportResolver,
Diagnostic as LGDiagnostic,
StaticChecker,
LGParser,
} from 'botbuilder-lg';
import { DiagnosticSeverity as LGDiagnosticSeverity, Diagnostic as LGDiagnostic, LGParser } from 'botbuilder-lg';
import { LgTemplate, Diagnostic as BFDiagnostic, offsetRange, LgFile, LgParsed } from '@bfc/indexers';

const staticChecker = new StaticChecker();

// state should map to tokenizer state
export enum LGCursorState {
ROOT = 'root',
Expand Down Expand Up @@ -123,19 +115,19 @@ export function textFromTemplate(template: Template): string {

export function checkTemplate(template: Template): LGDiagnostic[] {
const text = textFromTemplate(template);
return staticChecker.checkText(text, '', ImportResolver.fileResolver).filter(diagnostic => {
return LGParser.parseText(text, '').diagnostics.filter(diagnostic => {
// ignore non-exist references in template body.
return diagnostic.message.includes('does not have an evaluator') === false;
});
}

export function updateTemplate(content: string, name: string, body: string): string {
const resource = LGParser.parse(content);
const template = resource.templates.find(t => t.name === name);
const lgFile = LGParser.parseText(content);
const template = lgFile.templates.find(t => t.name === name);
// add if not exist
if (!template) {
return resource.addTemplate(name, [], body).toString();
return lgFile.addTemplate(name, [], body).toString();
} else {
return resource.updateTemplate(name, name, template.parameters, body).toString();
return lgFile.updateTemplate(name, name, template.parameters, body).toString();
}
}