DkmInstructionSymbol[] IDkmSymbolDocumentSpanQuery.FindSymbols(DkmResolvedDocument resolvedDocument, DkmTextSpan textSpan, string text, out DkmSourcePosition[] symbolLocation) { if (resolvedDocument.Module.CompilerId.LanguageId != Guids.PythonLanguageGuid) { Debug.Fail("Non-Python module passed to FindSymbols."); throw new NotSupportedException(); } return(ModuleManager.FindSymbols(resolvedDocument, textSpan, text, out symbolLocation)); }
public static DkmInstructionSymbol[] FindSymbols(DkmResolvedDocument resolvedDocument, DkmTextSpan textSpan, string text, out DkmSourcePosition[] symbolLocation) { var sourceFileId = DkmSourceFileId.Create(resolvedDocument.DocumentName, null, null, null); var resultSpan = new DkmTextSpan(textSpan.StartLine, textSpan.StartLine, 0, 0); symbolLocation = new[] { DkmSourcePosition.Create(sourceFileId, resultSpan) }; var location = new SourceLocation(resolvedDocument.DocumentName, textSpan.StartLine); var encodedLocation = location.Encode(); return(new[] { DkmCustomInstructionSymbol.Create(resolvedDocument.Module, Guids.PythonRuntimeTypeGuid, encodedLocation, 0, encodedLocation) }); }
public static DkmResolvedDocument[] FindDocuments(DkmModule module, DkmSourceFileId sourceFileId) { DkmDocumentMatchStrength matchStrength; // Shortcut invalid modules. if (module.Name.Contains("<")) { return(new DkmResolvedDocument[0]); } if (string.Equals(module.Name, sourceFileId.DocumentName, StringComparison.OrdinalIgnoreCase)) { matchStrength = DkmDocumentMatchStrength.FullPath; } else { // Either the module path is relative, or it's absolute but on a different filesystem (i.e. remote debugging). // Walk the local filesystem up starting from source file path, matching it against the module path component // by component, stopping once __init__.py is no longer seen on the same level. The intent is to approximate // a match on module names by matching the tails of the two paths that contribute to the fully qualified names // of the modules. string sourcePath = sourceFileId.DocumentName; string modulePath = module.Name; int levels = 0; do { try { string sourceFile = Path.GetFileName(sourcePath); string moduleFile = Path.GetFileName(modulePath); if (!string.Equals(sourceFile, moduleFile, StringComparison.OrdinalIgnoreCase)) { return(new DkmResolvedDocument[0]); } sourcePath = Path.GetDirectoryName(sourcePath); modulePath = Path.GetDirectoryName(modulePath); } catch (ArgumentException) { return(new DkmResolvedDocument[0]); } ++levels; } while (File.Exists(Path.Combine(sourcePath, "__init__.py"))); matchStrength = (levels == 1) ? DkmDocumentMatchStrength.FileName : DkmDocumentMatchStrength.SubPath; } return(new[] { DkmResolvedDocument.Create(module, module.Name, null, matchStrength, DkmResolvedDocumentWarning.None, false, null) }); }
public static DkmInstructionSymbol[] FindSymbols(DkmResolvedDocument resolvedDocument, DkmTextSpan textSpan, string text, out DkmSourcePosition[] symbolLocation) { var sourceFileId = DkmSourceFileId.Create(resolvedDocument.DocumentName, null, null, null); var resultSpan = new DkmTextSpan(textSpan.StartLine, textSpan.StartLine, 0, 0); symbolLocation = new[] { DkmSourcePosition.Create(sourceFileId, resultSpan) }; var location = new SourceLocation(resolvedDocument.DocumentName, textSpan.StartLine); var encodedLocation = location.Encode(); return new[] { DkmCustomInstructionSymbol.Create(resolvedDocument.Module, Guids.PythonRuntimeTypeGuid, encodedLocation, 0, encodedLocation) }; }