visual-studio-codegoland

How to ensure that the import order of vscode and Goland is the same


as you see , the second is Goland , the first is Vscode.

vscode

import (
    "flag"
    "os"
    "rblc-excel/model"
    "strconv"
    "strings"
    "sync"
    "time"
    "unicode"

    nested "github.com/aohanhongzhi/nested-logrus-formatter"
    "github.com/shopspring/decimal"
    log "github.com/sirupsen/logrus"
    "github.com/xuri/excelize/v2"
)

Goland

import (
    "flag"
    nested "github.com/aohanhongzhi/nested-logrus-formatter"
    "github.com/shopspring/decimal"
    log "github.com/sirupsen/logrus"
    "github.com/xuri/excelize/v2"
    "os"
    "rblc-excel/model"
    "strconv"
    "strings"
    "sync"
    "time"
    "unicode"
)

if I use vscode and Goland update the same go project , It will use the different sort rule for the import. it will change when you modify code , I think it not must be.

so how to keep it same?


Solution

  • This resembles the case discussed here - https://youtrack.jetbrains.com/issue/GO-10293, so I think you can try to change sorting order via Preferences | Editor | Code Style | Go | Imports | Sorting type in your IDE.