2022.01.28 - [dev-log/Rust] - rustfmt와 RLS, rust-analyzer

 

rustfmt와 RLS, rust-analyzer

rustfmt rustfmt는 러스트의 formatting 도구로, 이를 이용하여 일정한 스타일로 코드를 작성할 수 있음. 설치하기 $ rustup component add rustfmt​ 러스트 파일에 대해 rustfmt 실행하기 $ rustfmt main.rs​..

ahnanne.tistory.com

오토 포맷팅을 위해 사용할 수 있는 툴인 rust-analyzer의 설치 및 사용 방법에 대해 포스팅한 적이 있다.

 

최근에 구입한 맥북으로 러스트 공부를 하기 위해 러스트 설치도 하고, 작성해두었던 위 포스팅을 참고하여 rust-analyzer도 설치를 했다. (이전에는 윈도우10 데스크탑을 사용했다.)

 

*맥북 기종: MacBook Pro(14형, 2021년 모델) / Apple M1 Pro 칩

 

그런데 필요한 것들 설치를 하고 재부팅을 했는데도, 러스트 프로젝트를 실행하면 VS Code에 다음과 같은 경고가 떴다. 오토 포맷팅도 안됐다.

 

 

Unfortunately we don't ship binaries for your platform yet. You need to manually clone rust-analyzer repository and run `cargo xtask install --server` to build the language server from sources. If you feel that your platform should be supported, please create an issue about that here and we will consider it.

 

그래서 우선 두 번째 경고문에서 안내하는대로 rust-analyzer 레포를 클론한 뒤, 다음의 명령어를 실행시켜 랭귀지 서버를 빌드했다.

cargo xtask install --server

그리고 나서 재시작을 했는데도 변한 게 없어서 서치 좀 해보다가 settings.json에 다음과 같이 설정을 수정/추가했다.

{
  ...(생략),
  "[rust]": {
    "editor.defaultFormatter": "rust-lang.rust-analyzer"
  },
  "rust-analyzer.server.path": "~/.cargo/bin/rust-analyzer"
}

서버 경로 설정을 추가하는 방법은 이 답변을 참고했다.

러스트 디폴트 포매터는 이전 포스팅 시 설정했었던 값("matklad.rust-analyzer")은 잘못된 값으로 떠서, 자동완성된 목록 중에서 저 값("rust-lang.rust-analyzer") 같길래 이걸로 설정해주었다. 이게 운영체제 차이 때문인 건지 아니면 몇 달 사이에 뭔가가 바뀌어서 그런 건지는 한번 확인해봐야겠다.

 

무튼 이렇게 서버 경로 설정을 추가해주면 reload 하라고 뜨고, reload 해주면 다음과 같은 내용이 출력된다.

INFO [2022. 5. 22. 오전 11:59:33]: Using server binary at /Users/an-yein/.cargo/bin/rust-analyzer

이제 오토 포맷팅은 잘 되는데 경고 2개는 계속 뜬다. 뭐 오토 포맷팅 적용하는 게 목표였으니 일단 남겨두고 러스트 더 공부한 다음에 해결해보는 걸로 ㅋ 🤤

 

복사했습니다!