This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 646
Add completion items for unimported packages #497
Merged
ramya-rao-a
merged 6 commits into
microsoft:master
from
ramya-rao-a:unimported-intellisense
Oct 6, 2016
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0509883
Add completion items for unimported packages
ramya-rao-a 5ae0d10
Fix lint errors
ramya-rao-a 1e10347
Use better regex, add pkg path to suggestion doc
ramya-rao-a 5d6e3d6
Use additionalTextEdits so that 'useCodeSnippetsOnFunctionSuggest' fe…
ramya-rao-a 7b7ac12
Apply edit only if edit exists
ramya-rao-a e9d86d6
Add setting autocomplteUnimportedPackages, dont show imported pkgs
ramya-rao-a 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 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 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 |
---|---|---|
|
@@ -61,36 +61,39 @@ function askUserForImport(): Thenable<string> { | |
}); | ||
} | ||
|
||
export function getTextEditForAddImport(arg: string): vscode.TextEdit { | ||
// Import name wasn't provided | ||
if (arg === undefined) { | ||
return null; | ||
} | ||
|
||
let {imports, pkg} = parseFilePrelude(vscode.window.activeTextEditor.document.getText()); | ||
let multis = imports.filter(x => x.kind === 'multi'); | ||
if (multis.length > 0) { | ||
// There is a multiple import declaration, add to the last one | ||
let closeParenLine = multis[multis.length - 1].end; | ||
return vscode.TextEdit.insert(new vscode.Position(closeParenLine, 0), '\t"' + arg + '"\n'); | ||
} else if (imports.length > 0) { | ||
// There are only single import declarations, add after the last one | ||
let lastSingleImport = imports[imports.length - 1].end; | ||
return vscode.TextEdit.insert(new vscode.Position(lastSingleImport + 1, 0), 'import "' + arg + '"\n'); | ||
} else if (pkg && pkg.start >= 0) { | ||
// There are no import declarations, but there is a package declaration | ||
return vscode.TextEdit.insert(new vscode.Position(pkg.start + 1, 0), '\nimport (\n\t"' + arg + '"\n)\n'); | ||
} else { | ||
// There are no imports and no package declaration - give up | ||
return null; | ||
} | ||
} | ||
|
||
export function addImport(arg: string) { | ||
let p = arg ? Promise.resolve(arg) : askUserForImport(); | ||
p.then(imp => { | ||
// Import name wasn't provided | ||
if (imp === undefined) { | ||
return null; | ||
} | ||
|
||
let {imports, pkg} = parseFilePrelude(vscode.window.activeTextEditor.document.getText()); | ||
let multis = imports.filter(x => x.kind === 'multi'); | ||
if (multis.length > 0) { | ||
// There is a multiple import declaration, add to the last one | ||
let closeParenLine = multis[multis.length - 1].end; | ||
return vscode.window.activeTextEditor.edit(editBuilder => { | ||
editBuilder.insert(new vscode.Position(closeParenLine, 0), '\t"' + imp + '"\n'); | ||
}); | ||
} else if (imports.length > 0) { | ||
// There are only single import declarations, add after the last one | ||
let lastSingleImport = imports[imports.length - 1].end; | ||
return vscode.window.activeTextEditor.edit(editBuilder => { | ||
editBuilder.insert(new vscode.Position(lastSingleImport + 1, 0), 'import "' + imp + '"\n'); | ||
let edit = getTextEditForAddImport(imp); | ||
if (edit) { | ||
vscode.window.activeTextEditor.edit(editBuilder => { | ||
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. May not matter right now - but probably good to return the promise here so it get's chained into the |
||
editBuilder.insert(edit.range.start, edit.newText); | ||
}); | ||
} else if (pkg && pkg.start >= 0) { | ||
// There are no import declarations, but there is a package declaration | ||
return vscode.window.activeTextEditor.edit(editBuilder => { | ||
editBuilder.insert(new vscode.Position(pkg.start + 1, 0), '\nimport (\n\t"' + imp + '"\n)\n'); | ||
}); | ||
} else { | ||
// There are no imports and no package declaration - give up | ||
return null; | ||
} | ||
}); | ||
} | ||
} | ||
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. No need to remove final newlines. |
This file contains 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
Oops, something went wrong.
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.
arg
should beimportPackageName
?