-
Notifications
You must be signed in to change notification settings - Fork 19
Properly construct a callTip for pointers and symbols with breadcrumbs (T, [], *, etc) #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,19 +175,27 @@ do | |
|
|
||
| // Create symbols for the type suffixes such as array and | ||
| // associative array | ||
|
|
||
| // Build calltip, for the symbol | ||
| string callTip; | ||
| foreach (b; lookup.breadcrumbs[]) | ||
| { | ||
| if (b == ARRAY_SYMBOL_NAME) | ||
| callTip ~= "[]"; | ||
| else if (b == ASSOC_ARRAY_SYMBOL_NAME) | ||
| callTip ~= "[...]"; | ||
| else | ||
| callTip ~= b; | ||
| } | ||
|
|
||
| while (!lookup.breadcrumbs.empty) | ||
| { | ||
| auto back = lookup.breadcrumbs.back; | ||
| immutable bool isArr = back == ARRAY_SYMBOL_NAME; | ||
| immutable bool isAssoc = back == ASSOC_ARRAY_SYMBOL_NAME; | ||
| immutable bool isFunction = back == FUNCTION_SYMBOL_NAME; | ||
| if (back == POINTER_SYMBOL_NAME) | ||
| { | ||
| lastSuffix.isPointer = true; | ||
| lookup.breadcrumbs.popBack(); | ||
| continue; | ||
| } | ||
| if (!isArr && !isAssoc && !isFunction) | ||
| immutable bool isPointer = back == POINTER_SYMBOL_NAME; | ||
| if (!isArr && !isAssoc && !isFunction && !isPointer) | ||
| break; | ||
| immutable qualifier = isAssoc ? SymbolQualifier.assocArray : | ||
| (isFunction ? SymbolQualifier.func : SymbolQualifier.array); | ||
|
|
@@ -199,8 +207,16 @@ do | |
| lookup.breadcrumbs.popBack(); | ||
| lastSuffix.callTip = lookup.breadcrumbs.back(); | ||
| } | ||
| else if (isPointer) | ||
| { | ||
| lastSuffix.callTip = istring(callTip); | ||
| lastSuffix.isPointer = true; | ||
| } | ||
| else | ||
| { | ||
| lastSuffix.addChildren(isArr ? arraySymbols[] : assocArraySymbols[], false); | ||
| lastSuffix.callTip = istring(callTip); | ||
| } | ||
|
|
||
| if (suffix is null) | ||
| suffix = lastSuffix; | ||
|
|
@@ -246,7 +262,25 @@ do | |
| if (symbols.length > 0) | ||
| currentSymbol = symbols[0]; | ||
| else | ||
| { | ||
| // we can't resolve the type, so it's either enum/auto or a template | ||
| // let's handle that | ||
|
|
||
| // if there was known suffix, it's the type, use that | ||
| if (lastSuffix) | ||
| { | ||
| symbol.type = lastSuffix; | ||
| } | ||
|
|
||
| // other wise if the symbol has no type, then use the breadcrumb and make a symbol | ||
| // out of it, eg: 'T' | ||
| else if (!symbol.type) | ||
| { | ||
| symbol.type = SymbolAllocator.instance.make!DSymbol(part, CompletionKind.dummy, null); | ||
| symbol.ownType = true; | ||
| } | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| else | ||
|
|
@@ -277,6 +311,65 @@ do | |
| suffix.ownType = false; | ||
| symbol.type = lastSuffix; | ||
| symbol.ownType = true; | ||
|
|
||
| // if that's a pointer, then add the symbols since we built a new one | ||
| if (lastSuffix.isPointer) | ||
| { | ||
| // add symbols based on what pointer is pointing to | ||
| bool isPtr = false; | ||
| bool ptrType = false; | ||
| bool ptrArray = false; | ||
| bool ptrAA = false; | ||
|
|
||
| auto index = callTip.length; | ||
| while(index--) | ||
| { | ||
| auto c = callTip[index]; | ||
| if (c == '*') | ||
| isPtr = true; | ||
| else | ||
| { | ||
| if ((c == ')') && isPtr) | ||
| { | ||
| break; | ||
| } | ||
| else if (c == ']' && isPtr) | ||
| { | ||
| if (c > 1) | ||
| { | ||
| // TODO: if we ever put the length for static array | ||
| // this will need to be updated to support that | ||
| if(callTip[index -1] == '[') | ||
| { | ||
| ptrArray = true; | ||
| break; | ||
| } | ||
|
|
||
| // TODO: if we ever put the type name for AA | ||
| // this will need to be updated to support that | ||
| if(callTip[index -1] == '.') | ||
| { | ||
| ptrAA = true; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| ptrType = true; | ||
| break; | ||
| } | ||
| } | ||
|
Comment on lines
+327
to
+362
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mixed whitespaces with tabs here |
||
| } | ||
|
|
||
| if (ptrType) | ||
| lastSuffix.addChildren(currentSymbol.parts[], false); | ||
| else if (ptrArray) | ||
| lastSuffix.addChildren(arraySymbols[], false); | ||
| else if (ptrAA) | ||
| lastSuffix.addChildren(assocArraySymbols[], false); | ||
| } | ||
|
|
||
| if (currentSymbol is null && !remainingImports.empty) | ||
| { | ||
| // info("Deferring type resolution for ", symbol.name); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be better to iterate over the breadcrumbs (maybe make a copy) instead of iterating over the characters for stability?