Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…poser-1 into lg-lsp
  • Loading branch information
cosmicshuai committed Nov 28, 2019
2 parents 5824cef + f68709f commit 8ff61f2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Composer/packages/lib/code-editor/src/LgEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ declare global {

async function initializeDocuments(lgOption) {
const languageClient = window.monacoLGEditorInstance;
if (languageClient && lgOption && lgOption.inline) {
if (languageClient) {
await languageClient.onReady();
languageClient.sendRequest('initializeDocuments', lgOption);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,12 @@ export class LGServer {

this.connection.onRequest((method, params) => {
if (InitializeDocumentsMethodName === method) {
const { uri, content, template } = params;
this.LGDocuments.push({ uri, content, template });
const { uri, inline = false, content, template } = params;
this.LGDocuments.push({ uri, inline, content, template });
// run diagnostic
const textDocument = this.documents.get(uri);
if (textDocument) {
setTimeout(() => {
this.validate(textDocument);
}, 500);
this.validate(textDocument);
}
}
});
Expand All @@ -98,8 +96,9 @@ export class LGServer {
protected getLGDocumentContent(document: TextDocument): string {
const LGDocument = this.LGDocuments.find(item => item.uri === document.uri);
const text = document.getText();
if (LGDocument) {
if (LGDocument && LGDocument.inline) {
const { content, template } = LGDocument;
if (!content || !template) return text;
const updatedTemplate = {
Name: template.Name,
Parameters: template.Parameters,
Expand Down Expand Up @@ -313,9 +312,15 @@ export class LGServer {
let lineOffset = 0;
const LGDocument = this.getLGDocument(document);

// uninitialized
if (!LGDocument) {
return;
}

// if inline editor, concat new content for validate
if (LGDocument) {
if (LGDocument.inline) {
const { content, template } = LGDocument;
if (!content || !template) return;
const updatedTemplate = {
Name: template.Name,
Parameters: template.Parameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export interface Template {

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

export function getRangeAtPosition(document: TextDocument, position: Position): Range | undefined {
Expand Down

0 comments on commit 8ff61f2

Please sign in to comment.