public void ParseModeline(int numLine) { ITextBuffer buffer = this.theView.TextBuffer; var snapshot = buffer.CurrentSnapshot; if (snapshot.LineCount <= numLine) { return; } ILanguage language = langFactory.TryCreateLanguage(snapshot); if (language == null) { return; } var firstLine = snapshot.GetLineFromLineNumber(numLine); ITextChars tc = new LineChars(firstLine); var svc = language.GetService <IFirstLineCommentParser>(); String commentText = svc.Parse(tc); if (String.IsNullOrEmpty(commentText)) { return; } PkgSource.LogInfo("Found possible modeline: {0}", commentText); var modelineParser = new ModeLineParser(); var options = modelineParser.Parse(commentText); ApplyModelines(options); }
private void ApplyModeLine(String key, String value) { PkgSource.LogInfo("Modeline: {0}={1}", key, value); if (String.IsNullOrEmpty(value)) { // assume this is a boolean option value = key.StartsWith("no") ? "false" : "true"; } Action <IWpfTextView, String> option; if (optionMap.TryGetValue(key, out option)) { option(theView, value); } }
private JObject TryRead() { try { byte[] data = this.persistSettings.Read(); if (data != null && data.Length > 0) { return(JObject.Parse(this.encoding.GetString(data))); } } catch (Exception ex) { // avoid generating a VS error if // the JSON stored is invalid. // See https://github.com/tomasr/viasfora/issues/112 PkgSource.LogError("Error loading solution user settings", ex); } return(null); }
public void AddPackageSource(string name, string location, bool trusted, Request request) { // Nice-to-have put a debug message in that tells what's going on. request.Debug("Calling '{0}::AddPackageSource' '{1}','{2}','{3}'", PackageProviderName, name, location, trusted); var pkgSource = packageSources.FirstOrDefault(each => each.name.EqualsIgnoreCase(name)); if (pkgSource != null && !request.GetOptionValue(Constants.Parameters.IsUpdate).IsTrue()) { // pkgSource already exists. // this is an error. request.Error(ErrorCategory.ResourceExists, name, Constants.Messages.PackageSourceExists, name); return; } if (pkgSource != null) { //update pkgSource.location = location; pkgSource.isTrusted = trusted; } else { // add new pkgSource = new PkgSource { name = name, location = location, isTrusted = trusted, isValidated = true }; // add to the array. packageSources = packageSources.ConcatSingleItem(pkgSource).ToArray(); } request.YieldPackageSource(pkgSource.name, pkgSource.location, pkgSource.isTrusted, true, pkgSource.isValidated); }