Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4a51662
init
Feb 25, 2021
ba685b4
Merge branch 'main' into shuwan/gotoDefinition
Mar 3, 2021
98b99bc
add local file go to definition
Mar 3, 2021
9141766
remove a console log
Mar 3, 2021
01a0bd3
Merge branch 'main' into shuwan/gotoDefinition
Mar 3, 2021
64e93de
fix a test
Mar 3, 2021
d266ceb
Merge branch 'shuwan/gotoDefinition' of github.com:microsoft/BotFrame…
Mar 3, 2021
753e512
Merge branch 'main' into shuwan/gotoDefinition
Mar 16, 2021
5a50c17
Merge branch 'main' into shuwan/gotoDefinition
Mar 16, 2021
36aab7c
add jump file notification
cosmicshuai Mar 16, 2021
1c48e62
Merge branch 'shuwan/gotoDefinition' of https://github.com/microsoft/…
cosmicshuai Mar 16, 2021
f7c1704
add templateId
cosmicshuai Mar 16, 2021
233224f
Merge branch 'main' into shuwan/gotoDefinition
Mar 16, 2021
83ede8b
navigate to lg template defination
liweitian Mar 16, 2021
d3af153
Merge branch 'main' into shuwan/gotoDefinition
Mar 17, 2021
88aadee
Merge branch 'main' into shuwan/gotoDefinition
Mar 17, 2021
6dc31d8
change the place of a function call
cosmicshuai Mar 17, 2021
63d2a4c
Merge branch 'main' into shuwan/gotoDefinition
Mar 18, 2021
0aceb77
Merge branch 'main' into shuwan/gotoDefinition
Mar 18, 2021
0e5134f
Merge branch 'main' into shuwan/gotoDefinition
Mar 22, 2021
0297d00
Merge branch 'main' into shuwan/gotoDefinition
Mar 22, 2021
9ea673d
navigate to lg page on client
zhixzhan Mar 22, 2021
5dfd525
Merge branch 'main' into shuwan/gotoDefinition
Mar 23, 2021
1fc177a
change to onNavigateLGPage
cosmicshuai Mar 23, 2021
4bc5587
Merge branch 'main' into shuwan/gotoDefinition
Mar 24, 2021
86d30b4
fix multilanguage go to incorrect behaviors
cosmicshuai Mar 24, 2021
71eb4d7
Merge branch 'main' into shuwan/gotoDefinition
Mar 24, 2021
3e3154c
remove a log statement
cosmicshuai Mar 25, 2021
9d76e40
Merge branch 'main' into shuwan/gotoDefinition
Mar 25, 2021
a7961aa
Merge branch 'main' into shuwan/gotoDefinition
cosmicshuai Mar 26, 2021
c7ac9ef
fix signatures
cosmicshuai Mar 26, 2021
fa4835f
Merge branch 'main' of https://github.com/microsoft/BotFramework-Comp…
sorgh Mar 27, 2021
3cec9cf
removed logs and resovled conflicts
sorgh Mar 27, 2021
a035ca6
fix types
sorgh Mar 27, 2021
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
10 changes: 10 additions & 0 deletions Composer/packages/lib/code-editor/src/lg/LgCodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import styled from '@emotion/styled';
import { EditorDidMount } from '@monaco-editor/react';
import { FluentTheme, NeutralColors } from '@uifabric/fluent-theme';
import { navigate } from '@reach/router';
Comment thread
cosmicshuai marked this conversation as resolved.
Outdated
import formatMessage from 'format-message';
import get from 'lodash/get';
import { MonacoLanguageClient, MonacoServices } from 'monaco-languageclient';
Expand Down Expand Up @@ -81,6 +82,7 @@ export const LgCodeEditor = (props: LgCodeEditorProps) => {
quickSuggestions: true,
wordBasedSuggestions: false,
folding: true,
definitions: true,
...props.options,
};

Expand Down Expand Up @@ -130,6 +132,14 @@ export const LgCodeEditor = (props: LgCodeEditorProps) => {
const disposable = languageClient.start();
connection.onClose(() => disposable.dispose());
window.monacoLGEditorInstance = languageClient;

languageClient.onReady().then(() =>
languageClient.onNotification('GotoDefinition', (result) => {
if (lgOption?.projectId) {
navigate(`/bot/${lgOption.projectId}/language-generation/${result.fileId}/edit#L=${result.line}`);
}
})
);
},
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
DocumentOnTypeFormattingParams,
FoldingRangeParams,
FoldingRange,
Location,
} from 'vscode-languageserver-protocol';
import get from 'lodash/get';
import isEqual from 'lodash/isEqual';
Expand Down Expand Up @@ -55,6 +56,8 @@ export class LGServer {
private _lgParser = new LgParser();
private _luisEntities: string[] = [];
private _lastLuContent: string[] = [];
private _lgFile: LgFile | undefined = undefined;
private _templateDefinitions: Record<string, any> = {};
constructor(
protected readonly connection: IConnection,
protected readonly getLgResources: (projectId?: string) => ResolverResource[],
Expand Down Expand Up @@ -86,13 +89,15 @@ export class LGServer {
},
hoverProvider: true,
foldingRangeProvider: true,
definitionProvider: true,
documentOnTypeFormattingProvider: {
firstTriggerCharacter: '\n',
},
},
};
});
this.connection.onCompletion(async (params) => await this.completion(params));
this.connection.onDefinition((params: TextDocumentPositionParams) => this.definitionHandler(params));
this.connection.onHover(async (params) => await this.hover(params));
this.connection.onDocumentOnTypeFormatting((docTypingParams) => this.docTypeFormat(docTypingParams));
this.connection.onFoldingRanges((foldingRangeParams: FoldingRangeParams) =>
Expand Down Expand Up @@ -126,6 +131,30 @@ export class LGServer {
this.connection.listen();
}

protected definitionHandler(params: TextDocumentPositionParams): Location | undefined {
const document = this.documents.get(params.textDocument.uri);
if (!document) {
return;
}
const wordRange = getRangeAtPosition(document, params.position);
const word = document.getText(wordRange);
const curFileResult = this._lgFile?.templates.find((t) => t.name === word);

if (curFileResult?.range) {
return Location.create(
params.textDocument.uri,
Range.create(curFileResult.range.start.line - 1, 0, curFileResult.range.end.line, 0)
);
}

const refResult = this._templateDefinitions[word];
if (refResult) {
this.connection.sendNotification('GotoDefinition', refResult);
Comment thread
cosmicshuai marked this conversation as resolved.
}

return;
}

protected foldingRangeHandler(params: FoldingRangeParams): FoldingRange[] {
const document = this.documents.get(params.textDocument.uri);
const items: FoldingRange[] = [];
Expand Down Expand Up @@ -239,13 +268,15 @@ export class LGServer {
const content = this.documents.get(uri)?.getText() || '';
// if inline mode, composite local with server resolved file.
const lgTextFiles = projectId ? this.getLgResources(projectId) : [];
this.recordTemplatesDefintions(lgTextFiles);
Comment thread
cosmicshuai marked this conversation as resolved.
Outdated
if (fileId && templateId) {
const lgTextFile = lgTextFiles.find((item) => item.id === fileId);
if (lgTextFile) {
const lgFile = await this._lgParser.parse(lgTextFile.id, lgTextFile.content, lgTextFiles);
return await this._lgParser.updateTemplate(lgFile, templateId, { body: content }, lgTextFiles);
}
}

return await this._lgParser.parse(fileId || uri, content, lgTextFiles);
};
const lgDocument: LGDocument = {
Expand All @@ -258,6 +289,28 @@ export class LGServer {
this.LGDocuments.push(lgDocument);
}

protected async recordTemplatesDefintions(lgTextFiles: any[]) {
for (const file of lgTextFiles) {
const lgTemplates = await this._lgParser.parse(file.id, file.content, lgTextFiles);
for (const template of lgTemplates.templates) {
this._templateDefinitions[template.name] = {
fileId: this.removeLocaleInId(file.id),
templateId: template.name,
line: template?.range?.start?.line,
};
}
}
}

private removeLocaleInId(fileId: string): string {
const idx = fileId.lastIndexOf('.');
if (idx !== -1) {
return fileId.substring(0, idx);
} else {
return fileId;
}
}

protected getLGDocument(document: TextDocument): LGDocument | undefined {
return this.LGDocuments.find(({ uri }) => uri === document.uri);
}
Expand Down Expand Up @@ -848,6 +901,7 @@ export class LGServer {
return;
}

this._lgFile = lgFile;
if (text.length === 0) {
this.cleanDiagnostics(document);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function getRangeAtPosition(document: TextDocument, position: Position):
const pos = position.character;
const lineText = text.split(/\r?\n/g)[line];
let match: RegExpMatchArray | null;
const wordDefinition = /[a-zA-Z0-9_/.]+/g;
const wordDefinition = /[a-zA-Z0-9_]+/g;
while ((match = wordDefinition.exec(lineText))) {
const matchIndex = match.index || 0;
if (matchIndex > pos) {
Expand Down