Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
f2b65d7
Keep track of modifiers for callables and types
Jan 22, 2020
14e89cf
Make Modifiers a struct so serialization works
Jan 22, 2020
99a5731
Remove runtime tests until compiler version is updated
Jan 22, 2020
0bbbba5
Add converter and update serialization test
Jan 23, 2020
0b02a69
Update transformation and walker
Jan 23, 2020
088d7c5
Move modifiers out of the signatures
Jan 24, 2020
5b9a9e5
Fix attribute reader test
Jan 24, 2020
d0a4bd8
Undo superfluous changes
Jan 24, 2020
88a3e83
Update documentation for DefaultAccess
Jan 24, 2020
2bea882
Merge branch 'features/access-modifiers' into marshallsa/access-modif…
bamarsha Jan 24, 2020
4ec6574
Re-enable execution tests
Jan 27, 2020
77acec7
Merge branch 'marshallsa/access-modifiers' of https://github.com/micr…
Jan 27, 2020
122d7e8
Merge pull request #292 from microsoft/marshallsa/access-modifiers
bamarsha Jan 27, 2020
eb43e6d
Add parsing for access modifiers
Jan 28, 2020
0556439
Update syntax highlighting for private and internal
Jan 29, 2020
c5f90db
Add TODOs for parsing the final syntax
Jan 29, 2020
32f6e9b
Fix code style for creating modifiers record
Jan 29, 2020
cd40ab9
Merge pull request #295 from microsoft/marshallsa/access-modifier-par…
bamarsha Jan 29, 2020
3ef2013
Parse modifiers before fragment headers
Jan 30, 2020
09b5f70
Include modifiers in the fragment header parser
Jan 31, 2020
16bc448
Move private/internal to a separate list
Jan 31, 2020
56cbb57
Make getFragments a normal value
Jan 31, 2020
c757cc4
Remove let rec from fragment parsers
Jan 31, 2020
f0ab980
Merge branch 'features/access-modifiers' into marshallsa/access-modif…
bamarsha Jan 31, 2020
5514bb1
Move fragment header consistency check to do-block
Jan 31, 2020
dbc1fe3
Merge branch 'marshallsa/access-modifier-parsing-2' of https://github…
Jan 31, 2020
e697813
Merge pull request #298 from microsoft/marshallsa/access-modifier-par…
bamarsha Jan 31, 2020
4374c13
Add access modifiers to code completion
Feb 3, 2020
c26c93f
Include modifiers in code completion tests
Feb 3, 2020
cef7da9
optR makes more sense this way
Feb 3, 2020
4819127
Merge pull request #305 from microsoft/marshallsa/access-modifiers-co…
bamarsha Feb 4, 2020
9e48013
Fix fragment being created without consuming input
Feb 4, 2020
5d42a27
Merge pull request #306 from microsoft/marshallsa/modifier-empty-frag…
bamarsha Feb 5, 2020
01a5bd6
Check for access when resolving callables
Feb 7, 2020
03ec339
Check access when resolving types
Feb 8, 2020
82a18b1
Add error code for inaccessible type in a qualified symbol
Feb 10, 2020
96d6161
Show specific error message for inaccessible type in open NS
Feb 11, 2020
e1794ec
Add custom error message for inaccessible callable (unqualified) - ne…
Feb 12, 2020
f9f9565
Show specific error message for inaccessible qualified callables
Feb 12, 2020
0ea94f9
Rename ContainsCallable/Type to TryFindCallable/Type
Feb 12, 2020
d948529
Make errors for using less accessible types in more accessible declar…
Feb 14, 2020
3962538
Reword description of Ambiguous
Feb 14, 2020
990c76e
Update comments for NamespacesContaining{Callable, Type}
Feb 14, 2020
2335e06
Merge pull request #313 from microsoft/marshallsa/access-modifier-res…
bamarsha Feb 14, 2020
9bfefb3
Merge branch 'features/access-modifiers' into marshallsa/access-type-…
Feb 14, 2020
df315a4
Clarify checkUdt parameter in doc comment
Feb 14, 2020
1544c38
Update src/QsCompiler/Core/SymbolTable.fs
bamarsha Feb 15, 2020
e234937
NonSupportedException -> NotSupportedException
Feb 15, 2020
e0fe45f
Merge pull request #318 from microsoft/marshallsa/access-type-checking
bamarsha Feb 15, 2020
1507a5e
Add tests for access modifiers
Feb 18, 2020
d985c9b
Add a few more tests
Feb 19, 2020
214e6e8
Add tests for access modifiers in a referenced assembly
Feb 19, 2020
74f456a
Update access modifiers test namespace
Feb 19, 2020
fdd0bff
Skip access modifier tests for now
Feb 19, 2020
1dae005
Add tests for type constructor accessibility
Feb 19, 2020
1dc0f72
Re-enable tests except for redeclarations of references
Feb 20, 2020
43539b6
Replace tabs with spaces
Feb 20, 2020
bf7057c
Use more descriptive names
Feb 20, 2020
6a8a48e
Merge pull request #320 from microsoft/marshallsa/access-modifier-tests
bamarsha Feb 20, 2020
9d544b9
Add access modifiers to hover information
Feb 21, 2020
8fd37f2
Add access modifiers to Q# code output
Feb 21, 2020
9185064
Merge pull request #324 from microsoft/marshallsa/modifiers-in-hover-…
bamarsha Feb 21, 2020
5a3c7b1
Merge branch 'features/access-modifiers' into marshallsa/modifiers-qs…
bamarsha Feb 21, 2020
0287542
Merge pull request #325 from microsoft/marshallsa/modifiers-qs-code-o…
bamarsha Feb 21, 2020
8b09d3c
Add test for skipping inaccessible items in documentation
Feb 22, 2020
001a27e
Merge branch 'features/access-modifiers' into marshallsa/docgen-hide-…
Feb 22, 2020
d4b8949
Skip private and internal items when generating documentation
Feb 22, 2020
7481a69
Add copyright headers
Feb 22, 2020
e13d62c
Add doc comment for new test
Feb 22, 2020
9d02420
Clarify doc comment for WriteToStream
Feb 22, 2020
b386eaf
Merge pull request #326 from microsoft/marshallsa/docgen-hide-inacces…
bamarsha Feb 22, 2020
c7b512f
Hide inaccessible callables and types from code completion
Feb 24, 2020
267413b
Update namespace suggestion code actions for access modifiers
Feb 25, 2020
3c0cdb1
Add QsNullable.Bind
Feb 25, 2020
53f6ca4
Refactor this if statement a little
Feb 25, 2020
c67c34e
Merge pull request #334 from microsoft/marshallsa/code-completion-access
bamarsha Feb 25, 2020
6742ba5
Merge branch 'features/access-modifiers' into marshallsa/code-actions…
bamarsha Feb 25, 2020
9c721d4
Move nsName == null check earlier
Feb 25, 2020
aaf1018
Update doc comments for namespace suggestions
Feb 26, 2020
5929fc2
Merge pull request #337 from microsoft/marshallsa/code-actions-access
bamarsha Feb 26, 2020
84fadb9
Update symbol table documentation for access modifiers
Feb 26, 2020
a4f5b39
Merge pull request #343 from microsoft/marshallsa/symbol-table-docs
bamarsha Feb 27, 2020
1b8768e
Merge branch 'master' into marshallsa/access-modifiers-master-update
Feb 27, 2020
4ba4dbd
Merge branch 'features/access-modifiers' into marshallsa/access-modif…
bamarsha Feb 27, 2020
0cf75fc
Merge pull request #349 from microsoft/marshallsa/access-modifiers-ma…
bamarsha Feb 27, 2020
190a8f2
Remove the private access modifier
Mar 9, 2020
d44ecd3
Move internal keyword to operations syntax group
Mar 11, 2020
15ea32e
Move "References" tests to other test groups
Mar 11, 2020
9e67854
Merge pull request #361 from microsoft/marshallsa/remove-private
bamarsha Mar 12, 2020
1f29282
Allow shadowing imported internal callables
Mar 13, 2020
9916982
Mangle names in CompilationUnit.Build
Mar 13, 2020
7d31d30
Add TODO about reversing name mangling
Mar 13, 2020
93190f4
Update comments about accessibility in Namespace class
Mar 13, 2020
5ed2a27
Check partial NS before ref in TryAddCallableSpecialization
Mar 13, 2020
4de466d
Skip calling FromSingleSource in NS.TryFindCallable
Mar 13, 2020
486ddd6
Allow shadowing imported internal types
Mar 13, 2020
493327b
Enable redeclaration test
Mar 13, 2020
c43a078
Remove unused functions
Mar 13, 2020
77c748e
Check source then references in TryGetAttributeDeclaredIn
Mar 13, 2020
4a38476
Fix bug in PossibleQualifications
Mar 14, 2020
9b614ae
Fix bug in resolveInOpenNamespaces
Mar 14, 2020
7c0e5e4
Re-enable exception in SpecializationsDefinedInAllSources
Mar 14, 2020
05b2b2a
Re-enable assertion about external specializations
Mar 14, 2020
f45eb97
Add name mangling tests
Mar 14, 2020
7bbd6aa
Add test for using same internal name in multiple references
Mar 14, 2020
11ecd75
No diagnostics for "conflicting" internal names
Mar 14, 2020
9c5284c
Move ResolutionResult to SymbolResolution.fs
Mar 14, 2020
d05003f
Add comment about name tagging
Mar 14, 2020
d0162cd
Use Library2 instead of Library1Copy
Mar 14, 2020
665c6f5
Ignore async tasks instead of waiting
Mar 14, 2020
29b80d5
Disable multiple reference test
Mar 14, 2020
f197dc2
Use PascalCase in ResolutionResult module
Mar 15, 2020
eb27b21
Check if source is in references dictionary
Mar 15, 2020
9a74258
Use reversible name mangling
Mar 15, 2020
293b16a
Add missing doc comments
Mar 15, 2020
2c1c994
Add missing underscores
Mar 15, 2020
5e01a0a
Remove unnecessary thunking
Mar 15, 2020
7d5ebfa
Remove unnecessary nullability
Mar 15, 2020
4b9ee1a
Add test for grouping internal specializations
Mar 15, 2020
e7990a8
Refactor creating references
Mar 15, 2020
5a6cd36
Skip test for now
Mar 15, 2020
85fc5e3
Pulling in changes from PR 358 (#375)
bettinaheim Mar 16, 2020
a529fc5
Bringing over change from PR #360; avoid shadowing
Mar 16, 2020
6861418
Merge pull request #370 from microsoft/marshallsa/rename-later
bamarsha Mar 16, 2020
9ee21d8
Re-enable multiple internal references test
Mar 16, 2020
d11d895
Update symbol table
Mar 16, 2020
7e3a656
Group specializations by source file
Mar 16, 2020
4a15dcd
Fix alignment
Mar 16, 2020
ec84fa1
Only group specializations by source if callable is internal
Mar 17, 2020
75e4648
Re-add explicit this
Mar 17, 2020
4e2675a
Merge pull request #376 from microsoft/marshallsa/many-internal-refer…
bamarsha Mar 17, 2020
10cc84c
getting updates from master
Mar 17, 2020
cfeb0b8
Merge branch 'master' into beheim/access-modifiers
Mar 17, 2020
a47b302
Undo checks for current NS in code actions/completion
Mar 17, 2020
6ab8bf9
Check if methodDecl is null
Mar 17, 2020
044b7e9
Merge pull request #379 from microsoft/marshallsa/undo-editor-support…
bamarsha Mar 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/QsCompiler/CommandLineTool/LoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Microsoft.Quantum.QsCompiler
public class LoadContext : AssemblyLoadContext
{
public readonly string PathToParentAssembly;
private AssemblyDependencyResolver _Resolver;
private readonly AssemblyDependencyResolver _Resolver;
private readonly HashSet<string> _FallbackPaths;

/// <summary>
Expand Down Expand Up @@ -111,7 +111,7 @@ private Assembly OnResolving(AssemblyLoadContext context, AssemblyName name)
return path == null ? null : LoadFromAssemblyPath(path);
}

private static ConcurrentBag<LoadContext> Loaded =
private static readonly ConcurrentBag<LoadContext> Loaded =
new ConcurrentBag<LoadContext>();

/// <summary>
Expand Down
188 changes: 156 additions & 32 deletions src/QsCompiler/CompilationManager/CompilationUnit.cs

Large diffs are not rendered by default.

64 changes: 45 additions & 19 deletions src/QsCompiler/CompilationManager/EditorSupport/CodeActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Quantum.QsCompiler.Diagnostics;
using Microsoft.Quantum.QsCompiler.SyntaxProcessing;
using Microsoft.Quantum.QsCompiler.SyntaxTokens;
using Microsoft.Quantum.QsCompiler.SyntaxTree;
using Microsoft.Quantum.QsCompiler.TextProcessing;
using Microsoft.Quantum.QsCompiler.Transformations.QsCodeOutput;
using Microsoft.VisualStudio.LanguageServer.Protocol;
Expand Down Expand Up @@ -38,9 +39,13 @@ private static WorkspaceEdit GetWorkspaceEdit(this FileContentManager file, para
}

/// <summary>
/// Returns all namespaces in which a callable with the name of the symbol at the given position in the given file belongs to.
/// Returns an empty collection if any of the arguments is null or if no unqualified symbol exists at that location.
/// Returns the name of the identifier as out parameter if an unqualified symbol exists at that location.
/// Returns all namespaces in which a callable with the name of the symbol at the given position in the given
/// file belongs to.
///
/// Returns an empty collection if any of the arguments is null, if no unqualified symbol exists at that
/// location, or if the position is not part of a namespace.
///
/// Returns the name of the identifier as an out parameter if an unqualified symbol exists at that location.
/// </summary>
private static IEnumerable<NonNullable<string>> NamespaceSuggestionsForIdAtPosition
(this FileContentManager file, Position pos, CompilationUnit compilation, out string idName)
Expand All @@ -53,9 +58,13 @@ private static IEnumerable<NonNullable<string>> NamespaceSuggestionsForIdAtPosit
}

/// <summary>
/// Returns all namespaces in which a type with the name of the symbol at the given position in the given file belongs to.
/// Returns an empty collection if any of the arguments is null or if no unqualified symbol exists at that location.
/// Returns the name of the type as out parameter if an unqualified symbol exists at that location.
/// Returns all namespaces in which a type with the name of the symbol at the given position in the given file
/// belongs to.
///
/// Returns an empty collection if any of the arguments is null, if no unqualified symbol exists at that
/// location, or if the position is not part of a namespace.
///
/// Returns the name of the type as an out parameter if an unqualified symbol exists at that location.
/// </summary>
private static IEnumerable<NonNullable<string>> NamespaceSuggestionsForTypeAtPosition
(this FileContentManager file, Position pos, CompilationUnit compilation, out string typeName)
Expand Down Expand Up @@ -233,9 +242,9 @@ static string CharacteristicsAnnotation(Characteristics c)
static IEnumerable<Characteristics> GetCharacteristics(QsTuple<Tuple<QsSymbol, QsType>> argTuple) =>
SyntaxGenerator.ExtractItems(argTuple).SelectMany(item => item.Item2.ExtractCharacteristics()).Distinct();
var characteristicsInFragment =
fragment?.Kind is QsFragmentKind.FunctionDeclaration function ? GetCharacteristics(function.Item2.Argument) :
fragment?.Kind is QsFragmentKind.OperationDeclaration operation ? GetCharacteristics(operation.Item2.Argument) :
fragment?.Kind is QsFragmentKind.TypeDefinition type ? GetCharacteristics(type.Item2) :
fragment?.Kind is QsFragmentKind.FunctionDeclaration function ? GetCharacteristics(function.Item3.Argument) :
fragment?.Kind is QsFragmentKind.OperationDeclaration operation ? GetCharacteristics(operation.Item3.Argument) :
fragment?.Kind is QsFragmentKind.TypeDefinition type ? GetCharacteristics(type.Item3) :
Enumerable.Empty<Characteristics>();

//var symbolInfo = file.TryGetQsSymbolInfo(d.Range.Start, false, out var fragment);
Expand Down Expand Up @@ -294,10 +303,25 @@ static IEnumerable<Characteristics> GetCharacteristics(QsTuple<Tuple<QsSymbol, Q
internal static IEnumerable<(string, WorkspaceEdit)> SuggestionsForIndexRange
(this FileContentManager file, CompilationUnit compilation, LSP.Range range)
{
if (file == null || compilation == null || range?.Start == null) return Enumerable.Empty<(string, WorkspaceEdit)>();
var indexRangeNamespaces = compilation.GlobalSymbols.NamespacesContainingCallable(BuiltIn.IndexRange.FullName.Name);
if (!indexRangeNamespaces.Contains(BuiltIn.IndexRange.FullName.Namespace)) return Enumerable.Empty<(string, WorkspaceEdit)>();
var suggestedOpenDir = file.OpenDirectiveSuggestions(range.Start.Line, BuiltIn.IndexRange.FullName.Namespace);
if (file == null || compilation == null || range?.Start == null)
{
return Enumerable.Empty<(string, WorkspaceEdit)>();
}

// Ensure that the IndexRange library function exists in this compilation unit.
var nsName = file.TryGetNamespaceAt(range.Start);
if (nsName == null)
{
return Enumerable.Empty<(string, WorkspaceEdit)>();
}
var indexRange = compilation.GlobalSymbols.TryGetCallable(
new QsQualifiedName(BuiltIn.IndexRange.FullName.Namespace, BuiltIn.IndexRange.FullName.Name),
NonNullable<string>.New(nsName),
file.FileName);
if (!indexRange.IsFound)
{
return Enumerable.Empty<(string, WorkspaceEdit)>();
}

/// Returns true the given expression is of the form "0 .. Length(args) - 1",
/// as well as the range of the entire expression and the argument tuple "(args)" as out parameters.
Expand Down Expand Up @@ -343,8 +367,9 @@ static IEnumerable<TextEdit> IndexRangeEdits(CodeFragment fragment)

var fragments = file.FragmentsOverlappingWithRange(range);
var edits = fragments.SelectMany(IndexRangeEdits);
return edits.Any()
? new[] { ("Use IndexRange to iterate over indices.", file.GetWorkspaceEdit(suggestedOpenDir.Concat(edits).ToArray())) }
var suggestedOpenDir = file.OpenDirectiveSuggestions(range.Start.Line, BuiltIn.IndexRange.FullName.Namespace);
return edits.Any()
? new[] { ("Use IndexRange to iterate over indices.", file.GetWorkspaceEdit(suggestedOpenDir.Concat(edits).ToArray())) }
: Enumerable.Empty<(string, WorkspaceEdit)>();
}

Expand Down Expand Up @@ -437,10 +462,11 @@ static bool EmptyOrFirstAttribute(IEnumerable<CodeFragment> line, out CodeFragme
var docString = $"{docPrefix}# Summary{endLine}{docPrefix}{endLine}";

var (argTuple, typeParams) =
callableDecl.IsValue ? (callableDecl.Item.Item2.Item2.Argument, callableDecl.Item.Item2.Item2.TypeParameters) :
typeDecl.IsValue ? (typeDecl.Item.Item2, ImmutableArray<QsSymbol>.Empty) :
(null, ImmutableArray<QsSymbol>.Empty);
var hasOutput = callableDecl.IsValue && !callableDecl.Item.Item2.Item2.ReturnType.Type.IsUnitType;
callableDecl.IsValue ? (callableDecl.Item.Item2.Item3.Argument,
callableDecl.Item.Item2.Item3.TypeParameters)
: typeDecl.IsValue ? (typeDecl.Item.Item2.Item2, ImmutableArray<QsSymbol>.Empty)
: (null, ImmutableArray<QsSymbol>.Empty);
var hasOutput = callableDecl.IsValue && !callableDecl.Item.Item2.Item3.ReturnType.Type.IsUnitType;

var args = argTuple == null ? ImmutableArray<Tuple<QsSymbol, QsType>>.Empty : SyntaxGenerator.ExtractItems(argTuple);
docString = String.Concat(
Expand Down
51 changes: 27 additions & 24 deletions src/QsCompiler/CompilationManager/EditorSupport/CodeCompletion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.Quantum.QsCompiler.CompilationBuilder.DataStructures;
using Microsoft.Quantum.QsCompiler.DataTypes;
using Microsoft.Quantum.QsCompiler.SymbolManagement;
using Microsoft.Quantum.QsCompiler.SyntaxProcessing;
using Microsoft.Quantum.QsCompiler.SyntaxTokens;
using Microsoft.Quantum.QsCompiler.SyntaxTree;
Expand Down Expand Up @@ -310,7 +311,8 @@ private static IEnumerable<CompletionItem> GetLocalCompletions(
}

/// <summary>
/// Returns completions for all callables visible given the current namespace and the list of open namespaces.
/// Returns completions for all accessible callables given the current namespace and the list of open
/// namespaces, or an empty enumerable if symbols haven't been resolved yet.
/// </summary>
/// <exception cref="ArgumentNullException">
/// Thrown when any argument except <paramref name="currentNamespace"/> is null.
Expand All @@ -331,9 +333,9 @@ private static IEnumerable<CompletionItem> GetCallableCompletions(
if (!compilation.GlobalSymbols.ContainsResolutions)
return Array.Empty<CompletionItem>();
return
compilation.GlobalSymbols.DefinedCallables()
.Concat(compilation.GlobalSymbols.ImportedCallables())
.Where(callable => IsVisible(callable.QualifiedName, currentNamespace, openNamespaces))
compilation.GlobalSymbols.AccessibleCallables()
.Where(callable =>
IsAccessibleAsUnqualifiedName(callable.QualifiedName, currentNamespace, openNamespaces))
.Select(callable => new CompletionItem()
{
Label = callable.QualifiedName.Name.Value,
Expand All @@ -348,7 +350,8 @@ private static IEnumerable<CompletionItem> GetCallableCompletions(
}

/// <summary>
/// Returns completions for all types visible given the current namespace and the list of open namespaces.
/// Returns completions for all accessible types given the current namespace and the list of open namespaces, or
/// an empty enumerable if symbols haven't been resolved yet.
/// </summary>
/// <exception cref="ArgumentNullException">
/// Thrown when any argument except <paramref name="currentNamespace"/> is null.
Expand All @@ -369,9 +372,8 @@ private static IEnumerable<CompletionItem> GetTypeCompletions(
if (!compilation.GlobalSymbols.ContainsResolutions)
return Array.Empty<CompletionItem>();
return
compilation.GlobalSymbols.DefinedTypes()
.Concat(compilation.GlobalSymbols.ImportedTypes())
.Where(type => IsVisible(type.QualifiedName, currentNamespace, openNamespaces))
compilation.GlobalSymbols.AccessibleTypes()
.Where(type => IsAccessibleAsUnqualifiedName(type.QualifiedName, currentNamespace, openNamespaces))
.Select(type => new CompletionItem()
{
Label = type.QualifiedName.Name.Value,
Expand All @@ -385,7 +387,8 @@ private static IEnumerable<CompletionItem> GetTypeCompletions(
}

/// <summary>
/// Returns completions for all named items in any type.
/// Returns completions for all named items in any accessible type, or an empty enumerable if symbols haven't
/// been resolved yet.
/// </summary>
/// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
private static IEnumerable<CompletionItem> GetNamedItemCompletions(CompilationUnit compilation)
Expand All @@ -395,8 +398,7 @@ private static IEnumerable<CompletionItem> GetNamedItemCompletions(CompilationUn

if (!compilation.GlobalSymbols.ContainsResolutions)
return Array.Empty<CompletionItem>();
return compilation.GlobalSymbols.DefinedTypes()
.Concat(compilation.GlobalSymbols.ImportedTypes())
return compilation.GlobalSymbols.AccessibleTypes()
.SelectMany(type => ExtractItems(type.TypeItems))
.Where(item => item.IsNamed)
.Select(item => new CompletionItem()
Expand Down Expand Up @@ -438,8 +440,8 @@ private static IEnumerable<CompletionItem> GetGlobalNamespaceCompletions(
}

/// <summary>
/// Returns completions for namespace aliases with the given prefix that are visible at the given position in
/// the file.
/// Returns completions for namespace aliases with the given prefix that are accessible from the given position
/// in the file.
/// <para/>
/// Note: a dot will be added after the given prefix if it is not the empty string, and doesn't already end with
/// a dot.
Expand Down Expand Up @@ -499,9 +501,9 @@ private static string TryGetDocumentation(
{
case CompletionItemKind.Function:
case CompletionItemKind.Constructor:
var callable = compilation.GlobalSymbols.TryGetCallable(
var result = compilation.GlobalSymbols.TryGetCallable(
data.QualifiedName, data.QualifiedName.Namespace, NonNullable<string>.New(data.SourceFile));
if (callable.IsNull)
if (!(result is ResolutionResult<CallableDeclarationHeader>.Found callable))
return null;
var signature = callable.Item.PrintSignature();
var documentation = callable.Item.Documentation.PrintSummary(useMarkdown);
Expand All @@ -510,15 +512,15 @@ private static string TryGetDocumentation(
var type =
compilation.GlobalSymbols.TryGetType(
data.QualifiedName, data.QualifiedName.Namespace, NonNullable<string>.New(data.SourceFile))
.Item;
return type?.Documentation.PrintSummary(useMarkdown).Trim();
as ResolutionResult<TypeDeclarationHeader>.Found;
return type?.Item.Documentation.PrintSummary(useMarkdown).Trim();
default:
return null;
}
}

/// <summary>
/// Returns the names of all namespaces that have been opened without an alias and are visible from the given
/// Returns the names of all namespaces that have been opened without an alias and are accessible from the given
/// position in the file. Returns an empty enumerator if the position is invalid.
/// </summary>
/// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
Expand Down Expand Up @@ -714,14 +716,15 @@ private static CompletionList ToCompletionList(this IEnumerable<CompletionItem>
};

/// <summary>
/// Returns true if the qualified name is visible given the current namespace and a list of open namespaces.
/// Returns true if the declaration with the given qualified name would be accessible if it was referenced using
/// its unqualified name, given the current namespace and a list of open namespaces.
/// <para/>
/// Names that start with "_" are treated as "private"; they are only visible from the namespace in which they
/// are declared.
/// Note: Names that start with "_" are treated as "private;" they are only accessible from the namespace in
/// which they are declared.
/// </summary>
private static bool IsVisible(QsQualifiedName qualifiedName,
string currentNamespace,
IEnumerable<string> openNamespaces) =>
private static bool IsAccessibleAsUnqualifiedName(QsQualifiedName qualifiedName,
string currentNamespace,
IEnumerable<string> openNamespaces) =>
openNamespaces.Contains(qualifiedName.Namespace.Value) &&
(!qualifiedName.Name.Value.StartsWith("_") || qualifiedName.Namespace.Value == currentNamespace);
}
Expand Down
30 changes: 23 additions & 7 deletions src/QsCompiler/CompilationManager/EditorSupport/EditorCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using Microsoft.Quantum.QsCompiler.CompilationBuilder.DataStructures;
using Microsoft.Quantum.QsCompiler.DataTypes;
using Microsoft.Quantum.QsCompiler.SymbolManagement;
using Microsoft.Quantum.QsCompiler.SyntaxProcessing;
using Microsoft.Quantum.QsCompiler.SyntaxTokens;
using Microsoft.Quantum.QsCompiler.SyntaxTree;
Expand Down Expand Up @@ -248,13 +249,28 @@ List<QsFunctor> FunctorApplications(ref QsExpression ex)

// extracting and adapting the relevant information for the called callable

var ns = NonNullable<string>.New(nsName);
var methodDecl = id.Item1.Symbol is QsSymbolKind<QsSymbol>.Symbol sym
? compilation.GlobalSymbols.TryResolveAndGetCallable(sym.Item, ns, file.FileName).Item1
: id.Item1.Symbol is QsSymbolKind<QsSymbol>.QualifiedSymbol qualSym
? compilation.GlobalSymbols.TryGetCallable(new QsQualifiedName(qualSym.Item1, qualSym.Item2), ns, file.FileName)
: QsNullable<CallableDeclarationHeader>.Null;
if (methodDecl.IsNull) return null;
ResolutionResult<CallableDeclarationHeader>.Found methodDecl = null;
if (id.Item1.Symbol is QsSymbolKind<QsSymbol>.Symbol sym)
{
methodDecl =
compilation.GlobalSymbols.TryResolveAndGetCallable(sym.Item,
NonNullable<string>.New(nsName),
file.FileName)
as ResolutionResult<CallableDeclarationHeader>.Found;
}
else if (id.Item1.Symbol is QsSymbolKind<QsSymbol>.QualifiedSymbol qualSym)
{
methodDecl =
compilation.GlobalSymbols.TryGetCallable(new QsQualifiedName(qualSym.Item1, qualSym.Item2),
NonNullable<string>.New(nsName),
file.FileName)
as ResolutionResult<CallableDeclarationHeader>.Found;
}

if (methodDecl == null)
{
return null;
}

var (documentation, argTuple) = (methodDecl.Item.Documentation, methodDecl.Item.ArgumentTuple);
var nrCtlApplications = functors.Where(f => f.Equals(QsFunctor.Controlled)).Count();
Expand Down
Loading