ทำให้ตัวแปร VSCode มีสี

ฉันต้องการให้ตัวแปรแสดงด้วยสี

นี่คือลักษณะที่ปรากฏ:

หลาม

นี่คือวิธีที่ฉันต้องการให้เป็น:

หลากสี

เมื่อดูที่นี่ ฉันไม่พบการตั้งค่าใดๆ ที่อนุญาตให้ฉันเปลี่ยนแปลงได้


person Modelmat    schedule 09.12.2017    source แหล่งที่มา


คำตอบ (3)


ลองใช้การตั้งค่านี้ใน settings.json ของคุณ:

 "editor.tokenColorCustomizations": {
    "variables": "#f00"
 },

มีการปรับแต่งสีโทเค็น ง่ายๆ บางอย่างที่ใช้งานได้: ตัวแปร ความคิดเห็น คำหลัก ฟังก์ชัน ตัวเลข สตริง และประเภท สิ่งเหล่านี้อนุญาตให้ตั้งค่า สี เท่านั้น

หากคุณใช้ "textMateRules" คุณสามารถตั้งค่าคุณสมบัติเพิ่มเติมได้ ตัวอย่างเช่น:

"editor.tokenColorCustomizations": {
  "textMateRules": [
    {
      "scope": "comment",
      "settings": {
        "fontStyle": "italic",
        "foreground": "#C69650"
      }
    }
  ]
},
person Mark    schedule 09.12.2017
comment
ขอบคุณสำหรับสิ่งนี้ มันใช้ได้กับบางอย่าง แต่ไม่ใช่ทุกอย่าง ตัวอย่างเช่น สิ่งนี้ แสดงตัวแปร self เปลี่ยนเป็นสีแดง แต่ search_obj ไม่ใช่หรือเป็น ส่วน get_key ซึ่งควรจะมีการใช้ฟังก์ชัน - ฟังก์ชันใช้กับคำจำกัดความเท่านั้น - person Modelmat; 09.12.2017
comment
คุณยังสามารถลอง stackoverflow.com/questions/47272835/ ขอบเขตที่ละเอียดมากขึ้นได้อย่างไรอาจช่วยให้คุณบรรลุสิ่งที่คุณต้องการได้ - person Mark; 09.12.2017

สิ่งนี้ใช้ได้สำหรับฉัน มันทำให้ดูเหมือนการจัดรูปแบบ Javascript เริ่มต้นเท่าที่ฉันเห็น

In settings.json

"editor.tokenColorCustomizations": {
    "textMateRules": [
      {
        "scope": "meta.function-call.generic.python",
        "settings": {
          "foreground": "#DCDCAA"
        }
      },
      {
        "scope": "source.python",
        "settings": {
          "foreground": "#9CDCFE"
        }
      },
      {
        "scope": "punctuation.definition.string.begin",
        "settings": {
          "foreground": "#ce9178"
        }
      },
      {
        "scope": "punctuation.definition.string.end",
        "settings": {
          "foreground": "#ce9178"
        }
      },
      {
        "scope": "punctuation",
        "settings": {
          "foreground": "#dfdfdf"
        }
      }
    ]
}
person Austin Gomez    schedule 02.08.2019
comment
ขอบคุณมาก ใช้งานได้ทันทีสำหรับฉัน ! - person An Ant; 10.02.2021

คุณควรจะสามารถเพิ่มสีใน tokenColors เพื่อปรับแต่งสีได้ (ตัวอย่างพื้นฐาน):

SomeTheme.json

{ 
 "name": "Some Theme",
 "type": "dark",
 "colors": {
 ...
},
"tokenColors": [
   {
    "name": "Variables",
    "scope": "variable",
    "settings": {
    "foreground": "#e06c75"
   }
  },
 ]
}

ฉันไม่มี VSCode แม้ว่าจากการดูที่ another ธีม JSON มีลักษณะคล้ายกัน

person l'L'l    schedule 09.12.2017