microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.38k stars 28.62k forks source link

Links/Samples where language auto-detection doesn't work #131450

Open TylerLeonhardt opened 3 years ago

TylerLeonhardt commented 3 years ago

This issue is just to enumerate samples and things where auto-detect didn't work and why. There's likely not much that can be done beyond totally retraining the ML model... but at least we can have them in one place.

https://www.programiz.com/python-programming/examples/add-number

sana-ajani commented 3 years ago

Some C examples don't work for me, but it could be because it's just too short: https://www.programiz.com/c-programming/examples/add-numbers

sana-ajani commented 3 years ago

This JS example was detected as TS: https://www.programiz.com/javascript/examples/positive-negative-zero

sana-ajani commented 3 years ago

Tried auto-detection with a large JSON file and it wasn't able to detect it as JSON, just kept as "plain text": https://github.com/zemirco/sf-city-lots-json/blob/master/citylots.json

jsonMartin commented 3 years ago

I've had trouble getting Python code to be recognized. For example, using code from this example site, this code remains plain text:

# Import re module
import re

# Take any string data
string = input("Enter a string value: ")
# Define the searching pattern
pattern = '^[A-Z]'

# match the pattern with input value
found = re.match(pattern, string)

# Print message based on the return value
if found:
  print("The input value is started with the capital letter")
else:
  print("You have to type string start with the capital letter")
dapullar commented 3 years ago

Extension-less bazel BUILD files are detected as either Python, Javascript, Julia or Lua.

Example BUILD file (this currently resolves to Julia for me):

load("//tooling/bazel:defs.bzl", "stage", "codeowners", "ecs_deploy")

stage(
    name = "stage",
    base_prefix = "{PROJECT_NAME}/{STAGE_NAME}/{PROJECT_BASE_HREF}",
    files = glob(["out/**"]),
    stamp = [
        "NODE_NAME",
    ],
    tags = ["manual"],
)

ecs_deploy(
    name = "deploy",
    images = [
        "//products/docker:container_image_push",
    ],
    tags = [
        "manual",
        "post_release_task",
    ],
)

Also, files.associations are not respected for extension-less files. It sometimes resolves the correct language but it will default back to Python or Javascript 90% of the time. This does not work:

"files.associations": {
  "BUILD": "bazel"
},

I love the feature, but I had to turn it off because files.associations could not correctly enforce the lang.

"workbench.editor.languageDetection": false
TylerLeonhardt commented 3 years ago

@dapullar already fixed for 1.60.1. Thanks for reporting though!

ardunster commented 3 years ago

This SCSS detects as CSS : https://github.com/angular/components/issues/7162#issuecomment-493953159

owenblacker commented 2 years ago

As discussed, here's another example, this time of HTML that VS Code thinks is an INI file.

Curiously, it flashes up HTML in the status-bar section, before changing to Ini, but that might just be because my previous window had already been manually corrected to HTML.

TylerLeonhardt commented 2 years ago

initially reported by @Charles-Gagnon

  1. Open new untitled editor
  2. Type in a T-SQL query such as SELECT * FROM sys.databases

The language auto detection identifies this as a Dockerfile instead of SQL

anthonyvdotbe commented 2 years ago

Oftentimes when I'm writing plain text, VS Code suddenly detects it as one or the other programming language, even though the result doesn't make sense in the detected language.

As an example, I typed the following (I did a replace of [a-z] with s before posting here):

ssss sssssss sss ssss-ssssssss ssss -> sssssss ssssssss? (sss sss ssssssssssss sssss)
sssss ssss ss ssssssss, ssss ssss & sssss ssss sss ss ssss: ssssssssssss ssssssss ss ss?

which was detected as JavaScript by VS Code, even though that results in 22 JavaScript syntax errors.

Edit: another plaintext example being detected as Ruby:

zzzzz zzzzzzz zzzzz zzzzz -> zzz zzzzzz zzzz zzzzzzzzz zzz, zzzz zzzzzzzz
zzzzzzz zzzzzzz, zzzz zzzzzzzzz (zzz. 2 zzzzzz), zzzzzz zzzzz zz zzzz zzz zz zzzzzzzzzz, zzzzzz zzz + zzzzzzz & zzzz zzzzzzzzzzz zzzzzz

zzz zzzzzzzzzzzzzzzz zzzzzzzzz? zzzzz zz zzzzz & zzz zz zzzzz zzz zzz zzzzzzz

#zzz zzzzz zzzzzzzzzzz zzzzzzzz + #zzz zzzzzzz zzzzzzzzzzz zzz- zz zzzzzzzzz zz zzzzzzz zz zzzzzz? zzzzz zzzz zz 'z zzzzz zzz
zzzzzzzz zzz zzzzzz. zzzz, zzz 'z zzzzzzzz zzzz zzz zzzz

zzz zzz & zzz: zzzz zzzz zzzzzzz zz zzzz, zzzz zzzzzz zzzz zzzzzzzzzzzzzz zzzz zzzz: zzzz zzzz zzzzzz zzzzzz + 'z zz zzzz zzz zzzz zzzz
zzzzzzzzzzzz zzzzzzzzz zzzz zzzzz? zzzzzzzz + zzzzzzzzzzz zzzzz zzzzzzzzz
3 zzzzzzzz zzzzzzz :)

zzzz zzzz zzzzzz: zzzzzzzzz zzzz zzzz zzzzz? zzzzzzzzzzz? zzzzz zzz 'z zzzz zzz zzzzz zzzzz?

zzz/zzzz zzzzzzz: zzzzzzzzzzzzzzzzzzz zzz zz zzz zzzzzz zzz? zzzz zz zzzz zzz z'z zzzz'z zzzzz, zz zzzzz 'z zzzzzz zzzz zz zz zzz zz zzzzzz zzz zzzzzz?
TylerLeonhardt commented 2 years ago

ренессанс страхование обращайтесь в автосалон is treated as INI, reported in https://github.com/microsoft/vscode/issues/150873

katai5plate commented 9 months ago

JS code containing Japanese comments is often recognized as an INI file.

jsini

// ゲームパラメータオブジェクト
const gameParameters = {
  ui: {
    alwaysVisible: {
      /** ストレスゲージ */
      stressGauge: 0,
    },
    /** 満腹感% */
    satiety: 0,
    /** 鎮痛剤の血中濃度% */
    analgesicBloodLevel: 0,
    /** プレイヤー会話成功率% */
    playerConversationSuccessRate: 0,
  },
};
for-the-zero commented 1 month ago

i copied from gpt

const { desktopCapturer } = require('electron').desktopCapturer;
const { nativeImage } = require('electron').nativeImage;

function captureScreenshot() {
  desktopCapturer.getSources({ types: ['screen', 'window'] }).then(async sources => {
    for (const source of sources) {
      try {
        // 获取屏幕截图
        const image = await source.thumbnail.toPNG();
        // 将Buffer转换为NativeImage
        const nativeImg = nativeImage.createFromBuffer(image);
        // 将NativeImage转换为Base64编码的字符串
        const screenshot = nativeImg.toDataURL();

        // 在前端展示图片
        displayImage(screenshot);
      } catch (e) {
        console.error(e);
      }
    }
  });
}

function displayImage(screenshot) {
  // 假设你有一个<img>元素在HTML中,id为"screenshot"
  const imgElement = document.getElementById('screenshot');
  imgElement.src = screenshot;
}

// 调用函数进行截图
captureScreenshot();
// 添加一个方法来获取截图
async function captureScreen() {
  const sources = await desktopCapturer.getSources({ types: ['screen'] });
  const screen = sources[0];

  const image = await desktopCapturer.captureScreen({
    sourceId: screen.id,
    thumbnailSize: { width: 800, height: 600 }
  });

  return image;
}
//渲染进程
const { ipcRenderer } = require('electron');

document.getElementById('captureButton').addEventListener('click', async () => {
  const image = await ipcRenderer.invoke('capture-screen');

  if (image) {
    const canvas = document.getElementById('screenshotCanvas');
    const ctx = canvas.getContext('2d');

    const img = new Image();
    img.onload = () => {
      canvas.width = img.width;
      canvas.height = img.height;
      ctx.drawImage(img, 0, 0);
    };
    img.src = image.toPNG();
  }
});

// 在 Electron 12+ 版本中,你需要注册一个处理程序来响应 IPC 请求
ipcRenderer.handle('capture-screen', async (_, ...args) => {
  const mainProcessImage = await captureScreen();
  return mainProcessImage;
});