From 49db546f375eee2dbfef045773161e6a4ea59c2f Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 12 Dec 2018 01:02:12 +0900 Subject: [PATCH] internal/lsp/source: Use file:///C:/ on Windows file system URI should be started with file:/// always. Change-Id: I123e577d421de3e85dfec00596fbdb63c2231938 Reviewed-on: https://go-review.googlesource.com/c/153618 Reviewed-by: Rebecca Stambler Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/source/uri.go | 2 -- internal/lsp/source/uri_unix.go | 9 +++++++++ internal/lsp/source/uri_windows.go | 9 +++++++++ internal/lsp/source/uri_windows_test.go | 26 +++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 internal/lsp/source/uri_unix.go create mode 100644 internal/lsp/source/uri_windows.go create mode 100644 internal/lsp/source/uri_windows_test.go diff --git a/internal/lsp/source/uri.go b/internal/lsp/source/uri.go index 59429292..4e6d58e6 100644 --- a/internal/lsp/source/uri.go +++ b/internal/lsp/source/uri.go @@ -12,8 +12,6 @@ import ( "strings" ) -const fileSchemePrefix = "file://" - // URI represents the full uri for a file. type URI string diff --git a/internal/lsp/source/uri_unix.go b/internal/lsp/source/uri_unix.go new file mode 100644 index 00000000..de7dc3ac --- /dev/null +++ b/internal/lsp/source/uri_unix.go @@ -0,0 +1,9 @@ +// 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. + +// +build !windows + +package source + +const fileSchemePrefix = "file://" diff --git a/internal/lsp/source/uri_windows.go b/internal/lsp/source/uri_windows.go new file mode 100644 index 00000000..00cfce86 --- /dev/null +++ b/internal/lsp/source/uri_windows.go @@ -0,0 +1,9 @@ +// 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. + +// +build windows + +package source + +const fileSchemePrefix = "file:///" diff --git a/internal/lsp/source/uri_windows_test.go b/internal/lsp/source/uri_windows_test.go new file mode 100644 index 00000000..aa9025f1 --- /dev/null +++ b/internal/lsp/source/uri_windows_test.go @@ -0,0 +1,26 @@ +// 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. + +// +build windows + +package source + +import ( + "testing" +) + +func TestURIWindows(t *testing.T) { + s := `C:\Windows\System32` + uri := ToURI(s) + if uri != `file:///C:/Windows/System32` { + t.Fatalf("ToURI: got %v want %v", uri, s) + } + f, err := URI(uri).Filename() + if err != nil { + t.Fatal(err) + } + if f != s { + t.Fatalf("Filename: got %v want %v", f, s) + } +}