public CodeModel GetCurrentModel(ProbeAppSettings appSettings, string fileName, VsText.ITextSnapshot snapshot, string reason) { #if DEBUG if (snapshot == null) { throw new ArgumentNullException("snapshot"); } #endif if (_model != null) { if (snapshot != null && _model.Snapshot.Version.VersionNumber < snapshot.Version.VersionNumber) { _model = CreatePreprocessedModel(appSettings, fileName, snapshot, reason); var ev = ModelUpdated; if (ev != null) { ev(this, new ModelUpdatedEventArgs(_model)); } } } else { _model = CreatePreprocessedModel(appSettings, fileName, snapshot, reason); var ev = ModelUpdated; if (ev != null) { ev(this, new ModelUpdatedEventArgs(_model)); } } return(_model); }
public CodeModel CreatePreprocessedModel(ProbeAppSettings appSettings, string fileName, VsText.ITextSnapshot snapshot, bool visible, string reason) { CodeSource source; IEnumerable <Preprocessor.IncludeDependency> includeDependencies = null; if (visible) { source = new CodeSource(); source.Append(snapshot.GetText(), fileName, 0, snapshot.Length, true, true, false); source.Flush(); } else { var merger = new FileMerger(); merger.MergeFile(appSettings, fileName, snapshot.GetText(), false, true); source = merger.MergedContent; includeDependencies = (from f in merger.FileNames select new Preprocessor.IncludeDependency(f, false, true, merger.GetFileContent(f))).ToArray(); } var model = CreatePreprocessedModel(appSettings, source, fileName, visible, reason, includeDependencies); model.Snapshot = snapshot; return(model); }
public IEnumerable <FunctionDropDownItem> GetFunctionDropDownList(ProbeAppSettings appSettings, string fileName, VsText.ITextSnapshot snapshot) { var model = GetMostRecentModel(appSettings, fileName, snapshot, "Function drop-down list."); var prepModel = model.PreprocessorModel; if (prepModel == null) { yield break; } foreach (var func in model.PreprocessorModel.LocalFunctions) { var def = func.Definition; if (def.EntireSpan.Length == 0) { continue; } if (!def.SourceFileName.Equals(model.FileName, StringComparison.OrdinalIgnoreCase)) { continue; } yield return(new FunctionDropDownItem { Name = def.Name, Span = new Span(def.SourceStartPos, def.SourceStartPos), EntireFunctionSpan = def.EntireSpan }); } }
public CodeFile GetCodeFile(ProbeAppSettings appSettings, CodeModel model, IEnumerable <string> parentFiles) { if (_codeFile == null) { try { Log.Debug("Processing include file: {0}", _fullPathName); var content = GetSource(appSettings); if (content == null) { return(null); } var file = new CodeFile(model); file.Parse(content, _fullPathName, parentFiles, false); _codeFile = file; } catch (Exception ex) { Log.Error(ex, "Exception when processing include file '{0}'.", _fullPathName); _codeFile = null; } _lastCheck = DateTime.Now; } return(_codeFile); }
public CodeSource GetSource(ProbeAppSettings appSettings) { if (_source == null) { try { var merger = new FileMerger(); merger.MergeFile(appSettings, _fullPathName, null, false, false); _source = merger.MergedContent; var fileInfo = new FileInfo(_fullPathName); _lastModifiedDate = fileInfo.LastWriteTime; _lastCheck = DateTime.Now; foreach (var mergeFileName in merger.FileNames) { var content = merger.GetFileContent(mergeFileName); if (content == null) { throw new InvalidOperationException("Merger content is null."); } _preMergeContent[mergeFileName.ToLower()] = content; } } catch (Exception ex) { Log.Error(ex, "Exception when attempting to read content of include file '{0}'.", _fullPathName); _source = null; } } return(_source); }
public RunForm() { _options = ProbeToolsPackage.Instance.RunOptions; _appSettings = ProbeEnvironment.CurrentAppSettings; InitializeComponent(); }
private IEnumerable <ISignature> HandleComma(VsText.ITextSnapshot snapshot, ProbeAppSettings appSettings) { ThreadHelper.ThrowIfNotOnUIThread(); var fileStore = CodeModel.FileStore.GetOrCreateForTextBuffer(_textBuffer); if (fileStore != null) { var fileName = VsTextUtil.TryGetDocumentFileName(_textBuffer); var model = fileStore.GetMostRecentModel(appSettings, fileName, snapshot, "Signature help after ','"); var modelPos = (new VsText.SnapshotPoint(snapshot, _triggerPos)).TranslateTo(model.Snapshot, VsText.PointTrackingMode.Negative).Position; var argsToken = model.File.FindDownward <ArgsToken>().Where(t => t.Span.Start < modelPos && (t.Span.End > modelPos || !t.IsTerminated)).LastOrDefault(); if (argsToken != null && argsToken.Signature != null) { var modelSpan = new VsText.SnapshotSpan(model.Snapshot, argsToken.Span.ToVsTextSpan()); var snapshotSpan = modelSpan.TranslateTo(snapshot, VsText.SpanTrackingMode.EdgeInclusive); var applicableToSpan = snapshot.CreateTrackingSpan(snapshotSpan.Span, VsText.SpanTrackingMode.EdgeInclusive, 0); yield return(CreateSignature(_textBuffer, argsToken.Signature, applicableToSpan)); foreach (var sig in argsToken.SignatureAlternatives) { yield return(CreateSignature(_textBuffer, sig, applicableToSpan)); } } } }
private void RefreshAppCombo(ProbeAppSettings appSettings) { _suppressAppChange = true; try { c_appCombo.Items.Clear(); if (appSettings.Initialized) { var currentApp = appSettings.AppName; string selectApp = null; foreach (var appName in appSettings.AllAppNames) { c_appCombo.Items.Add(appName); if (appName == currentApp) { selectApp = appName; } } if (selectApp != null) { c_appCombo.SelectedItem = selectApp; } } } finally { _suppressAppChange = false; } }
public static CodeModel CreateFullModelForPreprocessed(CodeSource source, ProbeAppSettings appSettings, FileStore store, PreprocessorModel prepModel) { var model = new CodeModel(appSettings, store); var codeFile = new CodeFile(model); model.Init(source, codeFile, prepModel.FileName, false, prepModel.DefinitionProvider); return(model); }
public static CodeModel GetStdLibModel(ProbeAppSettings appSettings) { if (_stdLibModel == null) { CreateStdLibModel(appSettings); } return(_stdLibModel); }
public CodeModel CreatePreprocessedModel(ProbeAppSettings appSettings, string fileName, VsText.ITextSnapshot snapshot, string reason) { var source = new CodeSource(); source.Append(snapshot.GetText(), fileName, 0, snapshot.Length, true, true, false); source.Flush(); var model = CreatePreprocessedModel(appSettings, source, fileName, true, reason, null); model.Snapshot = snapshot; return(model); }
public FFScanner() { _appSettings = ProbeEnvironment.CurrentAppSettings; LoadCurrentApp(); _thread = new Thread(new ThreadStart(ThreadProc)); _thread.Name = "Function File Scanner"; _thread.Priority = ThreadPriority.BelowNormal; _thread.Start(); ProbeEnvironment.AppChanged += new EventHandler(ProbeEnvironment_AppChanged); Shell.FileSaved += Shell_FileSaved; }
public void ProcessFile(ProbeAppSettings appSettings, string fileName) { if (appSettings == null) { throw new ArgumentNullException(nameof(appSettings)); } _appSettings = appSettings; _fileName = fileName; _files.Clear(); _lines.Clear(); _replace.Clear(); var mergeFileNames = _appSettings.FindLocalFiles(fileName, true).ToArray(); if (mergeFileNames.Length == 0) { _errors.Add(new CodeError(null, "No files found.")); return; } // Process the base file (don't end with "&") foreach (var baseFileName in (from f in mergeFileNames where !f.EndsWith("&") select f)) { if (!string.IsNullOrEmpty(_baseFileName)) { _errors.Add(new CodeError(null, string.Format("More than one base file found. File '{0}' is ignored.", baseFileName))); continue; } _baseFileName = baseFileName; var file = new CodeFile(baseFileName, true); _files.Add(file); AddBaseFile(file); } // Process the local files (end with "&") foreach (var localFileName in (from f in mergeFileNames where f.EndsWith("&") select f)) { if (!_files.Any(f => f.FileName.Equals(localFileName, StringComparison.OrdinalIgnoreCase))) { var file = new CodeFile(localFileName, false); _files.Add(file); MergeLocalFile(file); } } }
public string LocateIncludeFile(ProbeAppSettings appSettings, string sourceFileName, string fileName, bool searchSameDir) { if (string.IsNullOrEmpty(fileName)) { return(null); } // Check if the include file is cached. IncludeFile file = null; var fileNameLower = fileName.ToLower(); if (searchSameDir && !string.IsNullOrEmpty(sourceFileName)) { if (_sameDirIncludeFiles.TryGetValue(fileNameLower, out file)) { return(file.FullPathName); } } if (_globalIncludeFiles.TryGetValue(fileNameLower, out file)) { return(file.FullPathName); } // Search the disk in same directory. if (searchSameDir && !string.IsNullOrEmpty(sourceFileName)) { var pathName = Path.Combine(Path.GetDirectoryName(sourceFileName), fileName); if (File.Exists(pathName)) { return(Path.GetFullPath(pathName)); } } // Search the disk in global include directories. if (appSettings.Initialized) { foreach (var includeDir in appSettings.IncludeDirs) { var pathName = Path.Combine(includeDir, fileName); if (System.IO.File.Exists(pathName)) { return(Path.GetFullPath(pathName)); } } } return(null); }
private void RefreshFileTree(ProbeAppSettings appSettings) { c_fileTree.Items.Clear(); if (appSettings.Initialized) { foreach (var dir in appSettings.SourceDirs) { c_fileTree.Items.Add(CreateDirTreeViewItem(dir, true)); } } if (!string.IsNullOrEmpty(c_fileFilterTextBox.Text)) { c_fileFilterTextBox.Text = string.Empty; } }
private string GenerateCredelixSwitches(ProbeAppSettings appSettings) { var sb = new StringBuilder(); sb.Append("/P \""); sb.Append(appSettings.AppName); sb.Append('\"'); var custom = ProbeToolsPackage.Instance.ProbeExplorerOptions.CredelixArguments; if (!string.IsNullOrWhiteSpace(custom)) { sb.Append(' '); sb.Append(custom); } return(sb.ToString()); }
public CodeModel RegenerateModel(ProbeAppSettings appSettings, string fileName, VsText.ITextSnapshot snapshot, string reason) { #if DEBUG if (snapshot == null) { throw new ArgumentNullException("snapshot"); } #endif _model = CreatePreprocessedModel(appSettings, fileName, snapshot, reason); var ev = ModelUpdated; if (ev != null) { ev(this, new ModelUpdatedEventArgs(_model)); } return(_model); }
private static void CreateStdLibModel(ProbeAppSettings appSettings) { var tempStore = new FileStore(); var includeFile = tempStore.GetIncludeFile(appSettings, null, "stdlib.i", false, new string[0]); if (includeFile != null) { _stdLibModel = tempStore.CreatePreprocessedModel(appSettings, includeFile.GetSource(appSettings), includeFile.FullPathName, false, "stdlib.i model", null); } else { var blankSource = new CodeSource(); blankSource.Flush(); _stdLibModel = tempStore.CreatePreprocessedModel(appSettings, blankSource, "stdlib.i", false, "stdlib.i model (blank)", null); } _stdLibDefines = _stdLibModel.PreprocessorModel.Preprocessor.Defines.ToArray(); }
public bool TryGetApplicableToSpan(char typedChar, SnapshotPoint triggerPt, out SnapshotSpan applicableToSpan, CancellationToken token) { ThreadHelper.ThrowIfNotOnUIThread(); _mode = CompletionMode.None; _fileName = VsTextUtil.TryGetDocumentFileName(_textView.TextBuffer); _appSettings = ProbeEnvironment.CurrentAppSettings; var tracker = Classifier.TextBufferStateTracker.GetTrackerForTextBuffer(triggerPt.Snapshot.TextBuffer); var state = tracker.GetStateForPosition(triggerPt, _fileName, _appSettings); if (Classifier.State.IsInLiveCode(state)) { Match match; var line = triggerPt.Snapshot.GetLineFromPosition(triggerPt.Position); var prefix = line.GetTextUpToPosition(triggerPt); if (typedChar == ' ') { #region Assignment or Comparison if ((match = _rxAfterAssignOrCompare.Match(prefix)).Success) { _mode = CompletionMode.AfterAssignOrCompare; applicableToSpan = triggerPt.ToSnapshotSpan(); _params.str = match.Groups[1].Value; _params.pt = new SnapshotPoint(line.Snapshot, match.Groups[1].Index + line.Start.Position); return(true); } #endregion #region #ifdef else if ((match = _rxAfterIfDef.Match(prefix)).Success) { _mode = CompletionMode.AfterIfDef; applicableToSpan = triggerPt.ToSnapshotSpan(); return(true); } #endregion #region Comma else if (prefix.EndsWith(", ")) { _mode = CompletionMode.AfterComma; applicableToSpan = triggerPt.ToSnapshotSpan(); return(true); } #endregion #region order by else if ((match = _rxOrderBy.Match(prefix)).Success) { _mode = CompletionMode.AfterOrderBy; applicableToSpan = triggerPt.ToSnapshotSpan(); return(true); } #endregion #region After Word else if ((match = _rxAfterWord.Match(prefix)).Success) { switch (match.Groups[1].Value) { case "case": _mode = CompletionMode.AfterCase; applicableToSpan = triggerPt.ToSnapshotSpan(); return(true); case "extract": _mode = CompletionMode.AfterExtract; applicableToSpan = triggerPt.ToSnapshotSpan(); _params.str = match.Groups[1].Value; return(true); case "return": _mode = CompletionMode.AfterReturn; applicableToSpan = triggerPt.ToSnapshotSpan(); return(true); case "tag": _mode = CompletionMode.AfterTag; applicableToSpan = triggerPt.ToSnapshotSpan(); return(true); default: _mode = CompletionMode.AfterWord; applicableToSpan = triggerPt.ToSnapshotSpan(); _params.str = match.Groups[1].Value; _params.snapshot = triggerPt.Snapshot; return(true); } } #endregion #region After Symbol else if ((match = _rxAfterSymbol.Match(prefix)).Success) { _mode = CompletionMode.AfterSymbol; applicableToSpan = triggerPt.ToSnapshotSpan(); return(true); } #endregion #region After Number else if ((match = _rxAfterNumber.Match(prefix)).Success) { _mode = CompletionMode.AfterNumber; applicableToSpan = triggerPt.ToSnapshotSpan(); return(true); } #endregion #region After String Literal else if ((match = _rxAfterStringLiteral.Match(prefix)).Success) { _mode = CompletionMode.AfterStringLiteral; applicableToSpan = triggerPt.ToSnapshotSpan(); return(true); } #endregion } #region Table.Field else if ((match = _rxTypingTable.Match(prefix)).Success) { _mode = CompletionMode.DotSeparatedWords; applicableToSpan = new SnapshotSpan(triggerPt.Snapshot, match.Groups[2].Index + line.Start.Position, match.Groups[2].Length); _params.str = match.Groups[1].Value; _params.str2 = match.Groups[2].Value; return(true); } #endregion #region Word else if ((match = _rxTypingWord.Match(prefix)).Success) { // Typing a regular word. _mode = CompletionMode.Word; _params.pt = new SnapshotPoint(triggerPt.Snapshot, line.Start.Position + match.Index); applicableToSpan = new SnapshotSpan(_params.pt, match.Length); return(true); } #endregion #region Class function bracket else if ((match = _rxClassFunctionStartBracket.Match(prefix)).Success) { _mode = CompletionMode.ClassFunction; applicableToSpan = triggerPt.ToSnapshotSpan(); _params.str = match.Groups[1].Value; _params.str2 = match.Groups[2].Value; return(true); } #endregion #region Function bracket else if ((match = _rxFunctionStartBracket.Match(prefix)).Success) { _mode = CompletionMode.Function; applicableToSpan = triggerPt.ToSnapshotSpan(); _params.str = match.Groups[1].Value; return(true); } #endregion #region #include else if ((match = _rxAfterInclude.Match(prefix)).Success) { _mode = CompletionMode.Include; applicableToSpan = triggerPt.ToSnapshotSpan(); _params.str = match.Groups[1].Value; return(true); } #endregion } else { if ((state & State.StringLiteral_Mask) != 0) { Match match; var line = triggerPt.Snapshot.GetLineFromPosition(triggerPt.Position); var prefix = line.GetTextUpToPosition(triggerPt); #region #include (for string literal) if ((match = _rxAfterInclude.Match(prefix)).Success) { _mode = CompletionMode.Include; applicableToSpan = triggerPt.ToSnapshotSpan(); _params.str = match.Groups[1].Value; return(true); } #endregion } } applicableToSpan = new SnapshotSpan(triggerPt.Snapshot, new Span(0, 0)); return(false); }
public int GetStateForPosition(SnapshotPoint snapPt, string fileName, ProbeAppSettings appSettings) { return(GetStateForPosition(snapPt.Position, snapPt.Snapshot, fileName, appSettings)); }
private void ProbeEnvironment_AppChanged(object sender, EventArgs e) { _appSettings = ProbeEnvironment.CurrentAppSettings; LoadCurrentApp(); RestartScanning("Probe app changed"); }
public int GetStateForPosition(int pos, ITextSnapshot snapshot, string fileName, ProbeAppSettings appSettings) { _snapshot = snapshot; var line = _snapshot.GetLineFromPosition(pos); var state = GetStateForLineStart(line.LineNumber, snapshot, fileName, appSettings); var lineStartPos = line.Start.Position; var fileStore = CodeModel.FileStore.GetOrCreateForTextBuffer(snapshot.TextBuffer); if (fileStore == null) { return(0); } var model = fileStore.GetMostRecentModel(appSettings, fileName, snapshot, "GetStateForPosition"); if (lineStartPos <= pos) { var lineText = line.GetTextIncludingLineBreak(); if (pos - lineStartPos < lineText.Length) { lineText = lineText.Substring(0, pos - lineStartPos); } _scanner.SetSource(lineText, line.Start.Position, line.Snapshot, model); var tokenInfo = new ProbeClassifierScanner.TokenInfo(); while (_scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state)) { ; } } return(state); }
public FFApp(FFScanner scanner, FFDatabase db, ProbeAppSettings appSettings) { _scanner = scanner ?? throw new ArgumentNullException(nameof(scanner)); _appSettings = appSettings ?? throw new ArgumentNullException(nameof(appSettings)); if (!_appSettings.Initialized) { return; } var conn = db.Connection; if (conn == null) { return; } // Load app info using (var cmd = db.CreateCommand("select rowid from app where name = @name")) { cmd.Parameters.AddWithValue("@name", _appSettings.AppName); using (var rdr = cmd.ExecuteReader(CommandBehavior.SingleRow)) { if (rdr.Read()) { _id = rdr.GetInt64(0); } } } if (_id != 0) { // Load files var loadedFiles = new List <FFFile>(); using (var cmd = db.CreateCommand("select rowid, * from file_ where app_id = @app_id and visible != 0")) { cmd.Parameters.AddWithValue("@app_id", _id); using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { loadedFiles.Add(new FFFile(this, db, rdr)); } } } foreach (var file in loadedFiles) { file.Load(db); _files[file.FileName.ToLower()] = file; } using (var cmd = db.CreateCommand("select file_name, modified from file_ where app_id = @app_id and visible = 0")) { cmd.Parameters.AddWithValue("@app_id", _id); using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { var fileName = rdr.GetString(0); var modified = rdr.GetDateTime(1); _invisibleFiles[fileName.ToLower()] = modified; } } } } else // _id == 0 { using (var cmd = db.CreateCommand("insert into app (name) values (@name); select last_insert_rowid();")) { cmd.Parameters.AddWithValue("@name", _appSettings.AppName); _id = Convert.ToInt64(cmd.ExecuteScalar()); } var options = ProbeToolsPackage.Instance.EditorOptions; if (!options.DisableBackgroundScan) { Shell.ShowNotificationAsync(Res.FFDatabaseCreationNotification, Res.FFDatabaseCreationCaption); } } }
private CodeModel(ProbeAppSettings appSettings, FileStore store) { _appSettings = appSettings ?? throw new ArgumentNullException(nameof(appSettings)); _store = store ?? throw new ArgumentNullException(nameof(store)); }
public EnvVarList CreateMergedVarList(ProbeAppSettings app) { if (app == null) { throw new ArgumentNullException("app"); } // Create the base list of environment vars var mergedVars = new EnvVarList(); mergedVars.LoadFromEnvironment(); mergedVars["pcurrentapp"] = app.AppName; var appEnv = app as PROBEENVSRVRLib.IProbeEnvPlatform; if (appEnv != null) { _platformFolder = appEnv.Folder; mergedVars["WbdkFrameworkVersion"] = appEnv.Version; } else { _platformFolder = null; } // Add Exe paths var path = new List <string>(); var excludeExeSubDirs = new string[] { "ccdll", "ctdef", "ctdll", "ncdll", "rtdll", "scdll", "st", "stdef", "stdll", "stn" }; foreach (var exePath in app.ExeDirs) { if (!Directory.Exists(exePath)) { continue; } var helpPath = Path.Combine(exePath, "help"); if (Directory.Exists(helpPath)) { path.Add(helpPath); } path.Add(exePath); AddSubDirs(path, exePath, excludeExeSubDirs); } // Add development studio exe paths AddDevelopmentExePaths(path); // Append the current environment variable data path.AddRange(mergedVars.GetDirectoryList("path")); RemoveDuplicatePaths(path); mergedVars.SetDirectoryList("path", path, 2048); // Include paths var includes = new List <string>(); foreach (var includePath in app.IncludeDirs) { if (!Directory.Exists(includePath)) { continue; } includes.Add(includePath); } AddDevelopmentIncludePaths(includes); includes.AddRange(mergedVars.GetDirectoryList("include")); RemoveDuplicatePaths(includes); mergedVars.SetDirectoryList("include", includes); // Lib paths var libs = new List <string>(); foreach (var libPath in app.LibDirs) { if (!Directory.Exists(libPath)) { continue; } libs.Add(libPath); } AddDevelopmentLibPaths(libs); libs.AddRange(mergedVars.GetDirectoryList("lib")); RemoveDuplicatePaths(libs); mergedVars.SetDirectoryList("lib", libs); mergedVars.Sort(); return(mergedVars); }
private IEnumerable <ISignature> HandleOpenBracket(VsText.ITextSnapshot snapshot, ProbeAppSettings appSettings) { ThreadHelper.ThrowIfNotOnUIThread(); var lineText = snapshot.GetLineTextUpToPosition(_triggerPos); var match = _rxFuncBeforeBracket.Match(lineText); if (match.Success) { var line = snapshot.GetLineFromPosition(_triggerPos); var word1 = match.Groups[2].Value; var word1Start = line.Start.Position + match.Groups[2].Index; var funcName = match.Groups[3].Value; var funcNameStart = line.Start.Position + match.Groups[3].Index; var fileStore = FileStore.GetOrCreateForTextBuffer(_textBuffer); if (fileStore != null) { if (!string.IsNullOrEmpty(word1)) { VsText.ITrackingSpan applicableToSpan = null; var fileName = VsTextUtil.TryGetDocumentFileName(snapshot.TextBuffer); var model = fileStore.GetMostRecentModel(appSettings, fileName, snapshot, "Signature help after '(' - dot separated words"); var modelPos = model.AdjustPosition(word1Start, snapshot); foreach (var word1Def in model.DefinitionProvider.GetAny(modelPos, word1)) { if (!word1Def.AllowsChild) { continue; } foreach (var word2Def in word1Def.GetChildDefinitions(funcName)) { if (!word2Def.ArgumentsRequired) { continue; } if (applicableToSpan == null) { applicableToSpan = snapshot.CreateTrackingSpan(new VsText.Span(_triggerPos, 0), VsText.SpanTrackingMode.EdgeInclusive); } yield return(CreateSignature(_textBuffer, word2Def.ArgumentsSignature, applicableToSpan)); } } } else { VsText.ITrackingSpan applicableToSpan = null; var fileName = VsTextUtil.TryGetDocumentFileName(snapshot.TextBuffer); var model = fileStore.GetMostRecentModel(appSettings, fileName, snapshot, "Signature help after '('"); var modelPos = model.AdjustPosition(funcNameStart, snapshot); foreach (var def in model.DefinitionProvider.GetAny(modelPos, funcName)) { if (!def.ArgumentsRequired) { continue; } if (applicableToSpan == null) { applicableToSpan = snapshot.CreateTrackingSpan(new VsText.Span(_triggerPos, 0), VsText.SpanTrackingMode.EdgeInclusive); } yield return(CreateSignature(_textBuffer, def.ArgumentsSignature, applicableToSpan)); } } } } }
public CodeModel CreatePreprocessedModel(ProbeAppSettings appSettings, CodeSource source, string fileName, bool visible, string reason, IEnumerable <Preprocessor.IncludeDependency> includeDependencies) { #if DEBUG Log.Debug("Creating preprocessed model. Reason: {0}", reason); var startTime = DateTime.Now; #endif var reader = new CodeSource.CodeSourcePreprocessorReader(source); var prepSource = new CodeSource(); var defProvider = new DefinitionProvider(appSettings, fileName); var fileContext = FileContextUtil.GetFileContextFromFileName(fileName); var prep = new Preprocessor(appSettings, this); if (includeDependencies != null) { prep.AddIncludeDependencies(includeDependencies); } prep.Preprocess(reader, prepSource, fileName, new string[0], fileContext, stdlibDefines: _stdLibDefines); prep.AddDefinitionsToProvider(defProvider); if (fileContext == FileContext.Include && !string.IsNullOrEmpty(fileName)) { var includeParentDefs = GetIncludeParentDefinitions(appSettings, fileName); defProvider.AddGlobalFromFile(includeParentDefs); } #if DEBUG var midTime1 = DateTime.Now; #endif var prepModel = new PreprocessorModel(prepSource, defProvider, fileName, visible, prep.IncludeDependencies) { Preprocessor = prep }; #if DEBUG var midTime2 = DateTime.Now; #endif CodeModel modelToReturn; if (visible) { modelToReturn = CodeModel.CreateVisibleModelForPreprocessed(source, appSettings, this, prepModel); modelToReturn.PreprocessorModel = prepModel; modelToReturn.DisabledSections = prepSource.GenerateDisabledSections().ToArray(); } else { modelToReturn = CodeModel.CreateFullModelForPreprocessed(prepSource, appSettings, this, prepModel); modelToReturn.PreprocessorModel = prepModel; } modelToReturn.PreprocessorReferences = prep.References; #if DEBUG var endTime = DateTime.Now; var elapsedTime = endTime.Subtract(startTime).TotalMilliseconds; var prepTime = midTime1.Subtract(startTime).TotalMilliseconds; var modelTime = midTime2.Subtract(midTime1).TotalMilliseconds; var visTime = endTime.Subtract(midTime2).TotalMilliseconds; Log.Debug("Created model in {0} msecs ({1} preprocessor, {2} model, {3} visible)", elapsedTime, prepTime, modelTime, visTime); #endif return(modelToReturn); }
/// <summary> /// Returns true if the position is not inside a comment, string literal or disabled code. /// </summary> public bool IsPositionInLiveCode(int pos, ITextSnapshot snapshot, string fileName, ProbeAppSettings appSettings) { return(State.IsInLiveCode(GetStateForPosition(pos, snapshot, fileName, appSettings))); }
public IncludeFile GetIncludeFile(ProbeAppSettings appSettings, string sourceFileName, string fileName, bool searchSameDir, IEnumerable <string> parentFiles) { #if DEBUG if (parentFiles == null) { throw new ArgumentNullException("parentFiles"); } #endif if (string.IsNullOrEmpty(fileName)) { return(null); } // Check if the include file is cached. IncludeFile file = null; var fileNameLower = fileName.ToLower(); if (searchSameDir && !string.IsNullOrEmpty(sourceFileName)) { if (_sameDirIncludeFiles.TryGetValue(fileNameLower, out file)) { file.CheckForRefreshRequired(); return(file); } } if (_globalIncludeFiles.TryGetValue(fileNameLower, out file)) { file.CheckForRefreshRequired(); return(file); } // Search the disk in same directory. if (searchSameDir && !string.IsNullOrEmpty(sourceFileName)) { var pathName = Path.Combine(Path.GetDirectoryName(sourceFileName), fileName); if (File.Exists(pathName)) { if (CheckForCyclicalInclude(pathName, parentFiles)) { return(null); } file = new IncludeFile(this, pathName); _sameDirIncludeFiles[fileNameLower] = file; return(file); } } // Search the disk in global include directories. if (appSettings.Initialized) { foreach (var includeDir in appSettings.IncludeDirs) { var pathName = Path.Combine(includeDir, fileName); if (File.Exists(pathName)) { if (CheckForCyclicalInclude(pathName, parentFiles)) { return(null); } file = new IncludeFile(this, pathName); _globalIncludeFiles[fileNameLower] = file; return(file); } } } return(null); }
public Definition[] GetIncludeParentDefinitions(ProbeAppSettings appSettings, string includePathName) { Definition[] cachedDefs; if (_includeParentDefs.TryGetValue(includePathName.ToLower(), out cachedDefs)) { return(cachedDefs); } Log.Debug("Getting include file parent definitions: {0}", includePathName); IEnumerable <string> parentFileNames; using (var searcher = ProbeToolsPackage.Instance.FunctionFileScanner.CurrentApp.CreateSearcher()) { parentFileNames = searcher.GetIncludeParentFiles(includePathName, 3); // TODO: make limit configurable } Definition[] commonDefines = null; if (!parentFileNames.Any()) { Log.Debug("This file is not included by any other file."); commonDefines = new Definition[0]; _includeParentDefs[includePathName.ToLower()] = commonDefines; return(commonDefines); } foreach (var parentPathName in parentFileNames) { Log.Debug("Preprocessing include parent: {0}", parentPathName); var merger = new FileMerger(); merger.MergeFile(appSettings, parentPathName, null, false, true); var source = merger.MergedContent; var reader = new CodeSource.CodeSourcePreprocessorReader(source); var prepSource = new CodeSource(); var fileContext = FileContextUtil.GetFileContextFromFileName(parentPathName); var prep = new Preprocessor(appSettings, this); var prepResult = prep.Preprocess(reader, prepSource, parentPathName, new string[0], fileContext, includePathName); if (!prepResult.IncludeFileReached) { Log.Warning("Include file not reached when preprocessing parent.\r\nInclude File: {0}\r\nParent File: {1}", includePathName, parentPathName); continue; } var defs = prep.ActiveDefineDefinitions; if (!defs.Any()) { // No defines will be common Log.Debug("No definitions found in include parent file: {0}", parentPathName); commonDefines = new Definition[0]; break; } if (commonDefines == null) { commonDefines = defs.ToArray(); Log.Debug("{1} definition(s) found in include parent file: {0}", parentPathName, commonDefines.Length); } else { // Create array of defines common to all commonDefines = (from c in commonDefines where defs.Any(d => d.Name == c.Name) select c).ToArray(); Log.Debug("{1} definition(s) found in include parent file: {0}", parentPathName, commonDefines.Length); if (commonDefines.Length == 0) { break; } } } if (commonDefines == null) { commonDefines = new Definition[0]; } Log.Debug("Using {0} definition(s) from include parent files.", commonDefines.Length); _includeParentDefs[includePathName.ToLower()] = commonDefines; return(commonDefines); }