2018-12-14 15:00:24 -07:00
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package lsp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
|
|
"golang.org/x/tools/internal/lsp/source"
|
2019-02-19 19:11:15 -07:00
|
|
|
"golang.org/x/tools/internal/span"
|
2018-12-14 15:00:24 -07:00
|
|
|
)
|
|
|
|
|
2019-02-19 19:11:15 -07:00
|
|
|
func organizeImports(ctx context.Context, v source.View, s span.Span) ([]protocol.TextEdit, error) {
|
|
|
|
f, m, err := newColumnMap(ctx, v, s.URI)
|
2019-02-04 15:44:35 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-02-19 19:11:15 -07:00
|
|
|
rng := s.Range(m.Converter)
|
|
|
|
if rng.Start == rng.End {
|
|
|
|
// if we have a single point, then assume the rest of the file
|
|
|
|
rng.End = f.GetToken(ctx).Pos(f.GetToken(ctx).Size())
|
2018-12-14 15:00:24 -07:00
|
|
|
}
|
2019-02-19 19:11:15 -07:00
|
|
|
edits, err := source.Imports(ctx, f, rng)
|
2018-12-14 15:00:24 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-02-19 19:11:15 -07:00
|
|
|
return toProtocolEdits(m, edits), nil
|
2018-12-14 15:00:24 -07:00
|
|
|
}
|