1
0
mirror of https://github.com/golang/go synced 2024-11-05 17:06:13 -07:00
Commit Graph

14 Commits

Author SHA1 Message Date
Josh Bleecher Snyder
cc1e254c18 go.tools/astutil: delete all matching imports in DeleteImport
Fixes golang/go#8459.

LGTM=crawshaw, bradfitz
R=bradfitz, crawshaw
CC=golang-codereviews
https://golang.org/cl/128220043
2014-08-14 11:51:51 -07:00
Dmitri Shuralyov
c0060eca2c go.tools/astutil: fix edge case in DeleteImport causing merging of import sections.
The issue occurs only when deleting an import that has a blank line immediately preceding,
and other imports before that.

Currently, DeleteImport assumes there's a blank line-sized hole left behind
where the import was, and always deletes it. That blank line-sized hole is there in all cases
except the above edge case.

This fix checks for that edge case, and does not remove the blank line-sized hole.

The CL also adds a previously failing test case that catches this scenario. After the change to
DeleteImport, the new test passes (along with all other tests).

Fixes golang/go#7679.

Note that there is no attempt to ensure the result *ast.File and *token.FileSet are perfectly
matching to what you would get if you printed the AST and parsed it back. This is how the
rest of the package and the current tests work (i.e., they only check that printing the AST gives
the correct output).
Changing that is very hard, if not impossible, at least not
without resorting to manipulating AST via printing, text manipulation and parsing.
This is okay for most usages, but it does create potential problems. For example,
astutil.Imports() currently only works correctly on freshly parsed AST. If that AST
is manipulated via astutil funcs, then Imports() may not always generate correct
output. However, thas is a separate issue and should be treated as such.

LGTM=bradfitz
R=golang-codereviews, gobot, adonovan, bradfitz
CC=golang-codereviews
https://golang.org/cl/92250045
2014-05-19 14:04:30 -07:00
Robert Daniel Kortschak
ab1e5c6c94 go.tools/astutil: fix parameter omission in doc comment
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/98290045
2014-05-16 10:35:33 -07:00
Alan Donovan
3fc0fc1310 go.tools: rename packages.
Was:		Now:
ssa		go/ssa
importer	go/loader
pointer		go/pointer

Next CL: call -> go/callgraph (requires more care)

R=gri, crawshaw
CC=golang-codereviews
https://golang.org/cl/52960043
2014-01-16 09:33:58 -05:00
Brad Fitzpatrick
ae534bcb6c astutil: fix a comment corruption case
This fixes a case where adding an import when there are is no
existing import declaration can corrupt the position of
comments attached to types. This was the last known
goimports/astutil corruption case.

See golang.org/issue/6884 for more details.

Unfortunately this requires changing the API to add a
*token.FileSet, which we should've had before.  I will update
goimports (the only user of this API?) immediately after
submitting this.

This CL also contains a hack (used only in this case of no
imports): rather than fix the comment positions by hand
(something that only Robert might know how to do), it instead
just prints the AST, manipulates the source, and re-parses
the AST. We can fix up later.

Fixes golang/go#6884

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/38270043
2013-12-16 14:43:29 -08:00
Alan Donovan
f119874203 go.tools/oracle: improvements to command set and performance.
Command set:
- what: an extremely fast query that parses a single
  file and returns the AST stack, package name and the
  set of query modes that apply to the current selection.
  Intended for GUI tools that need to grey out UI elements.
- definition: shows the definition of an identifier.
- pointsto: the PTA features of 'describe' have been split
  out into their own command.
- describe: with PTA stripped out, the cost is now bounded by
  type checking.

Performance:
- The importer.Config.TypeCheckFuncBodies predicate supports
  setting the 'IgnoreFuncBodies' typechecker flag on a
  per-package basis.  This means we can load dependencies from
  source more quickly if we only need exported types.
  (We avoid gcimport data because it may be absent or stale.)
  This also means we can run type-based queries on packages
  that aren't part of the pointer analysis scope. (Yay.)
- Modes that require only type analysis of the query package
  run a "what" query first, and restrict their analysis scope
  to just that package and its dependencies (sans func
  bodies), making them much faster.
- We call newOracle not oracle.New in Query, so that the
  'needs' bitset isn't ignored (oops!).  This makes the
  non-PTA queries faster.

Also:
- removed vestigial timers junk.
- pos.go: existing position utilties split out into own file.
  Added parsePosFlag utility.
- numerous cosmetic tweaks.

+ very basic tests.

To do in follow-ups:
- sophisticated editor integration of "what".
- better tests.
- refactoring of control flow as described in comment.
- changes to "implements", "describe" commands.
- update design doc + user manual.

R=crawshaw, dominik.honnef
CC=golang-dev, gri
https://golang.org/cl/40630043
2013-12-13 10:04:55 -05:00
Alan Donovan
fb3d862cae go.tools/importer: move PathEnclosingInterval to package astutil.
R=crawshaw
CC=golang-dev
https://golang.org/cl/38650044
2013-12-09 09:36:29 -05:00
Brad Fitzpatrick
2d324f247c astutil: in test, dump AST before and after on failure
R=golang-dev, crawshaw
CC=golang-dev
https://golang.org/cl/37740043
2013-12-06 10:11:13 +04:00
Robert Griesemer
849643aaaf go.tools: cleanups (added copyrights to astutil, clearer logic in go/types)
R=adonovan
CC=golang-dev
https://golang.org/cl/29110043
2013-11-19 09:07:02 -08:00
Brad Fitzpatrick
a284a61701 astutil: add new broken test
Tests will still pass because it's marked as known broken,
but it will log the unexpected for now.

R=golang-dev, crawshaw
CC=golang-dev
https://golang.org/cl/27330043
2013-11-16 14:53:18 -08:00
David Crawshaw
545b16b6db go.tools/astutil: add AddNamedImport
R=bradfitz
CC=golang-dev
https://golang.org/cl/23850044
2013-11-12 18:02:47 -05:00
David Crawshaw
0d4ee40f21 go.tools/astutil: add Imports, which returns imports grouped by spacing.
R=bradfitz
CC=golang-dev
https://golang.org/cl/23660045
2013-11-08 14:51:15 -05:00
David Crawshaw
6df4bd0406 go.tools/astutil: make sure import blocks are marked as such (Lparen=1)
R=bradfitz
CC=golang-dev
https://golang.org/cl/22320044
2013-11-06 15:31:54 -05:00
David Crawshaw
0b5928ea2a go.tools/astutil: a package for common AST utilities.
Lifts the import management utilities from gofix into
a package, so they can be used by goimports.

R=bradfitz
CC=golang-dev
https://golang.org/cl/22430043
2013-11-06 13:30:30 -05:00