private List <SimpleIntentSection> ExtractSimpleIntentSections(LUFileParser.NestedIntentSectionContext parseTree) { var simpleIntentSections = new List <SimpleIntentSection>(); foreach (var subIntentDefinition in parseTree.nestedIntentBodyDefinition().subIntentDefinition()) { var simpleIntentSection = new SimpleIntentSection(subIntentDefinition.simpleIntentSection()); simpleIntentSection.Range.Start.Character = 0; simpleIntentSections.Add(simpleIntentSection); } return(simpleIntentSections); }
private static LuResource ExtractFileContent(LUFileParser.FileContext fileContent, string content, List <Error> errors) { var sections = new List <Section>(); try { var modelInfoSections = ExtractModelInfoSections(fileContent); foreach (var section in modelInfoSections) { errors.AddRange(section.Errors); } sections.AddRange(modelInfoSections); } catch (Exception err) { errors.Add( Diagnostic.BuildDiagnostic( message: $"Error happened when parsing model info section: {err.Message}")); } try { var isSectionEnabled = IsSectionEnabled(sections); var nestedIntentSections = ExtractNestedIntentSections(fileContent); foreach (var section in nestedIntentSections) { errors.AddRange(section.Errors); } if (isSectionEnabled) { sections.AddRange(nestedIntentSections); } else { foreach (var section in nestedIntentSections) { var emptyIntentSection = new SimpleIntentSection(); emptyIntentSection.Name = section.Name; emptyIntentSection.Id = $"{emptyIntentSection.SectionType}_{emptyIntentSection.Name}"; // get the end character index // this is default value // it will be reset in function extractSectionBody() var endCharacter = section.Name.Length + 2; var range = new Range { Start = section.Range.Start, End = new Position { Line = section.Range.Start.Line, Character = endCharacter } }; emptyIntentSection.Range = range; var errorMsg = $"no utterances found for intent definition: \"# {emptyIntentSection.Name}\""; var error = Diagnostic.BuildDiagnostic( message: errorMsg, range: emptyIntentSection.Range, severity: Diagnostic.WARN); errors.Add(error); sections.Add(emptyIntentSection); foreach (var subSection in section.SimpleIntentSections) { sections.Add(subSection); errors.AddRange(subSection.Errors); } } } } catch (Exception err) { errors.Add( Diagnostic.BuildDiagnostic( message: $"Error happened when parsing nested intent section: {err.Message}")); } try { var simpleIntentSections = ExtractSimpleIntentSections(fileContent); foreach (var section in simpleIntentSections) { errors.AddRange(section.Errors); } sections.AddRange(simpleIntentSections); } catch (Exception err) { errors.Add( Diagnostic.BuildDiagnostic( message: $"Error happened when parsing simple intent section: {err.Message}")); } try { var entitySections = ExtractEntitiesSections(fileContent); foreach (var section in entitySections) { errors.AddRange(section.Errors); } sections.AddRange(entitySections); } catch (Exception err) { errors.Add( Diagnostic.BuildDiagnostic( message: $"Error happened when parsing entities: {err.Message}")); } try { var newEntitySections = ExtractNewEntitiesSections(fileContent); foreach (var section in newEntitySections) { errors.AddRange(section.Errors); } sections.AddRange(newEntitySections); } catch (Exception err) { errors.Add( Diagnostic.BuildDiagnostic( message: $"Error happened when parsing new entities: {err.Message}")); } try { var importSections = ExtractImportSections(fileContent); foreach (var section in importSections) { errors.AddRange(section.Errors); } sections.AddRange(importSections); } catch (Exception err) { errors.Add( Diagnostic.BuildDiagnostic( message: $"Error happened when parsing import section: {err.Message}")); } try { var qnaSections = ExtractQnaSections(fileContent); foreach (var section in qnaSections) { errors.AddRange(section.Errors); } sections.AddRange(qnaSections); } catch (Exception err) { errors.Add( Diagnostic.BuildDiagnostic( message: $"Error happened when parsing qna section: {err.Message}")); } sections = ReconstructIntentSections(sections); ExtractSectionBody(sections, content); var result = new LuResource(sections, content, errors); return(result); }