private static LiveTemplateMatcher MatcherFromRule(Rule rule) { var globalRules = NList.FromArray(new Rule[0]); var scope = new TreePart.Scope(new[] { rule }.NToList(), Scopename); var st = new LiveTemplateMatcher(new GenerateTree(globalRules, new[] { scope }.NToList())); return st; }
private static LiveTemplateMatcher MatcherFromRule(Rule rule) { var globalRules = NList.FromArray(new Rule[0]); var scope = new TreePart.Scope(new[] { rule }.NToList(), Scopename); var st = new LiveTemplateMatcher(new GenerateTree(globalRules, new[] { scope }.NToList())); return(st); }
MatchingResult ILookupItem.Match(PrefixMatcher prefixMatcher, ITextControl textControl) { string prefix = prefixMatcher.Prefix; if (string.IsNullOrEmpty(prefix)) { return(null); } Log.Info("Match prefix = {0}", prefix); if (_tree == null) { Log.Error("Expand tree is null, return."); return(null); } var matcher = new LiveTemplateMatcher(_tree); var matchedScopes = _scopes.Where(s => _tree.IsScopeExist(s)).ToList(); Log.Trace("Matched scopes = {0}", string.Join(", ", matchedScopes)); if (matchedScopes.Count == 0) { return(null); } foreach (var scope in matchedScopes) { try { var matchingResult = GetMatchingResult(prefix, matcher, scope); if (matchingResult != null) { return(matchingResult); } } catch (Exception e) { Log.Error("Exception during match", e); return(null); } } return(null); }
private MatchingResult GetMatchingResult(string prefix, LiveTemplateMatcher matcher, string scopeName) { var matchResult = matcher.Match(prefix, scopeName); if (matchResult.Success) { FillText(prefix, matchResult); Log.Info("Successfull match in scope [{1}]. Return [{0}]", matchResult, scopeName); return(CreateMatchingResult(prefix)); } else if (matchResult.Suggestion != null && string.IsNullOrEmpty(matchResult.Suggestion.Tail)) { FillText(prefix, matchResult.Suggestion); Log.Info("Suggestion match in scope [{1}] with result [{0}]", matchResult, scopeName); return(CreateMatchingResult(prefix)); } else { Log.Info("No completition found for {0} in scope {1}", prefix, scopeName); return(null); } }
public void LoadTree() { _tree = new LtgParser().ParseAll(_content); _ltm = new LiveTemplateMatcher(_tree); }
public void LoadTree() { _tree = new LtgParser().ParseAll(_content); _ltm = new LiveTemplateMatcher(_tree); }
MatchingResult ILookupItem.Match(PrefixMatcher prefixMatcher, ITextControl textControl) { string prefix = prefixMatcher.Prefix; Log.Info("Match prefix = {0}", prefix); if (_tree == null || string.IsNullOrEmpty(prefix)) { Log.Error("Expand tree is null, return."); return null; } var matcher = new LiveTemplateMatcher(_tree); var matchedScopes = _scopes.Where(s => _tree.IsScopeExist(s)).ToList(); Log.Trace("Matched scopes = {0}", string.Join(", ", matchedScopes)); if (matchedScopes.Count == 0) { return null; } foreach (var scope in matchedScopes) { try { var matchingResult = GetMatchingResult(prefix, matcher, scope); if (matchingResult != null) { return matchingResult; } } catch (Exception e) { Log.Error("Exception during match", e); return null; } } return null; }
private MatchingResult GetMatchingResult(string prefix, LiveTemplateMatcher matcher, string scopeName) { var matchResult = matcher.Match(prefix, scopeName); if (matchResult.Success) { FillText(prefix, matchResult); Log.Info("Successfull match in scope [{1}]. Return [{0}]", matchResult, scopeName); return CreateMatchingResult(prefix); } else if (matchResult.Suggestion != null && string.IsNullOrEmpty(matchResult.Suggestion.Tail)) { FillText(prefix, matchResult.Suggestion); Log.Info("Suggestion match in scope [{1}] with result [{0}]", matchResult, scopeName); return CreateMatchingResult(prefix); } else { Log.Info("No completition found for {0} in scope {1}", prefix, scopeName); return null; } }
private string FillText(string prefix, LiveTemplateMatcher.MatchResult matchResult) { var matchExpand = matchResult.Expand(prefix); Log.Trace("Template text: {0}", matchExpand); if (!string.IsNullOrEmpty(matchExpand)) { _template.Text = matchExpand; _displayName = matchResult.ExpandDisplay(prefix); FillMacros(prefix, matchResult); } return matchExpand; }
private void FillMacros(string prefix, LiveTemplateMatcher.MatchResult matchResult) { _template.Fields.Clear(); var appliedRules = matchResult.ReMatchLeafs(prefix); var appliedSubsNames = new List<string>(); foreach (var subst in appliedRules.Where(ar => ar.This is LeafRule.Substitution)) { var rule = (LeafRule.Substitution)subst.This; if (!appliedSubsNames.Contains(rule.Name)) { appliedSubsNames.Add(rule.Name); var macros = rule.Macros(); if (string.IsNullOrEmpty(macros)) { macros = "complete()"; } else { macros = macros.Replace("\\0", subst.Short); } Log.Trace("Place holder macro: {0}, {1}", macros, rule.Name); _template.Fields.Add(new TemplateField(rule.Name, macros, 0)); } } }