Vscode-rust: قم بتمرير متغيرات البيئة إلى RLS

تم إنشاؤها على ١ ديسمبر ٢٠١٧  ·  5تعليقات  ·  مصدر: rust-lang/vscode-rust

أواجه مشكلات مع المشاريع التي تتضمن diesel واستخدام متغيرات البيئة على سبيل المثال:

pub fn establish_connection() -> SqliteConnection {
    dotenv().ok();

    let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");

    SqliteConnection::establish(&database_url)
        .expect(&format!("Error connecting to {}", database_url))
}

النتائج في ما يلي في نافذة الإخراج:

{"message": "proc-macro مشتق بالذعر" ، "الرمز": فارغ ، "المستوى": "خطأ" ، "يمتد": [{"اسم_الملف": ""،" byte_start ": 72،" byte_end ": 83،" line_start ": 3،" line_end ": 3،" column_start ": 14،" column_end ": 25،" is_primary ": true،" text ": [{ "text": "# [derive (InferSchema)] # ["، "light_start": 14، "light_end": 25}]، "label": null، "selected_replacement": null، "extension": {"span" :{"اسم الملف":""،" byte_start ": 72،" byte_end ": 83،" line_start ": 3،" line_end ": 3،" column_start ": 14،" column_end ": 25،" is_primary ": false،" text ": [{ "text": "# [derive (InferSchema)] # ["، "light_start": 14، "light_end": 25}]، "label": null، "selected_replacement": null، "extension": {"span" : {"file_name": "Development / pathfinder-server / pathfinder-server / src / schema.rs"، "byte_start": 0، "byte_end": 37، "line_start": 1، "line_end": 1، "column_start ": 1،" column_end ": 38،" is_primary ": false،" text ": [{" text ":" infer_schema! ("dotenv: DATABASE_URL")؛ "،" light_start ": 1،" light_end ": 38 }] ، "label": خالية ، "الاستبدال_ المُقترَح": فارغ ، "توسيع": فارغ} ، "macro_decl_name": "infer_schema!" ، "def_site_span": {"file_name": ""،" byte_start ": 0،" byte_end ": 484،" line_start ": 1،" line_end ": 11،" column_start ": 1،" column_end ": 53،" is_primary ": false،" text ": [{ "text": "($ database_url: expr) => {"، "light_start": 1، "light_end": 31}، {"text": "mod __diesel_infer_schema {"، "light_start": 1، "light_end": 28}، {"text": "# [اشتقاق (InferSchema)] # ["، "light_start": 1، "light_end": 33}، {"text": "infer_schema_options (database_url = $ database_url)] Struct _Dummy؛ } pub "،" light_start ": 1،" light_end ": 79}، {" text ":" use self :: __diesel_infer_schema :: *؛ } ؛ ("،" light_start ": 1،" light_end ": 47}، {" text ":" $ database_url: expr، $ schema_name: expr) => {"،" light_start ": 1،" light_end ": 52}، {"text": "mod __diesel_infer_schema {"، "light_start": 1، "light_end": 28}، {"text": "# [derive (InferSchema)] # ["، "light_start": 1، "light_end" : 33}، {"text": "infer_schema_options ("، "light_start": 1، "light_end": 23}، {"text": "database_url = $ database_url، schema_name = $ schema_name)] هيكل _Dummy"، "light_start ": 1،" light_end ": 78}، {" text ":"؛ } pub use self :: __diesel_infer_schema :: *؛ }؛ "،" light_start ": 1،" light_end ": 53}]،" label ": null،" selected_replacement ": null،" extension ": null}}}،" macro_decl_name ":" # [اشتقاق (InferSchema) ] "،" def_site_span ": null}}]،" الأطفال ": [{" message ":" الرسالة: تسمى Result::unwrap() على قيمة Err : "فشل تحميل متغير البيئة DATABASE_URL: لم يتم العثور على متغير البيئة "" ، "الكود": فارغ ، "المستوى": "المساعدة" ، "الامتدادات": [] ، "الأطفال": [] ، "العرض": null}] ، "العرض": "الخطأ: اشتقاق proc-macro panickedn -> تطوير / pathfinder-server / pathfinder-server / src / schema.rs: 1: 1n | n1 | infer_schema! ("dotenv: DATABASE_URL") ؛ n | ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ Result::unwrap() على قيمة Err : "فشل تحميل متغير البيئة DATABASE_URL: متغير البيئة غير موجود" n = ملاحظة: نشأ هذا الخطأ في ماكرو خارج الصندوق الحالي (في الإصدارات الليلية ، قم بالتشغيل مع -Z خارجي -macro-backtrace لمزيد من المعلومات) n "}
{"message": "proc-macro مشتق بالذعر" ، "الرمز": فارغ ، "المستوى": "خطأ" ، "يمتد": [{"اسم_الملف": ""،" byte_start ": 72،" byte_end ": 83،" line_start ": 3،" line_end ": 3،" column_start ": 14،" column_end ": 25،" is_primary ": true،" text ": [{ "text": "# [derive (InferSchema)] # ["، "light_start": 14، "light_end": 25}]، "label": null، "selected_replacement": null، "extension": {"span" :{"اسم الملف":""،" byte_start ": 72،" byte_end ": 83،" line_start ": 3،" line_end ": 3،" column_start ": 14،" column_end ": 25،" is_primary ": false،" text ": [{ "text": "# [derive (InferSchema)] # ["، "light_start": 14، "light_end": 25}]، "label": null، "selected_replacement": null، "extension": {"span" : {"file_name": "Development / pathfinder-server / pathfinder-server / src / schema.rs"، "byte_start": 0، "byte_end": 37، "line_start": 1، "line_end": 1، "column_start ": 1،" column_end ": 38،" is_primary ": false،" text ": [{" text ":" infer_schema! ("dotenv: DATABASE_URL")؛ "،" light_start ": 1،" light_end ": 38 }] ، "label": خالية ، "الاستبدال_ المُقترَح": فارغ ، "توسيع": فارغ} ، "macro_decl_name": "infer_schema!" ، "def_site_span": {"file_name": ""،" byte_start ": 0،" byte_end ": 484،" line_start ": 1،" line_end ": 11،" column_start ": 1،" column_end ": 53،" is_primary ": false،" text ": [{ "text": "($ database_url: expr) => {"، "light_start": 1، "light_end": 31}، {"text": "mod __diesel_infer_schema {"، "light_start": 1، "light_end": 28}، {"text": "# [اشتقاق (InferSchema)] # ["، "light_start": 1، "light_end": 33}، {"text": "infer_schema_options (database_url = $ database_url)] Struct _Dummy؛ } pub "،" light_start ": 1،" light_end ": 79}، {" text ":" use self :: __diesel_infer_schema :: *؛ } ؛ ("،" light_start ": 1،" light_end ": 47}، {" text ":" $ database_url: expr، $ schema_name: expr) => {"،" light_start ": 1،" light_end ": 52}، {"text": "mod __diesel_infer_schema {"، "light_start": 1، "light_end": 28}، {"text": "# [derive (InferSchema)] # ["، "light_start": 1، "light_end" : 33}، {"text": "infer_schema_options ("، "light_start": 1، "light_end": 23}، {"text": "database_url = $ database_url، schema_name = $ schema_name)] هيكل _Dummy"، "light_start ": 1،" light_end ": 78}، {" text ":"؛ } pub use self :: __diesel_infer_schema :: *؛ }؛ "،" light_start ": 1،" light_end ": 53}]،" label ": null،" selected_replacement ": null،" extension ": null}}}،" macro_decl_name ":" # [اشتقاق (InferSchema) ] "،" def_site_span ": null}}]،" children ": [{" message ":" message: يُدعى Result::unwrap() على قيمة Err : "فشل تحميل متغير البيئة DATABASE_URL: لم يتم العثور على متغير البيئة "" ، "الكود": فارغ ، "المستوى": "المساعدة" ، "الامتدادات": [] ، "الأطفال": [] ، "العرض": null}] ، "العرض": "الخطأ: اشتقاق proc-macro panickedn -> تطوير / pathfinder-server / pathfinder-server / src / schema.rs: 1: 1n | n1 | infer_schema! ("dotenv: DATABASE_URL") ؛ n | ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ Result::unwrap() على قيمة Err : "فشل تحميل متغير البيئة DATABASE_URL: متغير البيئة غير موجود" n = ملاحظة: نشأ هذا الخطأ في ماكرو خارج الصندوق الحالي (في الإصدارات الليلية ، قم بالتشغيل مع -Z خارجي -macro-backtrace لمزيد من المعلومات) n "}

هل هناك طريقة لتمرير متغيرات البيئة إلى RLS؟ أو ربما يلزم تعيين مسار ما بحيث يتمكن dotenv من معرفة المتغير البيئي.

enhancement

التعليق الأكثر فائدة

في الوقت الحالي ، يمكن حل هذه المشكلة باستخدام برنامج نصي مُغلف تم تعيينه في تكوين rust-client.rlsPath . فيما يلي مثال على البرنامج النصي المجمع:

#!/bin/bash
(>&2 echo "Running custom RLS wrapper")

RLS=rls
# Needs to pick up internal rustc libraries in the sysroot 
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
# Set some extra env vars you'd like
export RUST_BACKTRACE=full
# Important to also forward all the arguments to the RLS binary 
$RLS "$@"

ومع ذلك ، أود أن أدعم ذلك على مستوى من الدرجة الأولى.

ال 5 كومينتر

هاه ، واجهت نفس المشكلة بالضبط! أحب أن أسمع شخصًا أكثر خبرة مع Rust يعطي فكرة عن كيفية حل هذه المشكلة.

أنا أيضا أحب أن أعرف. هل اكتشف أي منكماmpj أو @ kjeremy ذلك؟

نفس المشكلة للجميع ، هل هناك أي طريقة لجعل RLS تشغل بعض نصوص الخفافيش أو شيء من هذا القبيل؟

في الوقت الحالي ، يمكن حل هذه المشكلة باستخدام برنامج نصي مُغلف تم تعيينه في تكوين rust-client.rlsPath . فيما يلي مثال على البرنامج النصي المجمع:

#!/bin/bash
(>&2 echo "Running custom RLS wrapper")

RLS=rls
# Needs to pick up internal rustc libraries in the sysroot 
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
# Set some extra env vars you'd like
export RUST_BACKTRACE=full
# Important to also forward all the arguments to the RLS binary 
$RLS "$@"

ومع ذلك ، أود أن أدعم ذلك على مستوى من الدرجة الأولى.

أضف إصدار Windows لـ vscode rust-client.rlsPath :

<strong i="7">@echo</strong> off
rustc --print sysroot > a:/tmp/temp-rls-msvc.txt
SET /p LD_LIBRARY_PATH=<a:/tmp/temp-rls-msvc.txt
SET RUST_BACKTRACE=full
SET "LIB=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\lib\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64;"

rls %*
<strong i="8">@echo</strong> on

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات