1
0
mirror of https://github.com/golang/go synced 2024-11-05 22:46:12 -07:00
Commit Graph

2382 Commits

Author SHA1 Message Date
Yury Smolsky
48418e5732 godoc: display "go vet" errors before the output of a program
This change adds an option to run "go vet" for the playground program
and display errors before any output. To enable this, the playground
function has to be supplied with opts.enableVet set to true.
Vet check is performed only for succesfully run programs,
meaning that the "/compile" endpoint returned no errors.

This change highlights lines printed to stderr as errors (in red).

There is a corresponding change for the Playground: CL 100776.

Updates golang/go#7597
Updates golang/go#24576

Change-Id: I8c0f8c1189c461338b5bce57777b12aecab268fb
Reviewed-on: https://go-review.googlesource.com/107455
Run-TryBot: Yury Smolsky <yury@smolsky.by>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-05-08 19:22:17 +00:00
jimmyfrasche
76f5b51ce4 x/tools/godoc: make front page video respond to layout changes (2/2)
This part of a multi-repo change. See CL 108677 for details.

Note: this change also requires a CL to golang/go to complete the fix,
though either CL without the other is harmless.

Updates golang/go#24997.

Change-Id: I99ca9a4e6df16347b8706f24cef9689b3345854a
Reviewed-on: https://go-review.googlesource.com/108678
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-05-08 19:21:29 +00:00
Brad Fitzpatrick
8772326260 cmd/guru: skip the slow tests in short mode
Change-Id: I85c2de03087ae8bb8989763f255b362eeee5b397
Reviewed-on: https://go-review.googlesource.com/109556
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-05-04 17:47:05 +00:00
Agniva De Sarker
ae8027637c godoc/static: add test for static.go file generation
Moved the code which generates static.go to remain in the static package.
This makes the code testable.

Additionally, it is very easy for developers to forget to run "go generate"
to update static.go. Because while development, the templates directory
can be directly passed as a flag to read the files from it.

This test catches that.

Change-Id: I314907b98907bb14e4eabfd3c532ba2d84ce7c5f
Reviewed-on: https://go-review.googlesource.com/110158
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-05-03 19:34:25 +00:00
Jeevanandam M
f4ce24f1d8 godoc/static: cleanup unused lines in makestatic.go
Change-Id: I9b930efb5efd4b32c41c40d2399e04bacd75b470
GitHub-Last-Rev: 53db7899927e5ae255310c6a765526a10552649f
GitHub-Pull-Request: golang/tools#36
Reviewed-on: https://go-review.googlesource.com/111155
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-05-03 05:28:33 +00:00
Andrew Bonventre
8026fb003c cmd/guru: fix vet error in referrers.go
Fixes golang/go#25227

Change-Id: If121154f95681367874332dac30bfe69d1755182
Reviewed-on: https://go-review.googlesource.com/111035
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-05-02 21:01:57 +00:00
Agniva De Sarker
a25dedfa53 godoc: set the GOROOT path properly in cmdline mode
- Setting the GOROOT build path to the value passed from the command line.

- Clarified the return values to named parameters for extra clarity.

- And while here, added some missed out error handling. Just logging the error
to preserve original behavior.

Fixes golang/go#13296

Change-Id: I91427eee790928a3cfb51ae207747e9a17bd5496
Reviewed-on: https://go-review.googlesource.com/110275
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-05-02 17:46:13 +00:00
Josh Bleecher Snyder
5c8013c561 cmd/guru: re-use buffer for reading files
I felt guilty about leaving 2% on the table in CL 108878,
so I thought I'd get it a different way.

Teach readFile to accept a re-usable bytes.Buffer to read into,
to reduce the amount of garbage created.

To limit the possible memory impact of giant files,
only re-use the buffer for the duration of a single package.
Even that is enough to help.

name       old time/op       new time/op       delta
Referrers        4.67s ± 3%        4.58s ± 2%  -1.96%  (p=0.029 n=10+10)

name       old user-time/op  new user-time/op  delta
Referrers        16.5s ± 3%        15.8s ± 1%  -4.39%  (p=0.000 n=10+8)

name       old sys-time/op   new sys-time/op   delta
Referrers        16.1s ± 3%        15.9s ± 3%    ~     (p=0.218 n=10+10)

This work supported by Sourcegraph.

Change-Id: I594ef25c0fd5ccb766ff5b98dbbd1a75a7a4f957
Reviewed-on: https://go-review.googlesource.com/108935
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-05-01 18:53:35 +00:00
Josh Bleecher Snyder
c1f4e2c6dc cmd/guru: emit initial referrers result earlier
This simplifies and unifies the code.
It also improves the output:
Now the initial result is referred to from the perspective of
the query site, rather than from the perspective of the package
containing the query object, which seems more natural.

This work supported by Sourcegraph.

Change-Id: Ie7a77d39dd6568334e72d894dc66d35494ed4ac4
Reviewed-on: https://go-review.googlesource.com/108936
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-05-01 18:28:20 +00:00
Josh Bleecher Snyder
d4c6246f3e cmd/guru: parallelize loop in globalReferrersPkgLevel
This change parallelizes the outer loop in globalReferrersPkgLevel,
which loops over packages to inspect.

There is also an easily parallelizable inner loop.
However, parallelizing it adds complication
(deffiles needs a mutex, inQueryPackage requires a wait group)
and offers only a 2% speed-up.

Benchmarks for this change, looking for encoding/json.MarshalIndent:

name       old time/op       new time/op       delta
Referrers        5.31s ± 2%        4.67s ± 3%  -11.95%  (p=0.000 n=10+10)

name       old user-time/op  new user-time/op  delta
Referrers        15.9s ± 2%        16.5s ± 3%   +3.71%  (p=0.000 n=10+10)

name       old sys-time/op   new sys-time/op   delta
Referrers        15.7s ± 3%        16.1s ± 3%   +2.73%  (p=0.011 n=10+10)


Fixes golang/go#24272
Updates golang/go#25017


This work supported by Sourcegraph.

Change-Id: I5dcda9017103cdff59d0ffdf5e87d2c2c955a33a
Reviewed-on: https://go-review.googlesource.com/108878
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-05-01 18:27:15 +00:00
Josh Bleecher Snyder
1e1ec013b9 cmd/guru: optimize global pkglevel referrer queries
Global, package-level queries can be done without typechecking.
This makes it significantly cheaper.

Instead of typechecking, consider all packages that directly
import the query package. In each of those packages, filter out:

* files that don't contain the query name
* files that don't import the query package

Fully parse the remaining files and look for selector expressions
matching the query package and name.

There are a few twists (dot imports, the query package, xtests).
They are described, along with how they are handled,
in the large comment at the beginning of globalReferrersPkgLevel.

On my machine and GOPATH, this reduces typical time
needed to find referrers to encoding/json.MarshalIndent
from (roughly)

real	0m39.946s
user	2m27.844s
sys	0m54.774s

to (roughly)

real	0m5.687s
user	0m15.793s
sys	0m16.001s

The processing of packages could be parallelized;
that is left for a future change, to ease reviewing.

Benefits from that will be limited;
building the reverse import graph accounts for 73%
of the runtime, and that is dominated by syscalls.

Optimization idea from Alan Donovan.

This work supported by Sourcegraph.

Change-Id: Ib19e25fcdcb27673fb03d7300dba2a53198901ad
Reviewed-on: https://go-review.googlesource.com/97800
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-05-01 18:10:48 +00:00
Andrew Bonventre
c47212f6f0 godoc: don't exclude version field from File struct
When uploading a new release, it deserializes the payload into
a File struct for processing. It needs the Version field to
determine which release it's in.

Change-Id: I171f416dbb1b1b6c354948ea9a31b9c8694f892e
Reviewed-on: https://go-review.googlesource.com/110627
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-05-01 16:35:01 +00:00
Nikhil Benesch
836e0f611e cmd/goyacc: fix an off-by-one error in lineno tracking
Previously, goyacc's line number tracking would run off by one whenever
a multiline comment was used inside of an action, like so:

    expr:
        TOKEN
        {
            /* Hello. */
        }

This is because the character after the multi-line comment close marker
(i.e., the character immediately after `*/`) was blindly printed out
instead of properly accounted for. A newline character after a
multi-line comment would fail to increment lineno, for example, and any
error messages generated after that point would refer to the wrong line.
Similarly, a variable reference after a multi-line comment, like

    $$.val = &someStruct{Value: /* oops */$1}

would copy the $ literally into the resulting Go code. (This was not a
problem in practice because multi-line comments are typically followed
by whitespace.)

Adjust the control flow so the character after the multi-line comment
close marker character gets run through the relevant switch statement
and accounted for.

Change-Id: I276b6ffdb7626101f76811b7ee4804bacc6ef740
Reviewed-on: https://go-review.googlesource.com/110495
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-05-01 01:19:15 +00:00
Bryan C. Mills
165bdd618e imports: fix races in findImportGoPath
Before this change, findImportGoPath used a field within the
(otherwise read-only) structs in the dirScan map to cache the distance
from the importing package to the candidate package to be imported. As
a result, the top-level imports.Process function was not safe to call
concurrently: one goroutine could overwrite the distances while
another was attempting to sort by them. Furthermore, there were some
internal write-after-write races (writing the same cached distance to
the same address) that otherwise violate the Go memory model.

This change fixes those races, simplifies the concurrency patterns,
and clarifies goroutine lifetimes. The functions in the imports
package now wait for the goroutines they spawn to finish before
returning, eliminating the need for an awkward test-only mutex that
could otherwise mask real races in the production code paths.

See also:
https://golang.org/wiki/CodeReviewComments#goroutine-lifetimes
https://golang.org/wiki/CodeReviewComments#synchronous-functions

Fixes golang/go#25030.

Change-Id: I8fec735e0d4ff7abab406dea9d0c11d1bd93d775
Reviewed-on: https://go-review.googlesource.com/109156
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2018-04-30 20:17:55 +00:00
Agniva De Sarker
8e070db38e godoc: remove vendor prefixes for border-radius
All major browsers support the border-radius directive
without any vendor prefix. Hence, removing them.

https://caniuse.com/#search=border-radius

Change-Id: I2da5f109296df3c7f191df95876bd6849f51d9ae
Reviewed-on: https://go-review.googlesource.com/110155
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-28 22:29:17 +00:00
Agniva De Sarker
0b5ca0b040 godoc: use relative css unit
To scale the website elements independently of the default font size,
we use the css rem unit. This scales the elements proportionally if the
user has set a different font size than the default.

We make all calculations assuming that 1rem=16px, which is the
default font size for browsers.

Tested manually on FF 59 and Chrome 65 with permutations of different
resolutions and different default font-sizes upto 36px.

Fixes golang/go#6150

Change-Id: I7ded227ee2c55178271667009ab98ee0b4e7e8b3
Reviewed-on: https://go-review.googlesource.com/94935
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-04-27 00:46:46 +00:00
Rebecca Stambler
6e0e2181b9 go/internal/gcimporter: support indexed export data
Support indexed export data in the x/tools gcimporter. Fixes tests with
tip.

This is just a copy of the bimport.go and iimport.go files in the
standard library gcimporter package, including some minor fixes to the
existing bimport.go. The iexport logic in x/tools still needs to be
updated.

Fixes golang/go#25052

Change-Id: I2858e5c0853735c904f32b7b27c1c288a9e62e88
Reviewed-on: https://go-review.googlesource.com/109595
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-04-26 19:07:32 +00:00
Josh Bleecher Snyder
c1def519f0 imports: improve VendorlessPath docs
Eliminate Latin, lest someone complain
"it's Greek to me".

This work supported by Sourcegraph,
though perhaps not the commit message.

Change-Id: Ia44eaf5bc5adb6624b590c9cfdfe8083d1414a2c
Reviewed-on: https://go-review.googlesource.com/108937
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-23 20:32:37 +00:00
Josh Bleecher Snyder
81527693ec imports: export VendorlessPath
Rename to avoid imports/import stutter and export.
It will be used soon by guru's referrers command.

This work supported by Sourcegraph.

Change-Id: Ibfc39d061d6269a336a59d9b6979188a94537d94
Reviewed-on: https://go-review.googlesource.com/108877
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-04-23 20:00:20 +00:00
Josh Bleecher Snyder
71f44073ef cmd/guru: always import tests in initial referrers import
If test files are not included here,
then results in those files will be missing
for queries within a single package.

This work supported by Sourcegraph.

Change-Id: I8136ea250ba980179228d9b408d9e7409c49a873
Reviewed-on: https://go-review.googlesource.com/97799
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-04-23 20:00:06 +00:00
Josh Bleecher Snyder
7e5e8df4df cmd/guru: make tests granular and parallel
This make it possible to easily run individual guru tests.

It also slightly speeds up the overall test run,
from 23s to 18s on my machine;
the TestGuru/calls is now the limiting factor,
by a significant margin.

This work supported by Sourcegraph.

Change-Id: If61ebf1cc60441a65274f3fddd31f69c7ca23b48
Reviewed-on: https://go-review.googlesource.com/108876
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-04-23 19:59:51 +00:00
Ian Cottrell
94b14834a2 imports: extract fastWalk into new package internal/fastwalk
It is going to be used by a new tool.
Moved to an internal package so it does not become a publicly supported
api.
Modified the tests so they don't depend on the fix_test infrastructure.

Change-Id: Ib8ebef24dc23e180960af04aa3d06b5f41a7c02b
Reviewed-on: https://go-review.googlesource.com/99678
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-16 19:53:52 +00:00
Agniva De Sarker
1a83a0b548 godoc: fix counting of package files in GetPageInfo
CL 107155 introduced this bug due to oversight. There can be
a scenario where a folder has no source .go or .c files,
but has an ignored .go file. In that case, both the if conditions
to check the length of pkgfiles slice will evaluate to true.

Added a test case for it to prevent this happening in future.

Change-Id: I7181699bbf7580888a6f7923c5aeb842356941a8
Reviewed-on: https://go-review.googlesource.com/107195
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-16 18:17:07 +00:00
Kevin Burke
d9caac3737 godoc: add benchmark for directory scan
I'd like to propose changes to the directory scanner implementation,
and it would be good to be able to measure how changes compare in
terms of allocations and time taken.

Change-Id: I4ff4bbd38b5e3522f50d31473f2ac607bb0de802
Reviewed-on: https://go-review.googlesource.com/94904
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-15 15:36:21 +00:00
Agniva De Sarker
327197e6b0 godoc,blog: perform minor cleanup
- Remove a stray comment which was no longer needed. The accompanying
issue golang.org/issue/7524 was discussed and closed.
- Combine 2 if conditions into a single if-else because
length of a slice can never be negative.
- Remove http links from golangOrgAbsLinkReplacer now that all
links have been changed to https in the blog articles.

Change-Id: I2fe2ec245b580a91760c9331e9626b367f1b6740
Reviewed-on: https://go-review.googlesource.com/107155
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-14 19:30:04 +00:00
Agniva De Sarker
8723cc7387 blog: revert strings.Builder to bytes.Buffer
The blog repo can still be imported by older Go versions. Hence,
we need to maintain backward compatibility.

Change-Id: I0235d888734c2f191d04924815f8ffea0239aace
Reviewed-on: https://go-review.googlesource.com/107175
Run-TryBot: Kevin Burke <kev@inburke.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-14 19:22:41 +00:00
Agniva De Sarker
d11f6ec946 blog: serve relative links when run locally
Currently, links inside blog articles are absolute links to golang.org.
But when a godoc server is run locally, the blog package should
serve local links pointing to the local godoc server. It is not possible
to simply change the links inside the blog templates to relative urls
because the blog articles are independant pages on their own.
And moreover, they are served from blog.golang.org.

Rather, the blog package consumes and serves blog articles.
So, a flag was added in the Config struct to denote whether
to convert the links or not. This flag is then set from the
call site in godoc package where the blog server is initialized from.

This was required because "golang.org/x/tools/blog" is a package
which can be used by other code to serve blog pages and not just godoc.
This preserves existing functionality for all working code which
imports "golang.org/x/tools/blog" and changes the functionality only
when a godoc server is run locally.

And while here, replace relevant bytes.Buffer occurences
with strings.Builder.

Fixes golang/go#22681

Change-Id: I7dbf9c5f2f93fd0b7e17915238de1c084fcd1431
Reviewed-on: https://go-review.googlesource.com/105835
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-13 18:10:15 +00:00
David Url
5e86cd2985 cmd/present: display slide numbers
Fixes golang/go#5331

Change-Id: Iddd45452959823b2e8e3f9b4236a9a9a3968d35f
Reviewed-on: https://go-review.googlesource.com/97058
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-04-13 16:54:21 +00:00
haya14busa
1c0c7a8cce imports: Process should accept nil src
The comment of Process() implies src can be nil, but it didn't handle
nil src correctly before because parse() doesn't expect nil src.
Passing []byte(nil) to parser.ParseFile() results in error and parse()
tries to parse again by modifying src if src is statement list.

This problem isn't related with cmd/goimports because goimports doesn't
pass []byte(nil) to Process() as src.

Fixes golang/go#19676

Change-Id: Idbaa6646c3907690763eabc798860c56bb9963d4
Reviewed-on: https://go-review.googlesource.com/38613
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-12 23:47:31 +00:00
Brad Fitzpatrick
dc06d3e643 cmd/godoc: support http-01 ACME challenge in optional autocert support
Using same structure & naming as CL 91518.

Fixes golang/go#23627

Change-Id: Ifb73c77d2c39f9f669d425650f9c5bc31bace196
Reviewed-on: https://go-review.googlesource.com/106455
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-04-11 21:25:11 +00:00
Agniva De Sarker
8b3cccae50 godoc/vfs: improve implementation of RootType
- Removed the StandAlone and Asset root types as they were just there
for other vfses to satisfy the FileSystem interface and causing unnecessary
confusion. Returning just empty strings in those scenarios now to clarify
that it is a dummy placeholder.

- Removed the prefix "Fs" from RootType as it was unnecessary.

- Using the RootType type to pass down to the html templates
instead of converting to string. The templates are capable of converting
to the actual string representation when comparing the value.

Change-Id: Iadc039f1354ecd814eec0af1e52cdbaaeff0cc89
Reviewed-on: https://go-review.googlesource.com/106196
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-11 20:41:25 +00:00
Tobias Klauser
ccd319aab1 go/ssa/interp: add internal/syscall/unix.syscall_fcntl to fix tests
CL 100077 added the syscall_fcntl function in the internal/syscall/unix
package to refer to syscall.fcntl outside of the syscall package in a
unified way.

Add a replacement that simulates a successful fcntl call to fix the
interp tests.

Change-Id: I05847d222f18a19cb30f1395497e708a027a002e
Reviewed-on: https://go-review.googlesource.com/106415
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-11 19:48:31 +00:00
Brad Fitzpatrick
368a7e18b5 cmd/guru: skip broken test for old Go versions for now
Updates golang/go#24421

Change-Id: Iedcb629135802f78e8f149b377f34e49c8019fe9
Reviewed-on: https://go-review.googlesource.com/106435
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-04-11 19:25:09 +00:00
Agniva De Sarker
faed997d2c godoc: cleanup package templates
Separate the templates of package root directory and other
directories. This removes several if-else conditions and
makes the template code much cleaner.

To be merged after CL 95835.

For golang/go#3305

Change-Id: I435441dbe214e4c89271483173df7c30a42ee28f
Reviewed-on: https://go-review.googlesource.com/101295
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-04-10 16:42:09 +00:00
Agniva De Sarker
16d1af8d88 godoc: group package home page list by root
This CL groups the package list into two groups - standard library(GOROOT),
and third-party code(GOPATH).

It also wraps the list with a collapsible div header used in the package
documentation page. This makes the entire page easy to view and manage, and also
makes it consistent with the rest of the pages.

To implement this, a new function was added to the filesystem interface
which returns the root type of the filesystem. In most cases, it is either GOROOT
or GOPATH. There are other kinds of filesystems which are not used in the home page,
so additional values have been added to satisfy the interface.

A side effect of this is that the html template code has become a bit spaghetti-like
with if conditions all over. This is because the same template is used to render
a package directory as well as the package home page. A better way is to use
two separate templates for the different tasks. This cleans out a lot of the
if conditions and make for a much cleaner code. This has been taken care in CL 101295.

Fixes golang/go#3305
Fixes golang/go#15020

Change-Id: I876357dc76280a7df2ed08d7c6bc53d9a41e69ab
Reviewed-on: https://go-review.googlesource.com/95835
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-04-10 16:41:40 +00:00
Matthew Dempsky
5dfd8930f2 go/internal/gcimporter: rename from go/gcimporter15
Follow through on promise to remove the old API.

Change-Id: If1f5addfeb1b82acc5a1730474e2f06102dbb615
Reviewed-on: https://go-review.googlesource.com/105977
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-04-10 13:03:03 +00:00
Matthew Dempsky
14d5b80f95 go/gcimporter15: support bimport format v6
Format change introduced by golang.org/cl/105038.

Change-Id: I76eefe9ce7f52743cb5cdcfe77e5ee0b5eb8743f
Reviewed-on: https://go-review.googlesource.com/105976
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-09 23:44:46 +00:00
Agniva De Sarker
ac136b6c2d godoc: sort package listing
The directory slice gets created first from newDirTree and then
gets appended again after reading from the dirchs channel. Hence
we need to sort the slice after all the entries are added.

Fixes golang/go#24601

Change-Id: I9282e8643a4448b2c1c84495b7642610f6c56d50
Reviewed-on: https://go-review.googlesource.com/103955
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Kevin Burke <kev@inburke.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-01 16:57:15 +00:00
Dmitri Shuralyov
370143dbca godoc/static: add perf, review, sync subrepos
They exist and are considered to be worth listing based on the decision
made in golang/go#24432. They weren't listed previously. This change
fixes that.

Document the remaining subrepos that are not meant to be listed (per
decision in golang/go#24432), so it's clear that it's intentional for
them to not be visible at https://golang.org/pkg/#subrepo.

Closes golang/go#24432.
Updates golang/go#14304.

Change-Id: Icc50ebfcdbc490c32519d92a1a838eb3f54c823d
Reviewed-on: https://go-review.googlesource.com/103075
Reviewed-by: Austin Clements <austin@google.com>
2018-03-30 16:45:20 +00:00
Yury Smolsky
77106db15f cmd/godoc: fix TestWebIndex test
The godoc in the test was indexing sources in the default GOPATH.
If the default GOPATH pointed to local workspace, test would timeout.
The fix is to supply GOPATH set to non-existing path.

Fixes golang/go#24504

Change-Id: Iedf044cdec78d5c5642105650ad8ec17aa10a5ba
Reviewed-on: https://go-review.googlesource.com/102295
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-24 18:54:18 +00:00
Yury Smolsky
4c0f0e48a6 godoc: add vet support to playground.js
Playground needs godoc to support calls to /vet endpoint in playground.js.
Optional parameter "vetEl" is added to the function "playground".
If it's passed then the js installs the click handler to the element.

There is a corresponding CL 100776 for the playground code.

Updates golang/go#7597

Change-Id: Ica2e7cb9d76f6f19a1805c182e666b8142762da9
Reviewed-on: https://go-review.googlesource.com/100775
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-03-23 17:42:02 +00:00
Colin
2226533658 refactor/eg: Add support for multi line after statements to eg.
The semantics of this change are that the last line will be subsituted
in place of the expression, where as the lines before that will undergo
variable substitution and be prepended before the lowest (in the AST
tree sense) statement which included the expression.

Change-Id: Ie2571934dcc1b0a30b5cec157e690924a4ac2c5a
Reviewed-on: https://go-review.googlesource.com/77730
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-03-19 17:51:41 +00:00
Kevin Burke
96caea4103 godoc: fix runaway goroutine use
Previously we would spin up a new goroutine for every directory
we needed to parse. Since parent directories cannot exit until
children have exited, in large GOPATH directories we could have 8000+
goroutines evaluating directories concurrently. The race detector uses
tsan, and tsan can handle a maximum of 8192 concurrent threads at one
time.

Limit the number of concurrent threads. It is difficult to do this
in a way that does not involve a child being blocked on a parent
completing to spin up goroutines for itself to complete. Solve this by
completing work on the main thread if there are no additional workers
available to help complete work.

I was expecting limiting the concurrency to hurt performance, but it
actually significantly improves it. Benchmarks were performed using CL
94904 at tip, and with goroutines at 2, 4, and 8 times the number of
CPU's.

$ benchstat tip.benchmark gated-2.benchmark gated-4.benchmark gated-8.benchmark
name \ time/op    tip.benchmark  gated-2.benchmark  gated-4.benchmark  gated-8.benchmark
NewDirectory-4       293ms ± 2%         262ms ± 4%         252ms ± 4%         253ms ± 2%

name \ alloc/op   tip.benchmark  gated-2.benchmark  gated-4.benchmark  gated-8.benchmark
NewDirectory-4       218MB ± 0%         218MB ± 0%         218MB ± 0%         218MB ± 0%

name \ allocs/op  tip.benchmark  gated-2.benchmark  gated-4.benchmark  gated-8.benchmark
NewDirectory-4        513k ± 0%          508k ± 0%          509k ± 0%          510k ± 0%

Fixes golang/go#22110.

Change-Id: If01f78f1fc53cd195e4f8f6988c3c39b3c275992
Reviewed-on: https://go-review.googlesource.com/94955
Reviewed-by: Yury Smolsky <yury@smolsky.by>
Reviewed-by: Kevin Burke <kev@inburke.com>
2018-03-18 01:21:57 +00:00
Dmitri Shuralyov
14b3f5b193 godoc/static: add x/time subrepo
It exists, but wasn't listed previously. This change fixes that.

Fixes golang/go#24430.

Change-Id: Iaf83a4b7353794e6f411941de811ed1554955179
Reviewed-on: https://go-review.googlesource.com/101241
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-17 16:38:46 +00:00
Yury Smolsky
39919aea04 cmd/godoc: provide -all flag to output unexported identifiers
This flag includes unexported identifiers in command-line mode.
It is equivalent to ?m=all in web mode.

Fixes golang/go#8093

Change-Id: I1e5a69626929d3430638d900f3e975b272a98c90
Reviewed-on: https://go-review.googlesource.com/99435
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-03-16 16:52:36 +00:00
Robert Griesemer
c4b4e4b0fa cmd/guru: fix .golden file (fix build)
This regression is due to https://go-review.googlesource.com/c/go/+/100235
which made the go/scanner behavior match the compiler's scanner by
not modifying filenames in line directives in any form. Specifically,
relative filenames now remain relative. This makes it easier to reason
about the behavior of the scanner but may require clients to adjust
those filenames.

If removing the longer path in the .golden file is not satisfactory,
the (scanner) client may have to massage positions returned via line
directives; or better, the line directives are created with extended
path information.

R=adonovan

Change-Id: I836571a6dafef5e6d81e4c7add203c994e107055
Reviewed-on: https://go-review.googlesource.com/101015
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-16 01:01:07 +00:00
Agniva De Sarker
5ad4d95e58 godoc: add the defer attribute to script tags
This allows the scripts to be downloaded concurrently as the
body is being parsed.

Deferred scripts are executed in order and only after the entire
document has been loaded. So essentially the entire effect remains same
but we reduce the network download time.

Also, CL 90396 missed out updating static.go. Packaging the change along
with this.

Change-Id: Ia850bd50b49f2a9e0e4fbc29617858ab0fa8a0b9
Reviewed-on: https://go-review.googlesource.com/100295
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-03-15 17:24:39 +00:00
Nick Miyake
c41d143952 imports: support match without trailing slash for -local flag
Make it so that import prefixes specified using the -local flag are considered
a match for an import path if the prefix ends with a '/' and the import path
matches exactly the prefix without a slash. For example, specifying
"golang.org/x/tools/" as a prefix would match the import for the package
"golang.org/x/tools".

Fixes golang/go#24368

Change-Id: I0302db72fda63ad24d7b964aa73f78aa0ebccb37
Reviewed-on: https://go-review.googlesource.com/100460
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-15 06:52:34 +00:00
Andrew Bonventre
d853e8088c CONTRIBUTING.md: remove note about not accepting Pull Requests
Updates golang/go#24185

Change-Id: I6462c066b7efc4086496d9ed5e85a0d826f962bd
Reviewed-on: https://go-review.googlesource.com/100716
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-03-14 18:02:17 +00:00
Ian Cottrell
c1547a3f90 imports: Limit the amount of text printed in the large token case
If the test fails, it tries to print a million characters.
This limits it to just the start of got and want, which is enough to see
the imports block anyway.

Change-Id: I2c58db8e96e73da436ca16fa8a57c820a95242ca
Reviewed-on: https://go-review.googlesource.com/100216
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-13 18:49:02 +00:00